Solved

TDBEdit float format

Posted on 2004-08-03
10
548 Views
Last Modified: 2010-04-04
Hi!

My problem is the following. I have a *.dbf file with float fields defined. All of them are of certain precision and I see it in the Database Desktop.
I need to format the TDBEdit components connected to the table so that they display trailing zeros. For example, if the precision of the field is 4 and the field contains 1.23, I need 1.2300 to be displayed.

How can I do that? I tried setting up the EditMask for the Table fields, but there are the following problems:
- The mask works only when the field is being edited and I need it to be always displayed with trailing zeros
- I cannot figure out the precision of the field run-time, it always equals 0. Why?

Any help is very much appreciated. Thanks in advance!
0
Comment
Question by:vk33
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Accepted Solution

by:
DarkCore_ earned 50 total points
ID: 11701457
Have you used "DisplayFormat" property for this field?
0
 
LVL 4

Author Comment

by:vk33
ID: 11701482
Where's that property? I haven't found it in the TField class definition.
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 75 total points
ID: 11701554
if u are not using persistent fields, then you can set it at runtime as follows
(best in the afteropen event)

TFloatField(Dataset.FieldByName('FloatFieldNameHere')).DisplayFormat := '#0.00';

meikl ;-)
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 2

Expert Comment

by:DarkCore_
ID: 11701635
Are you using fields definitons at design time? if true, then is in object inspector, in any other case, you can use meikl trick when opening your Dataset.

Edu
0
 
LVL 4

Author Comment

by:vk33
ID: 11701674
Aha, yes, I didn't try casting to specific field types. Thanks!

But still there's the problem remaining - I cannot get the field precision. When I do something like that:

       Precision := TFloatField(Table.Fields.FindField('smth')).Precision

it returns default precision value (15), not the one specified in the dbf-header. How can I deal with that?

If you consider this an off-topic, I can rate this post and open another one, or just raise the points.
0
 
LVL 2

Expert Comment

by:DarkCore_
ID: 11701793
maybe is problem of the default format for floats, controlled by locale settings.
0
 
LVL 2

Expert Comment

by:Molando
ID: 11701802
use the above to format, to get the precision look at:
table1.FieldDefs.Items[1].Precision;

Fielddefs are the definitions of the fields.
Precision specifies the number of digits of accuracy used to store the field value.
0
 
LVL 2

Expert Comment

by:Molando
ID: 11701819
If the above gives you the wrong value, look at table1.FieldDefs.Items[1].size;
0
 
LVL 4

Author Comment

by:vk33
ID: 11702310
Both table1.FieldDefs.Items[0].Precision and table1.FieldDefs.Items[0].size return 0.

How should I generally obtain the meta-infomration about the table fields?

Just have a try, you create a simple table with one float column using Database Desktop, specify the size and precision values for this column. Next you launch Delphi, put the TTable component, connect it to the dbf-file previously created, activate the table and see the FieldDefs. I think there's something wrong here, it doesn't display the real size and precision values. And it's the same when you consult the property runtime. :/
0
 
LVL 4

Author Comment

by:vk33
ID: 11713931
Ok, I guess it's better to start another topic.

Thanks for the help!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question