Recent

Author Topic: Zeoslib  (Read 6335 times)

Hansvb

  • Sr. Member
  • ****
  • Posts: 351
Zeoslib
« on: May 26, 2014, 10:08:33 pm »
Hi, i'am using zeos 7.1.3a stable. 
numbers in a nvarchar field (Oracle) show like 5,6E4 in  stead of  5600.
In a much older version of zeos the numbers showd correct.

How to avoid the 5,6E4 notation?

dogriz

  • Full Member
  • ***
  • Posts: 119
    • Tech blog - Delphi, Lazarus, Firebird, Windows, Linux, Android...
Re: Zeoslib
« Reply #1 on: May 27, 2014, 07:39:03 am »
Select your number field in TZQuery or TZTable and play with DisplayFormat (eg. 0000, or #0...)
FPC 3.0.4
Lazarus 2.0.6
Debian x86_64, arm

Hansvb

  • Sr. Member
  • ****
  • Posts: 351
Re: Zeoslib
« Reply #2 on: May 27, 2014, 05:32:38 pm »
If yoill in : #### then the number will show correect. But that is not what i need.
The user will be able to add new query's or change query's. then i do not know the fields in the query. So i can not predefine the fielddisplay.
Is there a way to do in runtime?

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1251
Re: Zeoslib
« Reply #3 on: May 27, 2014, 07:16:03 pm »
Been there my friend...

A couple of options available to you.  As @dogriz suggested, you can set format.  Not comfortable with those myself (never know what all the different formats are), so you have a few more options.

The following code works...

Code: [Select]
Procedure TFrameGrid.InitialiseDataset(ADataset: TDataset);
Var
  i: Integer;
  oField: TField;
Begin
  If Not Assigned(ADataset) Then
    Exit;

  For i := 0 To ADataset.FieldCount - 1 Do
  Begin
    oField := ADataset.Fields[i];

    If oField.DataType In [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency] Then
      oField.OnGetText := @DatasetOnGetText;
  End;
End; 

Procedure TFrameGrid.DatasetOnGetText(Sender: TField; Var aText: Ansistring;
  DisplayText: Boolean);
Begin
  aText := Sender.AsString;
End;

Modifying your SQL so they no longer return values also works...  Easiest way I could find was to append a blank string...
Code: [Select]
Select Count(*) || '' As "Count"
From RandomTable

I used to workaround the issue by modifying the SQL.  All the grids I use are on a Frame, so I just added the first set of code to that frame, called InitialiseDataset everytime I opened a SQL.  (My issue is complicated by the fact that my grid never knows what the columns are going to be - end user can muck around the SQLs all they like - from what it sounds like - you're in the same boat as me)

UPDATE:  For completeness sake, here is where I originally yelled for help on the same subject.  This contains a link back to ZEOS bug ticket.

http://forum.lazarus.freepascal.org/index.php/topic,20696.msg120291.html#msg120291
« Last Edit: May 27, 2014, 07:20:36 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Hansvb

  • Sr. Member
  • ****
  • Posts: 351
Re: Zeoslib
« Reply #4 on: May 27, 2014, 08:30:44 pm »
Thanks, ik will try it tomorow.

is this the right way to call te procedure:

Code: [Select]
procedure TDataModule_Adress.ZQuery_AdressAfterOpen(DataSet: TDataSet);
begin
  InitialiseDataset(ZQuery_Adress.DataSource.DataSet);
end;

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1251
Re: Zeoslib
« Reply #5 on: May 27, 2014, 09:14:21 pm »
Dunno :-)  I called it immediately after Tdataset.open.  one way to find out though :-)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

mangakissa

  • Hero Member
  • *****
  • Posts: 1101
Re: Zeoslib
« Reply #6 on: May 28, 2014, 09:02:55 am »
Code: [Select]
InitialiseDataset(ZQuery_Adress.DataSource.DataSet);is the same as
Code: [Select]
InitialiseDataset(ZQuery_Adress);
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

miab3

  • Full Member
  • ***
  • Posts: 111
Re: Zeoslib
« Reply #7 on: May 28, 2014, 10:59:31 am »
That's one way to do it:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var I:integer;
begin
for I := 0 to ZQuery1.FieldCount - 1 do
  case ZQuery1.Fields[I].DataType of
    ftFloat, ftBCD, ftSmallint, ftInteger, ftWord:
        TNumericField(ZQuery1.Fields[I]).DisplayFormat := '#.##';
    ftCurrency:
        TNumericField(ZQuery1.Fields[I]).DisplayFormat := ',0.00';
  end;
end;

Michal

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1251
Re: Zeoslib
« Reply #8 on: May 28, 2014, 03:51:59 pm »
That's one way to do it:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var I:integer;
begin
for I := 0 to ZQuery1.FieldCount - 1 do
  case ZQuery1.Fields[I].DataType of
    ftFloat, ftBCD, ftSmallint, ftInteger, ftWord:
        TNumericField(ZQuery1.Fields[I]).DisplayFormat := '#.##';
    ftCurrency:
        TNumericField(ZQuery1.Fields[I]).DisplayFormat := ',0.00';
  end;
end;

Michal

Doesn't this just limit the display to 2 decimal places?  (as I said, I'm not strong with those format strings).   My issue is the end user can specify their own SQL's, and I'd hate to be limiting data to 2dp, when they may have wanted more, or even less.  TField.AsString correctly returns the expected number of decimal places if the user ROUND()'s their result.

I'm actually hoping you'll reply and correct me - I agree this is a nicer solution in that it leaves .OnGetText available for other uses...
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1251
Re: Zeoslib
« Reply #9 on: May 28, 2014, 03:56:02 pm »
Code: [Select]
InitialiseDataset(ZQuery_Adress.DataSource.DataSet);is the same as
Code: [Select]
InitialiseDataset(ZQuery_Adress);
Yes :-)  Well spotted.  As far as @Hansvb's code is concerned, it may be even better to call
Code: [Select]
procedure TDataModule_Adress.ZQuery_AdressAfterOpen(DataSet: TDataSet);
begin
  InitialiseDataset(DataSet);
end;
as this way he can link any number of Datasets to the one OnGetText, and they'll all work.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

miab3

  • Full Member
  • ***
  • Posts: 111
Re: Zeoslib
« Reply #10 on: May 28, 2014, 06:06:01 pm »

Doesn't this just limit the display to 2 decimal places? 

Yes.
I think  instead of '#.##' better be '0.##########'.

Michal
« Last Edit: May 28, 2014, 06:24:20 pm by miab3 »

Hansvb

  • Sr. Member
  • ****
  • Posts: 351
Re: Zeoslib
« Reply #11 on: May 29, 2014, 04:58:33 pm »
thans it works

 

TinyPortal © 2005-2018