Skip to main content
gamedev.net
🔒 Locked

TStrings?

Started by MarkyD Dec 11, 2001 at 12:28 PM 1 replies 1.1k views
Original Post
MarkyD
MarkyD
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 ~
Lifepower
Lifepower
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.