[fpc-pascal] Is there a way to declare a static varible in a function body?

yu ping spingyu at gmail.com
Wed Nov 18 13:53:01 CET 2009


Thanks, you are realy clever:))

2009/11/18 Frank Peelo <f26p at eircom.net>

> On 18/11/2009 08:10, yu ping wrote:
>
>> Is there a way to declare a static varible in a function body? the varib=
le
>> should remain the value assigned from last call.
>>
>
> Typed constant, const /name/ : /type/ =3D /initial value/;
> Takes the initial value when the program starts, but you can assign new
> values to it. But the value remains constant between calls.
>
> e.g.
>
> Function NextI:Integer;
> const
>  NextValue:Integer =3D 0;
> Begin
>  NextI :=3D NextValue;
>  NextValue :=3D NextValue+1;
> end;
>
> var
>  x : Integer;
> Begin
>  for x :=3D 1 to 10 do
>    writeln(NextI);
> end.
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freepascal.org/lists/fpc-pascal/attachments/20091118/b8ce=
3b27/attachment.htm


More information about the fpc-pascal mailing list