Recent

Author Topic: Float display format in LazReport  (Read 6914 times)

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Float display format in LazReport
« on: February 04, 2012, 10:16:24 am »
In a program I set custom float display format for datasets by reading a value from dataset "Options". I call on FormCreate this procedure:
Code: [Select]
procedure TFormMain.SetFloatDisplayFormat(Dataset: TDataSet);
var J:Integer;
begin
  //Set display format for Float type
  for J:=0 to Dataset.FieldDefs.Count-1 do begin
    if Dataset.FieldDefs[J].DataType=ftFloat
      then begin
        (Dataset.Fields[J] as TFloatField).DisplayFormat
          :=Options.FieldByName('FloatDisplayFormat').AsString;
      end;
  end;
end;
This way, every user can decide which float display format to use in dbrids, for example.

My question is: how can I do the same for LazReports, to have the same float display format in all reports, all float fields?

I tried to overload beforementioned procedure, for frDBDataset, in order to call it before ShowReport, but it seems that frDBDataset is not related to TDataset and does not have FieldDefs and Fields....
« Last Edit: February 04, 2012, 10:18:12 am by tatamata »

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: Float display format in LazReport
« Reply #1 on: January 29, 2014, 04:43:04 pm »
I have to ask the same question again, since I didn' find solution yet.
I tried to pass display format to a report this way:
frReport1.Values.FindVariable('vFloatDisplayFormat').Field:='#,##0.##';

and in frReport1 on a float field box, right click, choose "Variable format" and set there in a dialog I set variable format: Number, Custom and in textbox I put [vFloatDisplayFormat].

It doesn't work, I get some run-time error "External: SIGSEGV".

What am I doing wrong?
How to pass float display format to LazReport?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Float display format in LazReport
« Reply #2 on: January 29, 2014, 10:12:55 pm »
Do me a favor write a minimal sample application that demonstrates your problem and I'll look at it for you. Sorry but I'm a bit pressed for time.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: Float display format in LazReport
« Reply #3 on: February 01, 2014, 09:23:09 am »
Hello, taaz, thanks, but no need, I have figured it out:
In the reposrt itself, any float field has to be encapsuled in function FORMATFLOAT, inside a rectangle object:

Code: [Select]
[FORMATFLOAT([vFloatDisplayFormat], [SomeFloatField])]
While formating can be passed in GetValue event of the report component:

Code: [Select]
procedure TDataModule2.frReport1GetValue(const ParName: String;
  var ParValue: Variant);
begin
  if CompareText(ParName, 'vFloatDisplayFormat')=0 then begin
    ParValue:=DataModule1.ZMConnection1.FloatDisplayFormat;
    {ParValue:='#,##0.##';}
    end;
end;

If using GetValue event, then variables don't have to be defined under Categories/variables, they will be automatically detected in on GetValue event....

Regards

 

TinyPortal © 2005-2018