Board index » delphi » Data Items for List Views

Data Items for List Views

I have a list view which holds filenames.  The full filename (including the
path) is stored in the individual item's data property.  The filename (excluding
the path) is displayed as the item's caption.

When the user amends the item caption I am using the following code
to amend the filename:

if Item.Caption<>ExtractFileName(String(Item.Data)) then
 begin
       s:=ExtractFilePath(String(Item.Data)) + Item.Caption;
       Item.Data:=PChar(s);
end;    

This throws up an invalid pointer operation error.

What am I doing wrong?

Nirmal Singh

 

Re:Data Items for List Views


Quote
> if Item.Caption<>ExtractFileName(String(Item.Data)) then
>  begin
>        s:=ExtractFilePath(String(Item.Data)) + Item.Caption;
>        Item.Data:=PChar(s);
> end;

 i'm not sure, but does this work?

        Item.Data := StrNew(s);

             HTH, Aaron

Re:Data Items for List Views


Quote
On Tue, 13 Aug 2002 21:28:39 +1000, "Aaron Chan" <n...@spam.com> wrote:
>> if Item.Caption<>ExtractFileName(String(Item.Data)) then
>>  begin
>>        s:=ExtractFilePath(String(Item.Data)) + Item.Caption;
>>        Item.Data:=PChar(s);
>> end;

> i'm not sure, but does this work?

>        Item.Data := StrNew(s);

I've managed to fix it by amending the code as follows:

s:=ExtractFilePath(String(Item.Data)) + Item.Caption;
Item.Data:=nil;
Item.Data:=PChar(s);

Other Threads