Zeoslib lazarus / 16-Databases ---------------------------------------------------------------------- Hansvb · 2014-05-26 20:08 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 · 2014-05-27 05:39 Select your number field in TZQuery or TZTable and play with DisplayFormat (eg. 0000, or #0...) ---------------------------------------------------------------------- Hansvb · 2014-05-27 15:32 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 · 2014-05-27 17:16 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.ht ml#msg120291 ---------------------------------------------------------------------- Hansvb · 2014-05-27 18:30 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 · 2014-05-27 19:14 Dunno :-)  I called it immediately after Tdataset.open.  one way to find out though :-) ---------------------------------------------------------------------- mangakissa · 2014-05-28 07:02 Code: [Select]InitialiseDataset(ZQuery_Adress.DataSource.DataSet);is the same as Code: [Select]InitialiseDataset(ZQuery_Adress); ---------------------------------------------------------------------- miab3 · 2014-05-28 08:59 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 · 2014-05-28 13:51 Quote from: miab3 on May 28, 2014, 10:59:31 amThat'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... ---------------------------------------------------------------------- Mike.Cornflake · 2014-05-28 13:56 Quote from: mangakissa on May 28, 2014, 09:02:55 amCode: [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. ---------------------------------------------------------------------- miab3 · 2014-05-28 16:06 Quote from: Mike.Cornflake on May 28, 2014, 03:51:59 pm Doesn't this just limit the display to 2 decimal places?  Yes. I think  instead of '#.##' better be '0.##########'. Michal ---------------------------------------------------------------------- Hansvb · 2014-05-29 14:58 thans it works