Page 1 of 1

Script Variables

Posted: Thu May 11, 2023 8:22 pm
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"

Re: Script Variables

Posted: Fri May 12, 2023 11:36 am
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;

Re: Script Variables

Posted: Fri May 12, 2023 12:38 pm
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")

Re: Script Variables

Posted: Fri May 12, 2023 1:18 pm
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=');

Re: Script Variables

Posted: Fri May 12, 2023 2:08 pm
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.

Re: Script Variables

Posted: Fri May 12, 2023 7:49 pm
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.

Re: Script Variables

Posted: Wed May 17, 2023 9:34 pm
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?

Re: Script Variables

Posted: Thu May 18, 2023 8:42 am
by Sergey Tkachenko
I agree.
I made this change in my version.
Let me know if you need this change urgently.

Re: Script Variables

Posted: Thu May 18, 2023 1:06 pm
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?

Re: Script Variables

Posted: Sat May 20, 2023 3:28 pm
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.

Re: Script Variables

Posted: Sat Aug 05, 2023 2:42 pm
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.