Lazarus

Programming => Packages and Libraries => LazReport => Topic started by: Hydexon on May 22, 2018, 03:10:37 am

Title: [SOLVED] Report variables are not displayed using FindVariable().Field
Post by: Hydexon on May 22, 2018, 03:10:37 am
I have an little app which processes different reports, and i have variables which differs each other, in order to keep it simple and readable, i use the method TfrReport.Values.FindVariable('MyVar').Field to set it up in a procedure, my main problem is setting variables in OnGetValue event are easy, but FindVariable method no.

After researching a lot about for my problem, it simply doesn't work.

my procedure is like this (this loads a lot of specific data into variables specified for each type of report i have)

Code: Pascal  [Select][+][-]
  1. procedure TBoletaViewerForm.SetRecordsData;
  2. begin
  3. frReport1.Values.FindVariable('FieldVarTest').Field :=  'TEST' ;
  4. end;
  5.  

This code is called on the FormShow event, with the following code:
Code: Pascal  [Select][+][-]
  1.   frReport1.LoadFromFile(FReportFile);
  2.   if frReport1.PrepareReport then begin
  3.      SetRecordsData;
  4.      frReport1.ShowPreparedReport;
  5.   end;
  6.  

The FindVariable('FieldVarTest') function finds the variable and sets it up in the Field property correctly, but doesn't display anything in the report, if i move that in the OnGetValue event instead like this:

Code: Pascal  [Select][+][-]
  1. if ParName = 'FieldVarTest' then ParValue := 'Test Field Working!';
  2.  

works as intended.
I've tried a lot of alternatives such frVariables.Variables and doesn't work too, and a lot of answers points to the same FindVariable() but doesn't work neither. i getting a bit burnout trying to solve this.

Thanks.
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: taazz on May 22, 2018, 04:01:08 am
there is a smalle demo that shows variable access at http://forum.lazarus.freepascal.org/index.php/topic,40304.msg278363.html#msg278363
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: Hydexon on May 22, 2018, 05:03:14 am
there is a smalle demo that shows variable access at http://forum.lazarus.freepascal.org/index.php/topic,40304.msg278363.html#msg278363

Already tried it, but uses an really cumbersome way to do those things, some reports of mine have LOTS of TfrMemoView using those variables, and i have a lot of complex reports which needs to load a lot of data
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: balazsszekely on May 22, 2018, 05:25:06 am
@Hydexon

You should switch to Fortesreport. It's based on Quickreport, it also has bands, but you can access the report components directly. It's far better then Lazreport in my opinion. Download link: https://packages.lazarus-ide.org/fortes4lazarus3.24.zip
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: Hydexon on May 22, 2018, 05:39:07 am
@Hydexon

You should switch to Fortesreport. It's based on Quickreport, it also has bands, but you can access the report components directly. It's far better then Lazreport in my opinion. Download link: https://packages.lazarus-ide.org/fortes4lazarus3.24.zip

I knew it using LazReport in first place was a bad idea, i was thinking to move to FortesReport too, but oh well, i just i have to redesign the reports again, the data loading code was nothing overly complex and pretty isolated from the other code.

Thanks you.
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: taazz on May 22, 2018, 05:41:57 am
there is a smalle demo that shows variable access at http://forum.lazarus.freepascal.org/index.php/topic,40304.msg278363.html#msg278363 (http://forum.lazarus.freepascal.org/index.php/topic,40304.msg278363.html#msg278363)

Already tried it, but uses an really cumbersome way to do those things, some reports of mine have LOTS of TfrMemoView using those variables, and i have a lot of complex reports which needs to load a lot of data
Sorry this makes no sense to me, what "uses an really cumbersome way" means exactly? does it work or not? If it works then use if not provide a demo showing the problem.
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: Hydexon on May 22, 2018, 06:56:53 pm
When i mean about cumbersome, i mean of this:

