On Sat, 28 Nov 2009 12:10:48 -0500
Anthony Walter <sys...@gmail.com> wrote:

> procedure InitMyVariable(Value: T);
> function MyVariable: T;
> 
> implementation
> 
> var
>   PrivateMyVariable: T;
>   PrivateMyVariableSet: Boolean;
> 
> procedure InitMyVariable(Value: T);
> begin
>   if not PrivateMyVariableSet then
>     PrivateMyVariable := Value;
>   PrivateMyVariableSet := True;
> end;
> 
> function MyVariable: T;
> begin
>   Result := PrivateMyVariable;
> end;

PrivateMyVariableSet is not intialised, so will have an undefined
(random) value when InitMyVariable is first called.
Mattias' code given earlier avoids this problem.

Howard
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to