Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DisplayFormat of TDateTimeField/TFloatFields

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I'm setting up the SQL syntax for a query dynamically. I'm working against a SQL server 7.0 database (using Delphi 5).
Having set the query and activating it I want to display one of the fields (an average AVG calculated field). If I am dealing with a TFloatField then I set the DisplayFormat of the field to be '0.000' using 'query.Fields[1] AS TFloatField).DisplayFormat := '0.000'', similarly if dealing with a date/time (for averaging a time duration) I set the DisplayFormat using 'query.Fields[1] AS TDateTimeField).DisplayFormat := 'hh:mm:ss'' (only wanting to view the time element.
This process seems to operate OK outside the scope of my application, when I introduce it into my program (using exactly the same logic and syntax) when I set one of the QRDBText components in the QuickReport to have the appropriate DataSet/DataField (either the TFloatField or TDateTimeField as listed above) I am not seeing the data in the format as set at the query level. That is for the TFloatField I am seeing i.e. '8.3333333333' (want to see '8.333') or for the datetime am seeing '31/12/1899 03:20:00' (want to see '03:20:00'). It's as if the QuickReport is not picking up the DisplayFormat set against the Fields.
Can anyone suggest what I am missing here ?
Thanks in advance
Steve
 
Setting the DisplayFormat doesn't actually change the data at all, only how it is shown in data aware controls. I am not sure if you can get the "display" value yourself or not - try query.Fields[1].DisplayText. That might give you the value you're looking for.

Good luck! TealWren
 
You might be able to do it using a calculated string field associated with the TQuery, although you would have to create it dynamically in your case. Place the formatted string you want in that field, using the OnCalcFields event. Then use the calculated field for the report.
 
Quick Report operates at the dataset level and therefore operates at a lower level then TTable or TQuery which is where your formatting is usually applied.

TQRDBText components have their own display formatting property that you can use to format the display of your data.

Often I cheat, and place TQRText ( or whatever the label components are ) in the places I want the variable. Then create a method for the Band onPrint event, where I calculate and format the data, then assign the formatted string to the Caption property of labels.

Like I said, its cheating but it gets the job done. Especially, when your under the gun.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top