Re: pointer syntax
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 23 Nov 2005 10:27:13 +0100
"Bjørge" <bjorge@xxxxxxxxxxxxxxx> wrote in message
news:4Z6dnWjEx7TyBB7e4p2dnA@xxxxxxxxxxxxxx
[...]
> procedure CheckCreateStringList(var List: TStringList);
> begin
> if not Assigned(List) then
> List:=TStringList.Create;
> end;
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
> List: TStringList;
> begin
> CheckCreateList(List);
> List.Free;
> end;
>
> I guess someone would claim that this is strange coding style,
> but it's perfectly valid ;-)
Er, no. List contains garbage at the moment you pass it to
CheckCreateStringList which inspects and possibly assigns it.
Things will go horribly wrong if the space it takes up was
previously in use by an Integer with the value three.
Making it an out parameter would make the call valid again, but
invalidate the test inside the procedure. It's a logical error
to read an out parameter until you've assigned it a value.
Groetjes,
Maarten Wiltink
.
- Follow-Ups:
- Re: pointer syntax
- From: Bjørge
- Re: pointer syntax
- References:
- pointer syntax
- From: swansnow
- Re: pointer syntax
- From: Maarten Wiltink
- Re: pointer syntax
- From: swansnow
- Re: pointer syntax
- From: Bjørge
- pointer syntax
- Prev by Date: Re: Writing Binary Files with TFileStream
- Next by Date: Re: pointer syntax
- Previous by thread: Re: pointer syntax
- Next by thread: Re: pointer syntax
- Index(es):