TStrings?

Started by
1 comment, last by MarkyD 22 years, 4 months ago
This is the most confusing thing I''ve ever seen. For some reason, this code won''t work...

procedure DoSomeStuff;
var
   MyStrings: TStrings;
begin
     MyStrings:=TStrings.Create;
     MyStrings.Add(''Hello'');

// do some stuff here
 
     MyStrings.Free;
end;
 
The code works like normal, but when the line
MyStrings.Add(''Hello''); 
is executed, it causes an Abstract Error. To be honest I don''t know what an abstract error is (and I don''t really care) but whatever it is should it be appearing like this? Or am I missing something? ~ There''s no substitute for failure ~
Advertisement
Delphi should give you a warning when compiling this, you probably missed it: "constructing an instance containing abstract methods". TStrings is an abstract class, which should not be used as standalone.

Try using TStringList instead.

    procedure DoSomeStuff;var MyStrings: TStrings;begin      MyStrings:= TStringList.Create(); // creating TStringList instead of TStrings MyStrings.Add('Hello');// do some stuff here MyStrings.Free();end;  


- Arcane Lifepower -

"Although the world would call me free
Each day the more her slave am I
For in her very way to be
There's I don''t know what, I don't know why"


Edited by - Lifepower on December 11, 2001 1:45:04 PM
Oh. Seems so obvious now. Silly old me.

~ There''s no substitute for failure ~

This topic is closed to new replies.

Advertisement