2010-05-29 25 views
3

將delphi應用程序打包爲activex dll的最佳方法是什麼? 如果我只是編譯它,當我將它發送給其他人時,它會給他們錯誤,因爲他們沒有註冊ActiveX DLL。使用ActiveX控件分發Delphi應用程序

+0

最好我希望應用程序是獨立的,但無論我可以做什麼使它運行在某人elses機器上會很好。 – Nowayz 2010-05-29 01:44:45

回答

3

你應該做的是創建一個安裝程序。有幾個程序可以讓你這樣做。我更喜歡使用Delphi編寫的開源的InnoSetup,並且效果非常好。只需將您的ActiveX DLL與您的EXE一起放入安裝包中,然後告訴InnoSetup它需要去的位置(與您的應用程序相同的文件夾,Sys32或其他一些預定義的位置),然後處理其餘部分爲你。

1

當我在運行時創建COM服務器時,我使用了某物。如下所示。這個想法是捕捉「未註冊的類」例外並嘗試即時註冊服務器。通過一些搜索,您還可以找到一些示例,讀取註冊表中的類標識符,以確定是否註冊了activex服務器...我將該示例改編爲一些「MS Rich Text Box」(richtx32.ocx),但它不會沒有什麼不同。

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; 
+0

這不會爲用戶提供activex dll,只要在安裝時尚未完成就立即進行註冊。 – 2010-05-29 04:42:01

+0

@Francois:在我看來,這正是OP想要解決的問題?他寧願不必分發dll,但如果他這樣做,他想避免在用戶的機器上發生「dll not registered」錯誤。這就是Sertac的代碼所做的事情......當然,使用安裝程序將是另一種選擇,但也需要更多的維護(安裝腳本等)。 – 2010-05-29 09:36:05

+0

@François - 嗯,是的..也許我誤解了這個問題?... – 2010-05-29 09:52:53

相關問題