我在 MySQL 上有一个返回两个结果的过程,我需要在 Delphi 上显示它,但我没有找到如何传递每个结果。
这是我执行时在 DBForge 上的显示方式,我也想在 delphi 上显示这个,在 Query1
中显示 Query2
和 TTabControl
。
如何通过此查询并获取查询名称,例如:Query1
,Query2
?
答案 0 :(得分:0)
您没有说明您使用的是什么 DB 接口库,例如 FireDAC、Zeos 或其他东西。
您将发出类似 dbxyz.ExecSQL() 调用的命令并检查一些结果。
听起来您希望在结果集中取回多条记录。使用 TTabControl,您只需创建一个选项卡列表,如“Result-1”、“Result-2”等,具体取决于您返回的记录数量。 (它们是结果,而不是查询。)您可以默认选择第一个。
单击另一个选项卡时,使用控件的 TabIndex 属性从结果集中选择相应的结果,然后格式化该结果中的数据并以您在选项卡下方使用的任何格式显示它。
您提供的细节太少,除了选项卡控件的 OnChange 处理程序将使用 TabIndex 属性来查找所需的结果集之外,不可能显示任何代码。但这是我使用 TTabControl 对此采取的总体方法。
答案 1 :(得分:0)
我用命令解决了问题
var
tab: TTabItem;
stringGrid: TStringGrid;
repeat
tab:= TTabItem.Create(nil);
tab.Parent:= tabcontrol1;
tab.Text:= query.Fields.Fields[0].FieldName; //the table name
stringGrid:= TStringGrid.Create(Self);
stringGrid.Parent:= tab;
stringGrid.Align:= TAlignLayout.Client;
for I := 1 to query.FieldCount-1 do
begin
stringGrid.AddObject(TStringColumn.Create(stringGrid));
stringGrid.Columns[i-1].Header:= query.Fields.Fields[i].FieldName;
query.First;
for j := 0 to query.RecordCount-1 do
begin
stringGrid.cells[i-1, j]:= query.Fields.Fields[i].value;
query.Next;
end;
end;
stringGrid.RowCount:= j;
until not query.openNext;