SRL Archive - Help and Support

Check if var exists?


Gala

2012-04-23 15:37:42

Maybe this problem is really noobish, but I can't figure it out.
Is there a way to check if a var has a value? Like in PHP 'isset'?

Thx, Gala

Abu

2012-04-23 15:40:14

Don't you do

if Length(var) > 0 then //if it has a value, it should be greater than 0

Gala

2012-04-23 15:51:40

Is this not only for arrays?
Does it work for integers and strings, too?

Abu

2012-04-23 15:55:20

From: Gala
Is this not only for arrays?
Does it work for integers and strings, too?


No it works I think.


EDIT: Well this compiles anyway:
procedure Test;
var
day, pol: Integer;
begin
day := Length(pol);
if day > 0 then
Writeln('Hi!');
end;

EDIT2: No it doesn't :p

putonajonny

2012-04-23 15:56:11

From: Gala
Is this not only for arrays?
Does it work for integers and strings, too?


Length works for strings, not integers, you'd have to do something like:
if(variable = 0)then...

Brandon

2012-04-23 15:57:38

writeln(string = nil);
[LEFT]
writeln(int = 0);

writeln(ord(char) = 0);

writeln(char(somechar) = #0);

[/LEFT]


etc..

mixster

2012-04-23 16:01:04

What kind of craziness are you talking about?

PascalScript and Lape both set all variables to default values. If you need to check if you've given something a value already, you're doing something very wrong, but use a flag for it.

Gala

2012-04-23 16:20:56

From: mixster
What kind of craziness are you talking about?


Hehe.

Thx at all, I had an error in reasoning :duh: