[DUG] Rare access violations reading listitem.subitems
Ross Levis
ross at stationplaylist.com
Sun Aug 12 20:29:47 NZST 2007
I have put a try..except block around these now which is as good as your
code but it doesn't prevent the problem of replacements not occurring which
is the main problem.
I also suspected a thread issue initially. I do have 2 threads that update
a couple of the SubItems, but I checked these and they are only ever
accessed using Synchronize, so no problems there.
It is certainly an odd one. Cosmin's idea of something running on the users
computer causing window handles to be recreated could perhaps explain it,
but it sounds dodgy to me.
Thanks,
Ross.
-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Matthew Comb
Sent: Sunday, 12 August 2007 20:03
To: 'NZ Borland Developers Group - Delphi List'
Subject: RE: [DUG] Rare access violations reading listitem.subitems
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
_______________________________________________
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