简体   繁体   English

如何获得 FDQuery 结果?

[英]How to get FDQuery result?

Hi guys I have a few forms in my application and I have a test button where I want to fire a query taken from another unit.大家好,我的应用程序中有几个 forms,我有一个测试按钮,我想在其中触发从另一个单元获取的查询。 Here is my code:这是我的代码:

procedure TForm1.Button7Click(Sender: TObject);
var test : string;
begin
// test :=  Unit1.DataModule1.FDQuery2.Open.ToString;                  
 // Unit1.DataModule1.FDQuery2.ExecSQL;
 // test.ToString;
 // ShowMessage(Unit1.DataModule1.FDQuery2.Open);
 // Unit1.DataModule1.FDQuery2.Active := true;
  Unit1.DataModule1.FDQuery2.SQL.Text := 'SELECT CURRENT_DATE';
  Unit1.DataModule1.FDQuery2.Open();
  // Writeln(test);
end;

basically I want to be able to for example take the result array or whatever datatype returns and assign them for example to a TEdit and then change it and so on.基本上,我希望能够获取结果数组或返回的任何数据类型并将它们分配给例如 TEdit,然后更改它等等。 I wanted to show the result as a string but could not convert it properly.我想将结果显示为字符串,但无法正确转换。 How would you the store the response?您将如何存储响应? Also please correct my calls if there is something wrong - because my TFDQuery2 has the same argument like SQL.TEXT.如果有问题,请更正我的电话 - 因为我的 TFDQuery2 具有与 SQL.TEXT 相同的参数。 Is it possible to just fire that query and get the result in a way that I can show it or use it?是否可以只触发该查询并以我可以显示或使用它的方式获得结果?

After TFDQuery.Open() has executed the SELECT query, you can use the TFDQuery.Fields property to access the returned field values, eg:TFDQuery.Open()执行SELECT查询后,您可以使用TFDQuery.Fields属性访问返回的字段值,例如:

procedure TForm1.Button7Click(Sender: TObject);
var
  test : string;
begin
  Unit1.DataModule1.FDQuery2.SQL.Text := 'SELECT CURRENT_DATE';
  Unit1.DataModule1.FDQuery2.Open();
  test := Unit1.DataModule1.FDQuery2.Fields[0].AsString;
  Edit1.Text := test;
  Unit1.DataModule1.FDQuery2.Close();
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM