| |

VerySource

 Forgot password?
 Register
Search
Author: dai87331

decimal (20, 8) can only be displayed as TFloatField (EnableBCD = false) or TBCDField in dataset

[Copy link]

0

Threads

9

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-7-22 12:15:01
| Show all posts
Haha, it seems that the difficulty of this problem is not small. In general, there are many solutions. Of course, the problem lies mainly in Borland.
1. Modify the source code of ADODB.pas, that is, modify the field definition part converted from Recordset to DataSet. This issue has been discussed by many people. Forcibly modify the correspondence relationship of decimal
2. Modify the source code of DB.pas, that is, if ADO calls data directly from the Recordset
3. Create a new custom field class, such as TDoubleField, and then define it yourself. Of course, you have to modify the source code of ADODB.pas and DB.pas at this time.

The above three methods are once and for all methods, preferably the third method

The fourth method, this situation is suitable for the case where there are fewer such fields, which is to modify the GetText and SetText methods of the field, such as

procedure TForm1.ADOQuery1DecFieldSetText(Sender: TField; const Text: String);
begin
  ADOQuery1.Recordset.AbsolutePosition:=ADOQuery1.RecNo;
  ADOQuery1.Recordset.Fields[1].Value:=Text;
end;

procedure TForm1.ADOQuery1DecFieldGetText(Sender: TField; var Text: String; DisplayText: Boolean);
begin
  ADOQuery1.Recordset.AbsolutePosition:=ADOQuery1.RecNo;
  Text:=VarToStr(ADOQuery1.Recordset.Fields[1].Value);
end;

Of course, due to Borland's inherent shortcomings, the actual code may be more, and a lot of judgments need to be added. In fact, the basic principle is similar to the previous method, which is to bypass Borland's field definitions and write data directly to the Recordset.

5. This method is generally too rosy, that is, directly bypassing the data sensing controls to operate, so that you can do whatever you want.

In general, the third method is the best
Reply

Use magic Report

1

Threads

27

Posts

24.00

Credits

Newbie

Rank: 1

Credits
24.00

 China

 Author| Post time: 2020-7-24 18:45:01
| Show all posts
It seems that delphi does not have any floating point data type that can represent 123456789012.12345678
This value (except for Variant, Variant is not convenient to use in a 3-layer system).
Double, Extend will not work

There is a decimal type in .net, which can represent 29 digits.
delphi2006 for win32 still does not support the decimal type.

Therefore, none of the above methods are feasible.
Methods 4 and 5 may be feasible, but the changes are too large.
No modification for the time being, only 15-bit precision is supported.
Reply

Use magic Report

0

Threads

9

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-7-25 19:15:02
| Show all posts
If you want to make small changes, the fourth method is the simplest. Write these two as general procedures and call them where there are fields.

Then when you open the table, you can dynamically set the OnGetText and OnSetText events of the field as a general process. This is relatively simple and the window does not need to be changed.

In fact, all the data of the database in the Delphi background is transmitted as text, and it is converted when OnSetText. So the first thing to say is that the decimal data is controlled by string. In fact, Delphi itself controls the decimal data by string. You can see DB.pas for this. Source code.
Reply

Use magic Report

1

Threads

27

Posts

24.00

Credits

Newbie

Rank: 1

Credits
24.00

 China

 Author| Post time: 2020-7-26 16:30:01
| Show all posts
Method 4 does work for adoquery

But in the 3-layer structure:
ClientDataSet-->DataSetProvider-->AdoQuery-->DataBase
There is nothing we can do in this situation
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list