Ross Levis wrote: > 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. > > 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]); > > Not very efficient but nevermind.
You might want to take a look at my WideFormat function. It's in the JclWideFormat unit of the JCL. It's all in Delphi (no assembler) and it parses the standard format strings. You could adapt that code to handle your custom format strings and change your call to this: Result := FormatItemString(Result, Item.Caption, Item.Subitems[0], Item.Subitems[1], Item.Subitems[3]); Note this won't change your access-violation problem. It's just a comment on code efficiency. > 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? My advice would be to not use the contents of the UI control as the source of your program's data. Keep your data in a real data structure and only give the data to the UI control for display purposes. Then the UI control and the VCL wrapper object are no longer involved in whatever your crashing code is. I think TListView supports a "virtual" mode. It will trigger an event whenever it needs to know what to display in a cell, and you handle that event by returning the string from your internal data structure. This isn't the same as owner-draw mode -- you don't have to paint anything yourself. If TListView doesn't do that, then there's also Mike Lischke's free Virtual Tree View component. -- Rob _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

