CommandTextプロパティがSQLクエリに設定されているTDataSetを使用しています。また、TDataSetのフィールドに基づいてSQLクエリの一部を作成する次の関数を作成しました。しかし、それは不完全です。ご覧のとおり、TFieldの元のテーブルの名前を取得する必要があります。どうすればこれを達成できますか?
function GetDataSetFieldsMSSQL(Dataset: TDataSet): String;
var
I, L: Integer;
TableName: String;
begin
Result := '';
L := Dataset.Fields.Count;
if (L > 0) then
begin
TableName := ... // Name of the table for the Dataset.Fields[0] field.
Result := '[' + TableName + '].[' + Dataset.Fields[0].FieldName + ']';
I := 1;
while (I < L) do
begin
TableName := ... // Name of the table for the Dataset.Fields[I] field.
Result := Result + ',[' + TableName + '].[' + Dataset.Fields[I].FieldName + ']';
Inc(I);
end;
end;
end;