有两种形式。一个是主要的,它有几个按钮用于切换到第二种形式。第二个表单是模板:填写它的所有字段和按钮都是空的。如何将模板表单中的按钮的操作代码分配给主表单中的按钮。需要在 //STR[9] 上写什么,以便 button1 分配此行下面描述的代码?
procedure TForm4.SpeedButton1Click(Sender: TObject);
begin
Form5.Caption:= 'Add New Value';
Form5.DBLookupListBox1.ListSource:=Form4.DS_country;
Form5.DBLookupListBox1.ListField:='Country;Country_ID';
Form5.DBLookupListBox1.KeyField:=('Country_ID');
Form5.DBEdit1.DataSource:=Form4.DS_country;
Form5.DBEdit1.DataField:=('Country');
//STR[9]** Form5.Button1 (?????)**
begin
Form4.ADOQuery1.SQL.Clear;
Form4.ADOQuery1.SQL.Add('Select Country from ВИД WHERE Country='+#39+Form5.Edit1.Text+#39);
Form4.ADOQuery1.Open;
if Form4.ADOQuery1.IsEmpty then
begin
Form4.Query_vid.Insert;
Form4.Query_vid.FieldByName('Country').AsString := Form5.Edit1.Text;
Form4.Query_vid.Open;
Form4.Query_vid.Post;
MessageBox(Handle, 'new data was entered','Add New Value',MB_ICONINFORMATION);
end
else
begin
Form4.Query_vid.Cancel;
Form4.ADOQuery1.Cancel;
MessageBox(Handle,PChar(''+Form5.Edit1.text+'is already on the list'),'Ошибка',MB_ICONWARNING);
end;
end;
问题是模板表单中所有组件的所有值都是空的,我希望它们只有在按下主表单的某个按钮后才能填充。
Delphi 中的事件是引用对象过程的普通属性,这意味着它们可以被分配。
首先,从代码中,您需要创建一个带有事件等参数的对象过程。
然后赋值