动态创建组件
unit uCaliszcInterface;
interface
uses
CALISZCLib_TLB, SysUtils;
var
caCalis: TCALISZC;
function CreateCalis: boolean;
procedure caCalisProxyConnected(ASender: TObject; ErrorCode: Smallint);
implementation
function CreateCalis: boolean;
begin
if not Assigned(caCalis) then
begin
caCalis := TCALISZC.Create(nil);
end;
caCalis.OnProxyConnected := caCalisProxyConnected;
end;
procedure caCalisProxyConnected(ASender: TObject; ErrorCode: Smallint);
begin
end;
提示 “Incompatible types:'method pointer and regular procedure'”
为什么啊?动态创建组件,如果放在同一个类里就没问题。
[解决办法]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure ONABClick(Sender :TObject) ;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
btn :TButton ;
implementation
{$R *.dfm}
procedure TForm1.ONABClick(Sender :TObject) ;
begin
TButton(Sender).Caption := 'aaaaaa' ;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
btn := TButton.Create(self);
btn.Left := 100 ;
btn.Width := 100 ;
btn.Top := 100 ;
btn.Height := 20 ;
btn.Caption := 'AAA' ;
btn.Parent := self ;
btn.OnClick := ONABClick ;
end;
end.