Recent

Author Topic: Using Display Format  (Read 8386 times)

AKCarlow

  • New Member
  • *
  • Posts: 45
Using Display Format
« on: November 03, 2014, 11:34:52 am »
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?
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Using Display Format
« Reply #1 on: November 03, 2014, 12:35:32 pm »

AKCarlow

  • New Member
  • *
  • Posts: 45
Re: Using Display Format
« Reply #2 on: November 03, 2014, 02:20:10 pm »
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"
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Using Display Format
« Reply #3 on: November 03, 2014, 02:29:59 pm »
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)?
« Last Edit: November 03, 2014, 02:36:44 pm by exdatis »

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Using Display Format
« Reply #4 on: November 03, 2014, 02:53:57 pm »
Ah, sorry  :-[  >:(
use
  TNumericField(query.Fields[index]).DisplayFormat:= '#0,00.00'; {* e.g 2,000.00 *}

Sorry.....

AKCarlow

  • New Member
  • *
  • Posts: 45
Re: Using Display Format
« Reply #5 on: November 04, 2014, 11:29:45 am »
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).

Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Using Display Format
« Reply #6 on: November 04, 2014, 12:54:21 pm »
.... in OnActivate.

When I switch to the form I get an error eBCDOverflowException (screenshot attached).

use onShow.

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Using Display Format
« Reply #7 on: November 04, 2014, 12:57:04 pm »
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;     
« Last Edit: November 04, 2014, 01:01:01 pm by exdatis »

AKCarlow

  • New Member
  • *
  • Posts: 45
Re: Using Display Format
« Reply #8 on: November 11, 2014, 07:13:23 pm »
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.
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

 

TinyPortal © 2005-2018