Script Variables

ReportWorkshop support and discussion (TRichView reporting add-on)
Post Reply
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Script Variables

Post by Ceprotec »

When I assign an empty value to a variable, when using it right away, it is not recognized (rvrgeVariableUnknown)

Code: Select all

set %liv_fol_ins = ""
set %liv_fol_ins = %liv_fol_ins+"text"
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Script Variables

Post by Sergey Tkachenko »

I confirm the problem. It happens when this script is executed twice.

Quick fix.
Open RVReportGenerator.pas
Change the line 4373 from

Code: Select all

SL.Values[VarName] := VarToUStr(Val)
to

Code: Select all

SetValueWithoutDeletion(SL, VarName, VarToUStr(Val))
Then define the procedure SetValueWithoutDeletion as

Code: Select all

procedure SetValueWithoutDeletion(SL: TStringList; const Name, Value: TRVUnicodeString);
var
  I: Integer;
begin
  I := SL.IndexOfName(Name);
  if I < 0 then
    SL.Add(Name + '=' + Value)
  else
    SL.Strings[I] := Name + '=' + Value;
end;
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Re: Script Variables

Post by Ceprotec »

Partially resolved. It still happens with the first record in the first generation of the report (in the second generation it works)

Image

Code: Select all

set %teste = ""
set %teste = Upper(%teste) + Upper("1")
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Script Variables

Post by Sergey Tkachenko »

When do you call this script?
The variable is not assigned before the first call of "set".
You can initialize it in the script that is called before report generation:

Code: Select all

RVReportSetScriptAsString(rv, rvrsOnStart, 'set %teste = ""', True);
Or you can initialize RVReportGenerator's variables before executing:

Code: Select all

RVReportGenerator.Variables.Clear;
RVReportGenerator.Variables.Add('teste=');
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Re: Script Variables

Post by Ceprotec »

Sergey Tkachenko wrote: Fri May 12, 2023 1:18 pm When do you call this script?
The variable is not assigned before the first call of "set".
You can initialize it in the script that is called before report generation:

Code: Select all

RVReportSetScriptAsString(rv, rvrsOnStart, 'set %teste = ""', True);
Or you can initialize RVReportGenerator's variables before executing:

Code: Select all

RVReportGenerator.Variables.Clear;
RVReportGenerator.Variables.Add('teste=');
Initializing the variable (rvrsOnStart or RVReportGenerator.Variables.Add) resolved the issue.

I add scripts in TRVReportTableItemInfo.RowGenerationRules.

PS: If the script is added to rvrsBeforeRecord, it is not necessary to initialize the variable. If I add to rvrsAfterRecord, I need to initialize the variable as you demonstrated.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Script Variables

Post by Sergey Tkachenko »

Ceprotec wrote: Fri May 12, 2023 2:08 pm PS: If the script is added to rvrsBeforeRecord, it is not necessary to initialize the variable. If I add to rvrsAfterRecord, I need to initialize the variable as you demonstrated.
As expected. If a variable is defined in the script, and If the script is called after processing a record, this variable is not defined when processing the first record.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Re: Script Variables

Post by Ceprotec »

When the report (report properties) does not have a data query assigned, the events are not called.

I think that at least the Script_OnStart and Script_OnEnd events should be triggered. Is it possible to make this change?
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Script Variables

Post by Sergey Tkachenko »

I agree.
I made this change in my version.
Let me know if you need this change urgently.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Re: Script Variables

Post by Ceprotec »

Sergey Tkachenko wrote: Thu May 18, 2023 8:42 am Let me know if you need this change urgently.
No.

When do you plan to release an update?

----

There used to be private forums for subscribers, if it still exists, can you subscribe me to them?
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Script Variables

Post by Sergey Tkachenko »

In the beginning of June.
I want to add a couple of features (multi-format Linux clipboard with FMXLinux 1.74, and starting value for markdown lists), but I am implementing it in background, because currently I am focusing on RVMedia.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Script Variables

Post by Sergey Tkachenko »

Finally, it is implemented, in ReportWorkshop v5.2.2. Script_OnStart and Script_OnEnd are executed even if the root DataQuery is empty.
Post Reply