创建可以插入Office文档的ActiveX控件
There is a nice feature in Microsoft Word that allows you to put ActiveX controls onto a Word document. To do so you go to the Insert Menu, and click Object? This displays a dialog list a number of "Insertable" controls.
There is one problem with this dialog though; there is no browse button and no obvious method of adding your control to the list. So how do you do it?
Turns out your ActiveX control is missing one registry entry, and the Type Library editor does not give you the option of inserting it. The entry is 揑nsertable?(and you抳e been wondering why I have been using that word so much). The key goes in the HKEY_CLASSES_ROOT section of the registry under a key that is your ActiveX control抯 class id.
In the end, your registry should look something like this:
HKEY_CLASSES_ROOT->YourControl.TheClass->Insertable
Now, you can either go into RegEdit and enter this manually (a good way to make sure I抦 not lying through my teeth), or you can add this entry automatically when the control is registered. Ya, I thought so, option number 2 it is:
So, if you want this to be put in the registry automatically...
1. Go to the unit containing your automation object.
2. Make sure Registry and Windows are in your uses statement.
3. Modify your INITIALIZATION section to something like this with a new function:
procedure MoreKeys;
const
C_KEY: String = 'YourControl.TheClass'; // your controls class ID
var
oReg: TRegistry;
begin
oReg := TRegistry.Create;
try
oReg.OpenKey(HKEY_CLASSES_ROOT);
// the true mean create the key if it doesn抰 exist
oReg.OpenKey(C_Key + '\Insertable',True);
finally
oReg.CloseKey;
oReg.Free;
end;
end;
initialization
TActiveFormFactory.Create(
ComServer,
TActiveFormControl,
... yada, yada, yada );
MoreKeys;
End.
And you are done. Good luck.