用代码创建的TBIZFIELD字段,用BizFields.Remove ,或 BizFields.Free 均不能实现,再次创建时会提示字段已经存在,创建代码如下:
var
lBizField: TBizField;
lColumn: TDataGridColumn;
Fldid,flddisplayname:string;
begin
with Query1 do
begin
Close;
CommandText:='select f.code fcode,B.CODE BCODE,B.ABBR TABBR,F.abbr fabbr '
+' from ledwaybasic.FinancialItems F, '
+'(select * from ledwaybasic.basicdata where Type=''PTT'' and spec=''DS'') b '//单双面
+' order by B.CODE' ;
OPEN;
first;
while not eof do
begin
Fldid:=sysutils.trim(FieldByName('BCode').AsString)+'|'+sysutils.trim(FieldByName('FCode').AsString);
flddisplayname:=sysutils.trim(FieldByName('TABBR').AsString)+'|'+sysutils.trim(FieldByName('FABBR').AsString);
lBizField := TUserDataField.Create(DataSetTEST);
lBizField.DataSet := DataSetTEST; //指定字段所在的数据集
lBizField.ID :=Fldid; //'GS'; //设置字段ID
lBizField.DataType := TDataType.dtFloat; //设置字段类型
//lBizField.Size :=20; //设置字段大小
lBizField.DisplayName :=flddisplayname;// 'AA|公司';
lColumn := TDataGridColumn(DataGrid1.CreateColumnByClassName('TDataGridColumn')); // 字符串表示列的类型,可以是'TDataGridColumn', 'TDataGridImageColumn','TDataGridMaskColumn'
lcolumn.Name:='TDataGridColumn'+Fldid;
lColumn.FieldName :=Fldid ;//'KF'; // 邦定GUID字段
lColumn.BandIndex:=1;
lColumn.Width:=60;
lColumn.Alignment:=TAlignment.taRightJustify;
lColumn.HeaderAlignment:=TAlignment.taCenter;
next;
end;
end;
DataSource1.DataSet.Open;
end; |