cancel
Showing results for 
Search instead for 
Did you mean: 

Declare and initialize a global variable

SOLVED
Highlighted
Occasional Contributor

Declare and initialize a global variable

Environment: TestComplete 14.30.3743.7 x64 with Delphi script

 

At function level a variable can be declared and initialized at the same time: the syntax is as follow

var i:integer=8;

 

Using the same syntax for a global variable will lead to a TC syntax error. Does anyone know if it is possible to initialize a global variable with a default value? or, is this allowed within the above mentioned environment?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Declare and initialize a global variable

Funny... I tried that syntax inside a function declaration and got a syntax error as well.

 

As I recall, when making variable declarations that are NOT a parameter of the function, you cannot declare a default value.

 

For example, THIS is allowed

 

function blah(i:integer =8):Variant;

begin
    
end;

while this is not

 

function blah:Variant;
var 
i:integer = 8; begin end;

It's been a while since I've done DelphiScript work... but I do know that it's different than Delphi.  While Delphi proper allows for assigning default values to global variables, I don't think that applies to the DelphiScript implementation in TestComplete.  There really isn't a "global" scope in a TestComplete project of script code so it doesn't apply.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

1 REPLY 1
Highlighted
Community Hero

Re: Declare and initialize a global variable

Funny... I tried that syntax inside a function declaration and got a syntax error as well.

 

As I recall, when making variable declarations that are NOT a parameter of the function, you cannot declare a default value.

 

For example, THIS is allowed

 

function blah(i:integer =8):Variant;

begin
    
end;

while this is not

 

function blah:Variant;
var 
i:integer = 8; begin end;

It's been a while since I've done DelphiScript work... but I do know that it's different than Delphi.  While Delphi proper allows for assigning default values to global variables, I don't think that applies to the DelphiScript implementation in TestComplete.  There really isn't a "global" scope in a TestComplete project of script code so it doesn't apply.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors