Recent

Author Topic: [SOLVED] Report variables are not displayed using FindVariable().Field  (Read 7328 times)

Hydexon

  • Full Member
  • ***
  • Posts: 170
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.
« Last Edit: May 23, 2018, 05:38:16 pm by Hydexon »
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Report variables are not displayed using FindVariable().Field
« Reply #1 on: May 22, 2018, 04:01:08 am »
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

Hydexon

  • Full Member
  • ***
  • Posts: 170
Re: Report variables are not displayed using FindVariable().Field
« Reply #2 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
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

balazsszekely

  • Guest
Re: Report variables are not displayed using FindVariable().Field
« Reply #3 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

Hydexon

  • Full Member
  • ***
  • Posts: 170
Re: Report variables are not displayed using FindVariable().Field
« Reply #4 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.
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Report variables are not displayed using FindVariable().Field
« Reply #5 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

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.
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

Hydexon

  • Full Member
  • ***
  • Posts: 170
Re: Report variables are not displayed using FindVariable().Field
« Reply #6 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.  
« Last Edit: May 22, 2018, 07:18:21 pm by Hydexon »
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Report variables are not displayed using FindVariable().Field
« Reply #7 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.
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

jesusr

  • Sr. Member
  • ****
  • Posts: 484
Re: Report variables are not displayed using FindVariable().Field
« Reply #8 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.

Hydexon

  • Full Member
  • ***
  • Posts: 170
Re: Report variables are not displayed using FindVariable().Field
« Reply #9 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.
« Last Edit: May 23, 2018, 05:28:25 pm by Hydexon »
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

Hydexon

  • Full Member
  • ***
  • Posts: 170
Re: Report variables are not displayed using FindVariable().Field
« Reply #10 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!.
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

 

TinyPortal © 2005-2018