zhangwj000@nbip.net
I wrote the code as following, but when compiled, an error of "Event handler must be a procedure" occured! Can some one help me ?
/***********
form1.ScriptMemo.Lines.Append('procedure click1(Sender:TButton); ');
form1.ScriptMemo.Lines.Append('begin showmessage(''hello''); end;');
form1.ScriptMemo.Lines.Append(' begin ');
form1.ScriptMemo.lines.Append(' GForm.button1.OnClick:=@click1; ');
form1.ScriptMemo.Lines.Append(' end.');
/***********
/***********
form1.ScriptMemo.Lines.Append('procedure click1(Sender:TButton); ');
form1.ScriptMemo.Lines.Append('begin showmessage(''hello''); end;');
form1.ScriptMemo.Lines.Append(' begin ');
form1.ScriptMemo.lines.Append(' GForm.button1.OnClick:=@click1; ');
form1.ScriptMemo.Lines.Append(' end.');
/***********
Comments
I add the following line to the program
Form1.fsScript1.AddForm(GForm);
GForm is a dynamically generated form in a procedure.
then , I invoke the GForm object in the script. But it told me "undeclared variable GForm";
if I add the line as following
Form1.fsScript1.Parent:=fsGlobalUnit;
Form1.fsScript1.Parent.AddForm(GForm);
I can access GForm for the first time , but at the second time, an access violation error occured!
Thanks for helping me!
====================================
procedure GlobalCreateForm(ModID:integer);
var
GForm:TForm;
button1:TRESMButton;//derived button class
i:integer;
begin
GForm := TForm.Create(nil);
GForm.Parent := nil;
GForm.Caption := 'test form';
GForm.Name:='GForm';
for i:=1 to 5 do
begin
button1 := TRESMButton.Create(GForm);
button1.Parent:=GForm;
button1.Left:=10;
button1.Top:=20*i+10;
button1.Name:='button'+inttostr(i);
button1.Caption:=button1.Name;
button1.Height:=20;
button1.Width:=100;
button1.m_note:='note';
end;
Form1.fsScript1.Parent.AddForm(GForm);
// Form1.fsScript1.Parent.RemoveComponent(GForm);
form1.ScriptMemo.lines.Clear;
form1.ScriptMemo.Lines.Append('procedure click1(Sender:TButton); ');
form1.ScriptMemo.Lines.Append('begin showmessage(GForm.button1.m_note); end;');
form1.ScriptMemo.Lines.Append(' begin ');
form1.ScriptMemo.Lines.Append(' GForm.button1.m_note:=''test note''; ');
form1.ScriptMemo.lines.Append(' GForm.button1.OnClick:=@click1; ');
form1.ScriptMemo.Lines.Append(' end.');
if(form1.RunScript<>0)then
begin
GForm.Free;
Exit;
end;
GForm.ShowModal;
GForm.Free;
end;