Thanks in advenced,
Jordi
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i:=0 to 3 do
begin
Listbox1.items.addObjects(inttostr(i),inttostr(i));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage(string(listbox1.Items.objects[0]));
end;
end.
if you only want to add strings than use this one:
listbox1.items.add(inttostr(i));
now you can use the following to retrieve the strings:
showmessage(listbox1.items[i]);
but if you want to add an object you have to add an descendant of
tobject like this
listbox1.items.addobject(form1.caption, form1);
hth
werner
"jordi bardají" schrieb:
if you just want to add a string - use
Listbox1.items.add(inttostr(i))and retrieve it with
Listbox1.items[i]Good luck!
Mike
Jordi
Stotter Werner <wer...@input.at> escribió en artículo
<378B5AD7...@input.at>...
> hi,
>
> if you only want to add strings than use this one:
> listbox1.items.add(inttostr(i));
>
> now you can use the following to retrieve the strings:
> showmessage(listbox1.items[i]);
>
> but if you want to add an object you have to add an descendant of
> tobject like this
> listbox1.items.addobject(form1.caption, form1);
>
>
> hth
> werner
>
> "jordi bardají" schrieb:
>
Jordi.
Mike Price <Mi...@Price.org> escribió en artículo
<378B5C8E...@Price.org>...
> Jordi
>
> if you just want to add a string - use
>
> Listbox1.items.add(inttostr(i))
>
> and retrieve it with
>
> Listbox1.items[i]
>
> Good luck!
>
> Mike
>
> "jordi bardají" wrote:
>
try:
var
footoo: string = 'footoo';
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := EmptyStr;
ListBox1.Items.AddObject('foo', @footoo);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Label1.Caption := PString(ListBox1.Items.Objects[0])^;
end;
--
Regards
Ralph (TeamB)
--
this does not really work. Delphi Strings (AnsiStrings) are
reference-counted and playing tricks like typecasting a string variable to
Pointer and storing it into the Objects list of a TStrings derivative
collides with the reference based lifetime management. The results are not
pretty <g>.
What works is to allocate memory for a Pchar, copy the string into it and
store the PChar, e.g.
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
s: String;
begin
for i:=0 to 3 do
begin
s:= InttoStr(i);
Listbox1.items.addObjects(S, StrNew( Pchar(S)));
end;
end;
However, you have to be very careful here not to end up with a memory leak.
Before you can delete any item from the listbox you have to explicitely
free the memory for the PChar stored into it Objects property:
If Assigned( Objects[i] ) Then
StrDispose( Pchar( Objects[i] ));
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
I think that this is the correct code:
It is mandatory to do pointer(strnew(pchar(p))).
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
s:string;
P:pchar;
begin
s:= 'a';
for i:= 0 to 3 do
begin
s:= s+s;
p:=Pchar(s);
Listbox1.items.addObject(inttostr(i), pointer(strnew(pchar(p))));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
for i:= 0 to 3 do
showmessage(pchar(listbox1.Items.objects[i]));
end;
Peter Below (TeamB) <10011...@compuXXserve.com> escribió en artículo
<VA.0000339e.00e84365@noname>...