Board index » delphi » listview.Selected.SubItems.Text reading too much text?!?

listview.Selected.SubItems.Text reading too much text?!?

Hi,

I'm having some trouble sorting out what's going wrong in my little app.
Basically I display registry information in a TListView. Firstly the value,
then the data as the subitem.

The problem is when I read the subitem using the following code, I get two
extra characters at the end of my string:

listview.Selected.SubItems.Text

So I basically end up with two characters of garbage being written out.
Is there something I'm doing wrong? I've tried using Trim and TrimRight
without success.

I'm currently working around the problem by doing the following:

var
  temp : String;
  Buffer: array [0..255] of char;
begin
  StrLCopy(Buffer, PChar(listview.Selected.SubItems.Text),
    Length(listview.Selected.SubItems.Text) - 2);
  ...
end;

The -2 just drops the two illegal characters off the end.

Is this me or a Delphi bug? (Using D6 standard).

Thanks,
Aaron.

 

Re:listview.Selected.SubItems.Text reading too much text?!?


Quote
"Aaron" <a.mor...@NOSPAMparadise.net.nz> wrote in message

news:SWFa9.5761$CD2.786667@news02.tsnz.net...

Quote
> Hi,

> I'm having some trouble sorting out what's going wrong in my little app.
> Basically I display registry information in a TListView. Firstly the
value,
> then the data as the subitem.

> The problem is when I read the subitem using the following code, I get two
> extra characters at the end of my string:

> listview.Selected.SubItems.Text

Try specifying the index of the SubItem you are referring to - because the
Item can have more than one SubItem. This should return the proper string
value:

   ListView.Selected.SubItems[0];

Antti Kurenniemi

Re:listview.Selected.SubItems.Text reading too much text?!?


Ah... spot on. Thank you :)

It works a treat now, and I can remove that extra code.

Cheers, Aaron.

Quote
"Antti Kurenniemi" <Antti_Kurenni...@hotmail.com> wrote in message

news:d8Ga9.5549$EL6.59861@news.kpnqwest.fi...
Quote
> "Aaron" <a.mor...@NOSPAMparadise.net.nz> wrote in message
> news:SWFa9.5761$CD2.786667@news02.tsnz.net...
> > Hi,

> > I'm having some trouble sorting out what's going wrong in my little app.
> > Basically I display registry information in a TListView. Firstly the
> value,
> > then the data as the subitem.

> > The problem is when I read the subitem using the following code, I get
two
> > extra characters at the end of my string:

> > listview.Selected.SubItems.Text

> Try specifying the index of the SubItem you are referring to - because the
> Item can have more than one SubItem. This should return the proper string
> value:

>    ListView.Selected.SubItems[0];

> Antti Kurenniemi

Other Threads