On 17.11.2011 19:07, Mattias Gaertner wrote:
On Thu, 17 Nov 2011 15:15:46 +0100
Sven Barth<pascaldra...@googlemail.com> wrote:
Emagine the following code:
procedure Foo(var aList: TStrings);
begin
aList.Free;
aList := TStrings.Create;
end;
var
l: TStringList;
begin
l := TStringList.Create;
Foo(l);
l.Sort;
end.
When you run this code you will have a big problem. Your "l" variable is
a TStringList, but after calling Foo your variable holds a TStrings
instance (which is lower in the hierarchy than TStringList)! If you now
call Sort you will get an access violation if you're lucky or some
strange error if not, because Sort is introduced by TStringList. Thus
you call into "nothing" when executing this on a TStrings.
Is the reason why this is forbidden more clear now?
The l.Sort is the important line, that is missing in the wiki example.
Maybe this example can replace the example in the wiki?
I have extended the example in the wiki a bit in the hope to clarify the
seriousness of this issue.
Regards,
Sven
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal