有一列是Numeric(19,2)类型的,用ADO连接SQLServer2000,要在DbGridEh中显示成这样的格式+1,253.25
-15,234.24
+1.454,455.00
表中有个字段叫OperationType,当他的值为1时在数字前显示”+“,为2时显示“-”号,怎样实现这样的功能?
-15,234.24
+1.454,455.00
表中有个字段叫OperationType,当他的值为1时在数字前显示”+“,为2时显示“-”号,怎样实现这样的功能?
解决方案 »
- 菜鸟做了一个delphi+ado+access程序,但客户总往表里存图片,导致这个ACCESS文件超过2个G了,导致delphi程序不能再往里插入数据了。
- delphi如何调用c#写的dll得问题?
- 长整型取模计算
- 。非得把我压箱底的分都拿出来散。。。。什么世道啊。。。
- 关于COM的高难度问题
- 散分,sql语句,谢谢
- 请问用什么控件能实现如图所示的功能(图)!!!!!!!!!!!!急!!!!!!!!!!!!!!!!
- 如何直接从DBGrid控件中获得当前记录是第几条记录?而不采用query和table控件
- 从borland公司下载的interbase6.0限几个用户?
- 有什么好的学习方法用来学习对硬件进行编程
- 请教安装package时错误!!!!
- 求助:关于用delphi自动生成word文档的一个简单问题?
procedure TForm1.ADOQuery1cccGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
if Sender.DataSet.FieldByName('OperationType').asInteger=1 then
DisplayText := '+' + FormatCurr(',0.00', Sender.AsCurrency)
else if Sender.DataSet.FieldByName('OperationType').asInteger=2 then
DisplayText := '-' + FormatCurr(',0.00', Sender.AsCurrency)
end;
procedure cccGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
if Sender.DataSet.FieldByName('OperationType').asInteger=1 then
DisplayText := '+' + FormatCurr(',0.00', Sender.AsCurrency)
else if Sender.DataSet.FieldByName('OperationType').asInteger=2 then
DisplayText := '-' + FormatCurr(',0.00', Sender.AsCurrency)
end;2.然后定义:
如from2.Adoquery.FieldByName('显示的列').onGetText := cccGetText;
即可:
[Error] QueryAccountAllu.pas(129): Incompatible types: 'method pointer and regular procedure'
procedure cccGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
if Sender.DataSet.FieldByName('OperationType').AsInteger = 1 then
Text:='+'+FormatFloat('###,###0.00',Sender.AsFloat);
if Sender.DataSet.FieldByName('OperationType').AsInteger = 2 then
Text:='-'+FormatFloat('###,###0.00',Sender.AsFloat);
end;
private
procedure SetDisplayFormat(Sender: TField);2.
procedure form1.SetDisplayFormat(Sender: TField;var Text: String;DisplayText: Boolean);//注意加当前单元名,如form1
begin
if Sender.DataSet.FieldByName('OperationType').AsInteger = 1 then
Text:='+'+FormatFloat('###,###0.00',Sender.AsFloat);
if Sender.DataSet.FieldByName('OperationType').AsInteger = 2 then
Text:='-'+FormatFloat('###,###0.00',Sender.AsFloat);
end;3.在当前窗口创建或打开时,设置
from2.Adoquery.FieldByName('显示的列').onGetText := SetDisplayFormat;