[fpc-pascal] readonly variables
    Howard Page-Clark 
    hdpc at talktalk.net
       
    Sat Nov 28 19:14:40 CET 2009
    
    
  
On Sat, 28 Nov 2009 12:10:48 -0500
Anthony Walter <sysrpl at 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
    
    
More information about the fpc-pascal
mailing list