Archived

This topic is now archived and is closed to further replies.

MarkyD

TStrings?

Recommended Posts

MarkyD    127
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 ~

Share this post


Link to post
Share on other sites
Lifepower    136
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

Share this post


Link to post
Share on other sites