创建与TDataSet关联的Persistent Field组件的代码 [英] Code to create Persistent Field components associated with TDataSet
问题描述
寻找一些示例代码来说明如何在运行时创建 与数据集关联的TField组件。
Looking for some example code illustrating how to create at runtime TField Components associated with a dataset.
在IDE中,如果放下数据集组件,则右键单击将弹出在设计时提供此功能的字段编辑器。找不到能够在运行时执行该操作的代码。
In the IDE, if you plop down a dataset component, right-clicking brings up the fields editor that provides this functionality at design time. Have not been able to find code showing how to do it at runtime.
TIA
推荐答案
每种字段类型都有一个Create函数,您可以将DataSet传递给该函数,以创建该类型的字段并将其添加到Fields中。从DB.TStringField.Create的帮助中。
Each field type has a Create function that you pass the DataSet to that creates a field of that type and adds it to the Fields. From the help for DB.TStringField.Create.
var
T: TStringField;
begin
SQLDataSet1.Close;
T := TStringField.Create(SQLDataSet1);
T.FieldName := 'LastName';
T.Name := SQLDataSet1.Name + T.FieldName;
T.Index := SQLDataSet1.FieldCount;
T.DataSet := SQLDataSet1;
SQLDataSet1.FieldDefs.UpDate;
SQLDataSet1.Open;
end;
这篇关于创建与TDataSet关联的Persistent Field组件的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!