Difference between revisions of "ReNamer:Scripts:Initialize"

From den4b Wiki
Jump to navigation Jump to search
(Created page with 'Pascal Script code gets executed for every file name, but sometimes we need to run some sort of initialization procedure and run it only once. In order …')
 
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{Go|up=ReNamer:Scripts}}
 +
 
[[ReNamer:Pascal Script|Pascal Script]] code gets executed for every file name, but sometimes we need to run some sort of initialization procedure and run it only once. In order to achieve this we need to remember one simple fact: Boolean variables are initialized to "False" before the code is ran for the first time, so we can use this state for our own initialization procedure.
 
[[ReNamer:Pascal Script|Pascal Script]] code gets executed for every file name, but sometimes we need to run some sort of initialization procedure and run it only once. In order to achieve this we need to remember one simple fact: Boolean variables are initialized to "False" before the code is ran for the first time, so we can use this state for our own initialization procedure.
  
 
== Code ==
 
== Code ==
  
<source>
+
<syntaxhighlight lang="pascal">
 
var
 
var
 
   Initialized: Boolean;
 
   Initialized: Boolean;
Line 17: Line 19:
 
   // Main code here...
 
   // Main code here...
 
end.
 
end.
</source>
+
</syntaxhighlight>

Latest revision as of 16:04, 8 February 2017

Pascal Script code gets executed for every file name, but sometimes we need to run some sort of initialization procedure and run it only once. In order to achieve this we need to remember one simple fact: Boolean variables are initialized to "False" before the code is ran for the first time, so we can use this state for our own initialization procedure.

Code

var
  Initialized: Boolean;

procedure Initialize;
begin
  Initialized := True;
  // Initialization code here...
end;

begin
  if not Initialized then Initialize;
  // Main code here...
end.