#1 2022-12-13 20:01

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

GetGlobalVar and 7.4.0.2 Beta

7.4.0.2 Beta runs like a charm.

All the existing regular expression seem to run as before. So the extended functionality didn't crash any of the old pattern.

I could also throw away my mock of the SetScriptVar/GetScriptVar methods and use instead the new variants SetGlobalVar/GetGlobalVar.

But what I had to learn after some working and some not workings runs: GlobalVars aren't cleared between two preview runs. As I had moved some "initialized" booleans to the GlobalVars I was missing initialization on later runs.

I tried to find out programatically if I am at some code right after a new run - but this seems not to be manageable. So I just have to clear the GlobalVars in the first rule and use a script-local initialization flag.

A ReNamer-function which tells me the number of the rule I am in would have helped but my actual solution is OK.

So what remains? You could fix a little bit with one of these cool :

  1. change the behaviour to clear all GlobalVars on a new preview run. It might be of any use if the values where not cleared, but by now I don't have any scenario in mind.

  2. Put some information about the clearing (or not clearing) to your documentation. Is there any time the values are cleared? After changing the rules, doing a rename run or loading a preset? Or do all the value keep on living until the ReNamer instance is closed?

Offline

#2 2022-12-15 01:09

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: GetGlobalVar and 7.4.0.2 Beta

Global variables do not get cleared automatically, so they exist until cleared manually or until the application terminates.

This is as intended, as it's the most flexible behavior. However, it may be worthwhile adding an option (in application settings) to automatically clear global variables for each Preview.

The clearing aspect is now documented on the wiki.

Offline

#3 2022-12-15 01:14

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: GetGlobalVar and 7.4.0.2 Beta

Regarding the potential use cases for never clearing variables automatically...

A longer term plan is to implement an option for executing scripts at various stages of the application workflow, including before/after preview, before/after rename, maybe even on demand.

Offline

#4 2022-12-15 20:52

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: GetGlobalVar and 7.4.0.2 Beta

den4b wrote:

The clearing aspect is now documented on the wiki.

Looks good - so it is less investigative now wink

den4b wrote:

Regarding the potential use cases for never clearing variables automatically...

A longer term plan is to implement an option for executing scripts at various stages of the application workflow, including before/after preview, before/after rename, maybe even on demand.

Ok. With this upcoming there will be more options for clearing:

  1. Option to clear on each preview.

  2. instead of a) you could insert a rule as first rule to clear all or (as mentioned in wiki) via script initialization.

  3. if clearing is only needed seldom (for example at times rules are developed) there might be a button to clear all - or again a simple rule on top waiting for activation.

  4. Somewhat like c) would be the possibility to run rules "on demand"

If you think of flexible stages it would be helpful to query this stage from inside the scripts. If this is possible, initialization could (for example) take place every "before preview" stage.

I don't know if this is possible: One other idea for having stages in the rules would be to have special names for procedures or functions to be implemented ...

Offline

#5 2022-12-15 20:58

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: GetGlobalVar and 7.4.0.2 Beta

If I would like to have an array as one of the global vars. Does it really have to be that complex to add new values to it?

LocalArray      := GetGlobalVar('GlobalArray');
Len             := Length(LocalArray);
SetLength(LocalArray, Len+1);
LocalArray[Len] := ValueToBeAdded;
SetGlobalVar('GlobalArray', LocalArray);

Last edited by jogiwer (2022-12-16 15:07)

Offline

#6 2022-12-20 15:40

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: GetGlobalVar and 7.4.0.2 Beta

jogiwer wrote:

If I would like to have an array as one of the global vars. Does it really have to be that complex to add new values to it?

You can generalize it into a local function, for example:

procedure AppendGlobalVar(const Name: String; const Value: Variant);
var
  V: Variant;
  A: Array of Variant;
  I: Integer;
begin
  V := GetGlobalVar(Name);
  if VarIsEmpty(V) then
    A := [Value]
  else
  begin
    A := V;
    I := Length(A);
    SetLength(A, I + 1);
    A[I] := Value;
  end;
  SetGlobalVar(Name, A);
end;

begin
  AppendGlobalVar('GlobalArray', 'Hello');
  AppendGlobalVar('GlobalArray', 'World');
end.

Offline

Board footer

Powered by FluxBB