在程序中注册OCX控件
procedure TForm1.Button1Click(Sender: TObject);var
astr:String;
bstr:String;
ProcAddr:Pointer;
DllAddr:Integer;
begin
od1.Execute;
astr:=od1.FileName+chr(0);
DllAddr:=LoadLibrary(PChar(astr));
if DllAddr<>0 then
begin
bstr:='DllUnregisterServer'+chr(0);
//只要将以上处改为DllRegisterServer即不注册ActiveX控件
ProcAddr:=GetProcAddress(DllAddr,PChar(bstr));
if ProcAddr<>nil then
CallWindowProc(ProcAddr,DllAddr,0,0,0)
else
ShowMessage(od1.FileName+'不是有效的控件');
FreeLibrary(DllAddr);
end
else
ShowMessage(od1.FileName+'无法装载');
end;