Code: Pascal  [Select][+][-]
  1.  
  2. if (View is TfrMemoView) then
  3.   begin
  4.     if (View as TfrMemoView).Name = 'mPost' then
  5.       (View as TfrMemoView).Memo.Text := ' ' + edPost.Text;
  6.     if (View as TfrMemoView).Name = 'mDepartment' then
  7.       (View as TfrMemoView).Memo.Text := ' ' + edDepartment.Text;
  8.     if (View as TfrMemoView).Name = 'mDate' then
  9.       (View as TfrMemoView).Memo.Text := ' ' + FormatDateTime('MM.DD.YYYY', DP.Date);
  10.   end;
  11.  

in the frReportEnterRect event, and also i need to load the data and set the variables once (where talking about dozens of variables, and many of them are from different reports), since i call my database several times. i prefer do like this, an more cleaner way to do things:

Code: Pascal  [Select][+][-]
  1. procedure TBoletaViewerForm.SetRecordsData;
  2. begin
  3. frReport1.Values.FindVariable('FieldVarTest').Field :=  'TEST' ;
  4. end;
  5.  
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: taazz on May 22, 2018, 07:48:39 pm
When i mean about cumbersome, i mean of this:

Code: Pascal  [Select][+][-]
  1.  
  2. if (View is TfrMemoView) then
  3.   begin
  4.     if (View as TfrMemoView).Name = 'mPost' then
  5.       (View as TfrMemoView).Memo.Text := ' ' + edPost.Text;
  6.     if (View as TfrMemoView).Name = 'mDepartment' then
  7.       (View as TfrMemoView).Memo.Text := ' ' + edDepartment.Text;
  8.     if (View as TfrMemoView).Name = 'mDate' then
  9.       (View as TfrMemoView).Memo.Text := ' ' + FormatDateTime('MM.DD.YYYY', DP.Date);
  10.   end;
  11.  
is that from GetMem's demo? I didn't looked it I assume that the code I posted was enough for variables.
in the frReportEnterRect event, and also i need to load the data and set the variables once (where talking about dozens of variables, and many of them are from different reports), since i call my database several times. i prefer do like this, an more cleaner way to do things:

Code: Pascal  [Select][+][-]
  1. procedure TBoletaViewerForm.SetRecordsData;
  2. begin
  3. frReport1.Values.FindVariable('FieldVarTest').Field :=  'TEST' ;
  4. end;
  5.  
How about this?
Code: Pascal  [Select][+][-]
  1. procedure TBoletaViewerForm.SetRecordsData;
  2. begin  frVariables.Variable['Test1'] := 'This is a test' ;end;
  3.  
Is this cumbersome?

from your description so far I'm thinking you should be using custom dataset not variables. In any I wish you grate fun and success with your chosen solution.
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: jesusr on May 22, 2018, 09:13:39 pm
Quote
frReport1.Values.FindVariable('FieldVarTest').Field :=  'TEST' ;

If this doesn't raise an access violation this means that you have actually defined a 'variables editor' variable, how is that defined? as linked to a dataset field, as "other" and then as an expression?, is it assigned to [NONE]?.

 If it is set to [NONE] in the editor then this might be the answer, you are changing the field but its marked as unasigned, is not much useful this way, at run time you would have to change the type to other than vtNotAssigned.
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: Hydexon on May 23, 2018, 05:26:14 pm
Quote
frReport1.Values.FindVariable('FieldVarTest').Field :=  'TEST' ;

If this doesn't raise an access violation this means that you have actually defined a 'variables editor' variable, how is that defined? as linked to a dataset field, as "other" and then as an expression?, is it assigned to [NONE]?.

 If it is set to [NONE] in the editor then this might be the answer, you are changing the field but its marked as unasigned, is not much useful this way, at run time you would have to change the type to other than vtNotAssigned.

Sorry for the late response
I've noticed all my needed variables are set to [None] as value in the Variables editor, i have to change it to Unassigned in order to work?. It's not linked to any dataset tho.
Title: Re: Report variables are not displayed using FindVariable().Field
Post by: Hydexon on May 23, 2018, 05:37:56 pm
It worked!, assign the variable's value to Expression and adding an QuotedStr around my real value in Pascal code made it to work!, thanks!.
TinyPortal © 2005-2018