procedure TForm1.DBGrid1DblClick(Sender: TObject); var no:string; begin if ADOQuery2.Active then begin no:=DBGrid1.DataSource.DataSet.Fields[2].value; //雙擊獲值 ADOQuery2.close; ADOQuery2.SQL.clear; //ADOQuery2.SQL.Add('select * from Tbl1 where id='''+no+''''); //直接獲變量值 ADOQuery2.SQL.Add('select * from Tbl1 where id=:no'); //獲參查 ADOQuery2.parameters.parambyname('no').value:=no; ADOQuery1.Prepared ; ADOQuery2.open; end; end;
//雙擊獲DBGrid1值。 procedure TForm1.DBGrid1CellClick(Column: TColumn); begin showmessage(DBGrid1.Datasource.Dataset.Fields[1].AsString); with DBGrid1 do showmessage(format('row=%d',[SelectedIndex])); Edit.text:=DBGrid1.Datasource.Dataset.Fields[3].AsString; end;
var
no:string;
begin
if ADOQuery2.Active then
begin
no:=DBGrid1.DataSource.DataSet.Fields[2].value; //雙擊獲值
ADOQuery2.close;
ADOQuery2.SQL.clear;
//ADOQuery2.SQL.Add('select * from Tbl1 where id='''+no+''''); //直接獲變量值
ADOQuery2.SQL.Add('select * from Tbl1 where id=:no'); //獲參查
ADOQuery2.parameters.parambyname('no').value:=no;
ADOQuery1.Prepared ;
ADOQuery2.open;
end;
end;
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
showmessage(DBGrid1.Datasource.Dataset.Fields[1].AsString);
with DBGrid1 do
showmessage(format('row=%d',[SelectedIndex]));
Edit.text:=DBGrid1.Datasource.Dataset.Fields[3].AsString;
end;