procedure TCtrlClick(Sender:Tobject); procedure TFra_Show.TCtrlClick(Sender:Tobject); var iniFile:TIniFile; i:integer; sSelect:String; begin i:=TEdit(Sender).tag; inifile:=TIniFile.Create(CasePath+'Case.ini'); sSelect:=iniFile.ReadString(IntToStr(i),'Select',''); if sSelect<>'' then begin FrmSelect.SelectShow(SysPath+'file\System\'+Copy(sSelect,1,2)+'.Txt',Copy(sSelect,4,Length(sSelect)-3),'I'); if sReturn<>'' then Tedit(Sender).text:=sReturn; end; iniFile.Free; end; EdtTmp[k]:=TEdit.Create(nil); with EdtTmp[k] do begin Hint:=IntToStr(j+1); parent:=PnlRight; ParentFont:=True; Tag:=i; Ctl3D:=False; BorderStyle:=bsNone; Left:=intLeft; top:=intRow*Intheight+IntY; Width:=StrtoInt(SArray[6])*IntWidth; Height:=StrtoInt(SArray[8])*IntHeight; if SArray[11]<>'' then begin ReadOnly:=True; OnClick:=TCtrlClick; end; end;
触发事件能不能动态?比如将触发事件写在一个ini文件中,动态调用。
当然可以..只要你把Procedure给相对应控件的事件就可以了.. 事件其实也是一个属性的..
[Error[Error] Unit1.pas(13): Published field 'button1' not a class nor interface type] Unit1.pas(13): Field definition not allowed after methods or properties 原代码照搬,有问题
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure myclick(Sender: TObject);
private
button1:Tbutton;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
procedure TForm1.myclick(Sender: TObject);
begin
showmessage('按下按钮');
end;
procedure TForm1.FormShow(Sender: TObject);
begin
button1:=tbutton.Create(application);
button1.Parent:=form1;
button1.Caption:='测试';
button1.OnClick:=myclick;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
button1.free;
end;end.
button1:=tbutton.Create(application);
button1.Parent:=form1;
button1.Caption:='测试';
button1.OnClick:=myclick;
放在你要创建的地方,位置设置一下
procedure TFra_Show.TCtrlClick(Sender:Tobject);
var
iniFile:TIniFile;
i:integer;
sSelect:String;
begin
i:=TEdit(Sender).tag;
inifile:=TIniFile.Create(CasePath+'Case.ini');
sSelect:=iniFile.ReadString(IntToStr(i),'Select','');
if sSelect<>'' then
begin
FrmSelect.SelectShow(SysPath+'file\System\'+Copy(sSelect,1,2)+'.Txt',Copy(sSelect,4,Length(sSelect)-3),'I');
if sReturn<>'' then Tedit(Sender).text:=sReturn;
end;
iniFile.Free;
end; EdtTmp[k]:=TEdit.Create(nil);
with EdtTmp[k] do
begin
Hint:=IntToStr(j+1);
parent:=PnlRight;
ParentFont:=True;
Tag:=i;
Ctl3D:=False;
BorderStyle:=bsNone;
Left:=intLeft;
top:=intRow*Intheight+IntY;
Width:=StrtoInt(SArray[6])*IntWidth;
Height:=StrtoInt(SArray[8])*IntHeight;
if SArray[11]<>'' then
begin
ReadOnly:=True;
OnClick:=TCtrlClick;
end;
end;
事件其实也是一个属性的..
原代码照搬,有问题