Distributing a Delphi Application Using an ActiveX Control

What is the best way to package activex dlls using delphi application? If I just compile it when I send it to someone else, it will give them errors because they do not have a registered ActiveX DLL.

+3
source share
2 answers

What you have to do is create an installer. There are several programs that will allow you to do this. I prefer InnoSetup , which is open source written in Delphi and works very well. Just put your ActiveX DLL into the installation package with the EXE and tell InnoSetup where it should go (in the same folder as your application, in Sys32 or in several other predefined places), and it takes care of everything else for you.

+3
source

COM , sth. . , "class not registered" " ". , , , activex... " MS" (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;
+1

Source: https://habr.com/ru/post/1747632/


All Articles