register.pas

来自「注册/反注册OCX,DLL的例子」· PAS 代码 · 共 79 行

PAS
79
字号
unit Register;

interface             {程序:斗鱼 2005 QQ:13335085}

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ActiveX;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label2: TLabel;
    Label1: TLabel;
    OpenDialog1: TOpenDialog;
    procedure Edit1ContextPopup(Sender: TObject; MousePos: TPoint;
      var Handled: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  OCXHand:THandle;
  RegFunc:TDLLRegisterServer;

implementation

{$R *.dfm}

procedure TForm1.Edit1ContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
begin
   Handled:=true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.InitialDir:=ExtractFilePath(Application.Exename);
if not OpenDialog1.Execute then exit;
begin      
try
Edit1.Text:=OpenDialog1.FileName;
OCXHand:=LoadLibrary(PChar(OpenDialog1.FileName));
RegFunc:=GetProcAddress(OCXHand, 'DllRegisterServer');
ShowMessage('文件:'+OpenDialog1.FileName+'注册成功!');
if RegFunc <> 0 then
ShowMessage('Error!');
finally
FreeLibrary(OCXHand);
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
OpenDialog1.InitialDir:=ExtractFilePath(Application.Exename);
if not OpenDialog1.Execute then exit;
begin      //DllRegisterServer   注册OCX
try        //DllUnregisterServer 反注册OCX
Edit1.Text:=OpenDialog1.FileName;
OCXHand:=LoadLibrary(PChar(OpenDialog1.FileName));
RegFunc:=GetProcAddress(OCXHand, 'DllUnregisterServer');
ShowMessage('文件:'+OpenDialog1.FileName+'反注册成功!');
if RegFunc <> 0 then
ShowMessage('Error!');
finally
FreeLibrary(OCXHand);
end;
end;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?