Second example: same form with listview and two buttons:
// Will fail
procedure TForm1.AddString(Var S : String);
begin
with form1.listview1 do begin
if (Finddata(0,@s,true,true)=nil) then begin
with items.add do begin
data:=@s;
Caption:=s;
end;
end else
showmessage('Item already is in the listview');
end;
end;
// Working code
procedure TForm1.AddPChar(Var P : PChar);
begin
with form1.listview1 do begin
if (Finddata(0,P,true,true)=nil) then begin
with items.add do begin
data:=P;
Caption:=P;
end;
end else
showmessage('Item already is in the listview');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
Var S : String;
begin
s := 'First string';
AddString(s);
s := 'Second string';
AddString(s);
s := 'Third string';
AddString(s);
end;
procedure TForm1.Button2Click(Sender: TObject);
Var P : PChar;
begin
P := 'First string';
AddPChar(P);
P := 'Second string';
AddPChar(P);
P := 'Third string';
AddPChar(P);
end;