通过代码给TClientDataSet增加计算字段的问题(200分)

F

flai

Unregistered / Unconfirmed
GUEST, unregistred user!
SQL语句是: select name,sex from person
因为 sex 编码为: 1 男 2 女

SQL语句通过App Server发给DB Server,并通过App Server返回给客户端(thin-client)

我希望ClientDataSet增加name字段,sex 字段,sex_calc 计算字段,其中sex字段
visible=false,并且希望在代码中实现,所以我的代码如下:

Type
TWIField=record
FldType:TFieldType;
Size:Integer;
FldName:String;
DisplayLabel:String;
Visible:boolean;
FldKind:TFieldKind;
end;
PWIField=^TWIField;
.....................
.....................

procedure CreateDataSet(CDSet:TClientDataSet;FieldDefs:TList);
Var
i:Integer;
AFld:TField;
begin
for i:=0 to FieldDefs.Count-1 do
if PWIField(FieldDefs.Items).FldKind=fkData then
With CDSet.FieldDefs.AddFieldDef do
begin
DataType:=PWIField(FieldDefs.Items).FldType;
if DataType=ftString then
Size:=PWIField(FieldDefs.Items).Size;
Name:=PWIField(FieldDefs.Items).FldName;
?????用什么属性来指明这是计算字段呢?????
end;
if CDSet.FieldDefs.Count>0 then
CDSet.CreateDataSet;
end;

有没有其它实现方法?

在设计期是可以实现的,但是如果字段多的话,很麻烦并且容易出错,并且没有代码实现
来得通用,模块化


先行谢过!
 
没做过!!!
 
自己搞定的,不用计算字段来实现,而是通过OnGetText事件

今儿真高兴

便宜笨笨猫了
 
顶部