Re: pointer syntax
- From: "Bjørge" <bjorge@xxxxxxxxxxxxxxx>
- Date: Wed, 23 Nov 2005 13:26:04 +0100
Maarten Wiltink wrote:
> "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.
Oh yeah. Forgot the initialization
List:=nil;
....and I think for the nth time: "Why arent those initialized to nil in the
first place ?"
> 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.
Of course. What puzzles me is this: With strings and dynamic arrays it's
taken care of (the nil initialization, that is). Why not with other pointer
types ?
--
Bjørge
bjorge@xxxxxxxxxxxx
.
- Follow-Ups:
- Re: pointer syntax
- From: J French
- 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
- Re: pointer syntax
- From: Maarten Wiltink
- pointer syntax
- Prev by Date: Re: copy one character from a string.
- Next by Date: Re: copy one character from a string.
- Previous by thread: Re: pointer syntax
- Next by thread: Re: pointer syntax
- Index(es):