[DUG] Rare access violations reading listitem.subitems

Matthew Comb matt at ferndigital.com
Sun Aug 12 20:02:57 NZST 2007


Ross,

Two things.

1. What has access to these items ? Could a thread be altering these items
out from beneath you  ? (I noticed in a previous email from you in July that
you are working with threads).
2. Why not make the code a little safer

e.g.

If (length(Items.SubItems) > 2) then 
begin
  Result := StringReplace(Result,'%a',Item.Caption,[rfReplaceAll]);
  Result := StringReplace(Result,'%t',Item.SubItems[0],[rfReplaceAll]);
  Result := StringReplace(Result,'%s',Item.SubItems[1],[rfReplaceAll]);
  Result := StringReplace(Result,'%c',Item.Subitems[3],[rfReplaceAll]);
End
Else
Begin
  What the hell am I doing trying to access an array element that does not
exist.
End;



I have one user of my software which is experiencing an occasional access
violation in a routine which is simply reading some data stored in a
ListView.  The items in the listview are static and not changing at the
time.  There are always 5 columns of data, the Caption, and 4 SubItems.

The function simply replaces some parameters in a user formatted string with
data as follows.
 

Not very efficient but nevermind.

The first line always works.  Item.Caption gets replaced correctly every
time and never crashes.  If an Access Violation occurs, it's usually on the
2nd line, but sometimes this also works, and the crash occurs on the 3rd
line.  I've not seen a crash on the 4th line.

The items were loaded at least 20 minutes prior to this function being
called, so it's not a matter of the ListItem being deleted or created at the
same time.

It's completely beyond me.  Are there any known issues with ListViews in
Delphi 7, or any other ideas?

Thanks,
Ross.


_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe


_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe




More information about the Delphi mailing list