Using Display Format lazarus / 16-Databases ---------------------------------------------------------------------- AKCarlow · 2014-11-03 10:34 I have a MySQL database imported from a creaky old MSAccess db. It has several columns that store monetary amounts, and the import set them all to decimal(19,4). I'm looking at some of these columns in Lazarus with TDBGrid -> TDataSource -> TSQLQuery -> TMySQL56Connection. In the TFieldDefs of the TSQLQuery for these fields the DataType is set (automatically) to ftFMTBcd, with Precision -1 and size 4. I would like to have the data displayed with two decimal places, instead of, as at present, 35.00 showing as 35, 35.70 showing as 35.7, and 35.72 showing, as desired, as 35.72. Anything I put in the DisplayFormat field of the Columns in the TDBGrid (eg 0.00, '0.00', "0.00", #,##0.00 etc) causes a crash. What am I doing wrong? ---------------------------------------------------------------------- exdatis · 2014-11-03 11:35 See: http://forum.lazarus.freepascal.org/index.php/topic,26272.msg1611 38.html#msg161138 p.s. I use ('#0.00' or '#00,0.00') ---------------------------------------------------------------------- AKCarlow · 2014-11-03 13:20 Thanks. I tried Code: [Select]procedure TfPayments.FormCreate(Sender: TObject); begin qTransacts.Fields[3].DisplayFormat:= '#0.00' end;    which I think is what you were suggesting, but I get a compile error: Identifier idents no member "DisplayFormat" ---------------------------------------------------------------------- exdatis · 2014-11-03 13:29 If I'm right, you tried to use transaction(qTransacts.Fields[3])?  You must use DataSet(query) and where is your query component? Is it on TfPayments?. Also, you need an activated query(opened) before you set format. I'm quite sure that query.Fields[index].DisplayFormat works(I use). Are you sure that is your query opened(because, you use onCreate-form event)? ---------------------------------------------------------------------- exdatis · 2014-11-03 13:53 Ah, sorry    use   TNumericField(query.Fields[index]).DisplayFormat:= '#0,00.00'; {* e.g 2,000.00 *} Sorry..... ---------------------------------------------------------------------- AKCarlow · 2014-11-04 10:29 qTransacts is a TSQLQuery on a table named Transacts. It is on the form fPayments. In case it is not active at form create, I've put the code (TNumericField(qTransacts.Fields[3]).DisplayFormat:= '#,##0.00'; ) for setting DisplayFormat in OnActivate. When I switch to the form I get an error eBCDOverflowException (screenshot attached). ---------------------------------------------------------------------- exdatis · 2014-11-04 11:54 Quote from: AKCarlow on November 04, 2014, 11:29:45 am.... in OnActivate. When I switch to the form I get an error eBCDOverflowException (screenshot attached). use onShow. ---------------------------------------------------------------------- exdatis · 2014-11-04 11:57 Part of my code(it's working):       //set labels and formats       dm.qGeneral.Fields[0].DisplayLabel:= 'PK'; {* dm->DataModule *}       dm.qGeneral.Fields[0].DisplayWidth:= 5;       dm.qGeneral.Fields[0].Alignment:= taLeftJustify;       dm.qGeneral.Fields[1].DisplayWidth:= 10;       dm.qGeneral.Fields[1].DisplayLabel:= 'Datum';       dm.qGeneral.Fields[1].Alignment:= taCenter;       TDateField(dm.qGeneral.Fields[1]).DisplayFormat:= 'dd.MM.yyyy';       dm.qGeneral.Fields[2].DisplayWidth:= 7;       dm.qGeneral.Fields[2].DisplayLabel:= 'Uplata';       TNumericField(dm.qGeneral.Fields[2]).DisplayFormat:= '#00,0.00';       dm.qGeneral.Fields[2].Alignment:= taRightJustify;       {* set fields 3,4 hide *}       dm.qGeneral.Fields[3].Visible:= False;       dm.qGeneral.Fields[4].Visible:= False;       dm.qGeneral.EnableControls; ---------------------------------------------------------------------- AKCarlow · 2014-11-11 18:13 I've tried various settings, without success. Reading around, it would appear that there is problem with setting DisplayFormat on fmtBCD fields. I'll live without formatting and hope it is fixed in the next release.