Variables not being reset
Not sure if this is a bug but is definitely something for people to be careful about.
If I have a procedure and in it I declare a local variable eg
function Steve(StringToTest: string): string;
var
sLocalVar: string;
begin
if Pos(':', StringToTest) > 0 then
sLocalVar := 'Fred';
Result := 'Jim ' + sLocalVar;
end;
If I call function Steve and pass in 'aaa : bbb' then I get back 'Jim Fred' as expected.
If I then call Steve AGAIN and pass in 'aaabbb' then I will still get 'Jim Fred' out.
The problem is that sLocalVar is not being reset even though it goes out of scope.
You may say that all local variables should be implicitly initialised but I guess Delphi makes me lazy.
Anyway, one to watch out for as it caused me grief for quite a few hours today.
Cheers
Steve
If I have a procedure and in it I declare a local variable eg
function Steve(StringToTest: string): string;
var
sLocalVar: string;
begin
if Pos(':', StringToTest) > 0 then
sLocalVar := 'Fred';
Result := 'Jim ' + sLocalVar;
end;
If I call function Steve and pass in 'aaa : bbb' then I get back 'Jim Fred' as expected.
If I then call Steve AGAIN and pass in 'aaabbb' then I will still get 'Jim Fred' out.
The problem is that sLocalVar is not being reset even though it goes out of scope.
You may say that all local variables should be implicitly initialised but I guess Delphi makes me lazy.
Anyway, one to watch out for as it caused me grief for quite a few hours today.
Cheers
Steve
Comments