Re: Strange listbox behaviour
- From: "Tom de Neef" <tdeneef@xxxxxxxx>
- Date: Wed, 9 May 2007 23:36:05 +0200
"Ikke" <ikke@xxxxxxx> schreef in bericht
news:Xns992BE93F2B89Aikkehierbe@xxxxxxxxxxxxxxxxx
Hi everybody,
One problem solved, another popping up...
I've got a listbox on a form, which contains a list of TFileInfo objects.
Here's the code behind the click event:
---
procedure TForm1.originalsClick(Sender: TObject);
var
f : TFileInfo;
idx : integer;
o : TObject;
begin
idx := TListBox(sender).ItemIndex;
o := TListBox(sender).Items.Objects[idx];
ShowMessage(IntToStr(idx) + ': ' + o.ClassName);
end;
---
Now, the strange thing is what happens when I click the listbox several
times in a row.
Let's say I click the second item. Here's what showmessage is showing me:
1st: 1: TFileInfo (which I expected)
2nd: 1: TIconImage
3rd: 1: TBrush
and then, after clicking again, I get an AccessViolation.
Nothing happens with the listbox or the program in the meantime, it's
just me clicking several times on the listbox.
Can somebody please shed some light on this issue?
I can't. But I want to remind you that your previous problem was caused by a
typecast error. Delphi will do a marvelous job in warning you about dangers
in your code - but typecasts are necessarily outside these checks. Try to
avoid them wherever you can is my advice.
If OriginalsClick will only be called when clicking the listbox, you can
replace Tlistbox(sender) by the name of the listbox. That removes one
uncertainty. And as long as you typecast Sender, add sender.ClassName to the
message string.
Tom
.
- Follow-Ups:
- Re: Strange listbox behaviour
- From: Ikke
- Re: Strange listbox behaviour
- References:
- Strange listbox behaviour
- From: Ikke
- Strange listbox behaviour
- Prev by Date: Strange listbox behaviour
- Next by Date: Re: Strange listbox behaviour
- Previous by thread: Strange listbox behaviour
- Next by thread: Re: Strange listbox behaviour
- Index(es):
Relevant Pages
|
|