举个例子吧: procedure CheckProc(yourParam: DataType); begin //加入你的代码 end;procedure CheckClick(Sender: TObject); begin CheckProc(yourParam); end;.... checkbox1.onclick ;= checkclick; ....建议你将yourparam定义为该单元的全局变量,在你调用之前,修改此参数值即可.
是这样的,要传的参数是checkbox动态生成时生成的,象你说的这样调用 的话,参数值就变了。原代码是这样的:with ADOQuery1 do begin SQL.Text := Format('select ques from quest where name=%s', //不要用''''+X+''''有漏洞 [QuotedStr(DBComboBox1.Text )]); //直接操作SQL.Text没有必要SQL.Clear; Open; while not Eof do begin with TLabel.Create(self) do begin Parent := Panel1; Caption := FieldByName('ques').Value; Left := E; Top := H; Width := E + Width + 160; end; str:=FieldByName('ques').Value ;//要传的实参 //-----------读ANSW表中的相应选项----------------- with ADOQuery2 do begin SQL.Text :=Format('select chck from answ where name=%s and qst='''+str+'''', [Quotedstr(DBCombobox1.Text)]) ; Open; while not Eof do begin with Tcheckbox.Create(self) do begin Parent := Panel1; Caption := Fieldbyname('chck').Value ; Left := E; E := E + 160; Top := H + 35; onclick:=checkboxcheck; //调用过程 分不够我可以加,先谢过!
procedure TForm2.CheckProc (Sender:TObject); begin with ADOQuery3 do begin SQL.Text := Format('update answ set jilu=''true'' where name=%s and qst='''+str+'''',//----------参数引用-------- [Quotedstr(DBCombobox1.Text)]); showmessage(SQL.Text); ExecSQL; end; end;
procedure CheckProc(yourParam: DataType);
begin
//加入你的代码
end;procedure CheckClick(Sender: TObject);
begin
CheckProc(yourParam);
end;....
checkbox1.onclick ;= checkclick;
....建议你将yourparam定义为该单元的全局变量,在你调用之前,修改此参数值即可.
的话,参数值就变了。原代码是这样的:with ADOQuery1 do begin
SQL.Text := Format('select ques from quest where name=%s', //不要用''''+X+''''有漏洞
[QuotedStr(DBComboBox1.Text )]); //直接操作SQL.Text没有必要SQL.Clear;
Open;
while not Eof do begin
with TLabel.Create(self) do begin
Parent := Panel1;
Caption := FieldByName('ques').Value;
Left := E;
Top := H;
Width := E + Width + 160;
end;
str:=FieldByName('ques').Value ;//要传的实参
//-----------读ANSW表中的相应选项-----------------
with ADOQuery2 do begin
SQL.Text :=Format('select chck from answ where name=%s and qst='''+str+'''',
[Quotedstr(DBCombobox1.Text)]) ;
Open; while not Eof do begin
with Tcheckbox.Create(self) do begin
Parent := Panel1;
Caption := Fieldbyname('chck').Value ;
Left := E;
E := E + 160;
Top := H + 35;
onclick:=checkboxcheck; //调用过程
分不够我可以加,先谢过!
就是当前触发事伯的这个控件,而不管这个控件是否是动态创建的!onclick:=checkboxcheck; //调用过程
这句并不是调用,而是给动态创建的CheckBox的OnClick事件赋值!
使得你在单击这个CheckBox时来执行CheckBoxCheck过程,
这时CheckBoxCheck过程的参数Sender就是这个动态创建出来的CheckBox!
begin
with ADOQuery3 do begin
SQL.Text := Format('update answ set jilu=''true'' where name=%s and qst='''+str+'''',//----------参数引用--------
[Quotedstr(DBCombobox1.Text)]);
showmessage(SQL.Text);
ExecSQL;
end; end;