1. 程式人生 > >動態生成lookup字段

動態生成lookup字段

def tde classes sse class 增加 designer nal data

var
i: Integer;
begin
//ADOQuery已打開
//在數據集打開的情況下新增加一個字段
with Self.ADOQuery1 do
begin
TDataSetDesigner.Create(Self.ADOQuery1);
try
Designer.BeginDesign;
//Keep Old Field
//保留舊的字段
Designer.DataSet.Fields.Clear;
for i := 0 to FieldDefList.Count - 1 do
begin
with FieldDefList.FieldDefs[i].CreateField(Self) do
begin
DisplayLabel := IntToStr(i);
end;
end;

//Add New Field
//增加新的字段
with DB.DefaultFieldClasses[TFieldType(2)].Create(Self) do
begin
FieldKind := TFieldKind(1);
FieldName := ‘FieldName‘ + IntToStr(i + 1);
Name := ‘FieldName1‘ + IntToStr(i + 1);
DataSet := Self.ADOQuery1;
end;
//用於做後續增加字段的標誌
DesignerData := ‘Design‘;
finally
Designer.EndDesign;
Designer.Free;
Self.RefreshListBox;
end;
end;
end;

動態生成lookup字段