Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Initialize TStrings

301 views
Skip to first unread message

Gerald Schneider

unread,
Aug 8, 1999, 3:00:00 AM8/8/99
to
It's surely quite simple, but I always get the message: Warning: variable
'xxxx' has not been initialized

How can I initialize a variable of the type TStrings?

--
CU,
Gerald
eMail............gschneider@gmx.de
Homepage...http://surf.to/phreak
ICQ99a........4910692
Pager...........9494048@scall.de

Shane

unread,
Aug 9, 1999, 3:00:00 AM8/9/99
to
You cannot use TStrings direct since it's an abstract base class. You have
to use derive a class from it....or just use TStringList instead which
already derives from TStrings...

var MyStrings: TStringList;
i: Integer;
begin
MyStrings:= TStringList.Create;
try
MyStrings.Add('string1');
MyStrings.Add('string2');
MyStrings.Add('string3');

for i:=0 to MyStrings.Count-1 do
Memo1.Lines.Add(MyStrings.Strings[i]);

finally
MyStrings.Free;
end;
end;

HTH,
Shane Bridges


Gerald Schneider <gschn...@gmx.de> wrote in message
news:93414750...@news.mediaWays.net...

James King

unread,
Aug 9, 1999, 3:00:00 AM8/9/99
to
You need to do this:
MultipleDrivesList: TStringList;

MultipleDrivesList := TStringList.Create;

MultipleDrivesList.Free;

Gerald Schneider wrote in message <93414750...@news.mediaWays.net>...

GWhit41980

unread,
Aug 10, 1999, 3:00:00 AM8/10/99
to
In article <EHKr3.936$Co3....@news1.mia>, "James King"
<mang...@bellsouth.net> writes:

>>It's surely quite simple, but I always get the message: Warning: variable
>>'xxxx' has not been initialized

I haven't seen the code but it's common to get this message if the variable is
either created or 'initialised' _within_ a try finally block ie

SomeProcedure(...
var
i: integer;
begin
try
i:= 0;
//more code
finally
...
end;
end;

will produce the warning message.

SomeProcedure(...
var
i: integer;
begin
i:= 0; //moved out of try finally block
try
//more code
finally
...
end;
end;

won't.

As it's only _trying_ it, it isn't guaranteed to happen.

Gordon.

~~~~~~~~~~~~~~~~~~~~~~~~
Certifiable - definitely <g>

http://members.aol.com/mgcsoft/ (the function junction equation editor)
http://members.aol.com/delphistuf/delphstf.htm (Delphi bits and bobs and a
few links)


MGCSoft

0 new messages