在query对应的onGetText事件中处理 begin if query1.fieldbyname('评价').asstring='1' then begin text:='好' end; if query1.fieldbyname('评价').asstring='2' then begin text:='一般' end; if query1.fieldbyname('评价').asstring='3' then begin text:='差' end;
1.select (case [字段名] when 1 then '是' when 0 then '否' end); 2.在数据集相关字段的OnGetText、OnSetText中做读写的转化; 3.用内存表,在这里大材小用,权做一个参考
这是对aqAdmin(TADOQuery)的字段sys进行读写转化的代码,功能是当数据库字段值为true时显示'是',反之为'否';写入时若选择'是',则写true入数据库反之为false;读案例sousouwjh(sousouwjh) 已实现了,找这个字段的方法是双击DBGRID的DataSource的DataSet,然后再在弹出的框中击右键,选Add all fields...,然后选中你要转化的那个字段,再按F11,选择Events标签页,那里就是OnGetText、OnSetText所在的地方,下面的代码你只要改一些就够了,true改为1,其它类似,若只有0、1两个字段,再看看sousouwjh(sousouwjh),写的较细,g下面代码权做参照:procedure TfrmAdmin.aqAdminsysGetText(Sender: TField; var Text: String; DisplayText: Boolean); begin if Sender.AsBoolean = true then Text := '是' else Text := '否'; end;procedure TfrmAdmin.aqAdminsysSetText(Sender: TField; const Text: String); begin if Text = '是' then Sender.AsBoolean := true else Sender.AsBoolean := false; end;
然后在DBGRID里,新建一个虚的LOOKUP字段,把1和你的这个编码表的数据一一对应,就可以了~!显示的时候,显示的是这个个虚的LOOKUP字段~!
begin
if query1.fieldbyname('评价').asstring='1' then
begin
text:='好'
end;
if query1.fieldbyname('评价').asstring='2' then
begin
text:='一般'
end;
if query1.fieldbyname('评价').asstring='3' then
begin
text:='差'
end;
2.在数据集相关字段的OnGetText、OnSetText中做读写的转化;
3.用内存表,在这里大材小用,权做一个参考
DisplayText: Boolean);
begin
if Sender.AsBoolean = true then
Text := '是'
else
Text := '否';
end;procedure TfrmAdmin.aqAdminsysSetText(Sender: TField; const Text: String);
begin
if Text = '是' then
Sender.AsBoolean := true
else
Sender.AsBoolean := false;
end;