如何最好地将ActiveX dll与Delphi应用程序打包?如果我只是编译它,当我将其发送给其他人时,他们会因为没有注册ActiveX dll而出现错误。
uses
comobj;
function RegisterServer(ServerDll: PChar): Boolean;
const
REGFUNC = 'DllRegisterServer';
UNABLETOREGISTER = '''%s'' in ''%s'' failed.';
FUNCTIONNOTFOUND = '%s: ''%s'' in ''%s''.';
UNABLETOLOADLIB = 'Unable to load library (''%s''): ''%s''.';
var
LibHandle: HMODULE;
DllRegisterFunction: function: Integer;
begin
Result := False;
LibHandle := LoadLibrary(ServerDll);
if LibHandle <> 0 then begin
try
@DllRegisterFunction := GetProcAddress(LibHandle, REGFUNC);
if @DllRegisterFunction <> nil then begin
if DllRegisterFunction = S_OK then
Result := True
else
raise EOSError.CreateFmt(UNABLETOREGISTER, [REGFUNC, ServerDll]);
end else
raise EOSError.CreateFmt(FUNCTIONNOTFOUND,
[SysErrorMessage(GetLastError), ServerDll, REGFUNC]);
finally
FreeLibrary(LibHandle);
end;
end else
raise EOSError.CreateFmt(UNABLETOLOADLIB, [ServerDll,
SysErrorMessage(GetLastError)]);
end;
function GetRichTextBox(Owner: TComponent): TRichTextBox;
begin
Result := nil;
try
Result := TRichTextBox.Create(Owner);
except on E: EOleSysError do
if E.ErrorCode = HRESULT($80040154) then begin
if RegisterServer('richtx32.ocx') then
Result := TRichTextBox.Create(Owner);
end else
raise;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
[...]
RichTextBox := GetRichTextBox(Self);
RichTextBox.SetBounds(20, 20, 100, 40);
RichTextBox.Parent := Self;
[...]
end;