Re: Strange listbox behaviour



"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


.



Relevant Pages

  • Strange listbox behaviour
    ... I've got a listbox on a form, which contains a list of TFileInfo objects. ... procedure TForm1.originalsClick(Sender: TObject); ... idx: integer; ...
    (comp.lang.pascal.delphi.misc)
  • Re: Random listbox item selection
    ... How can i select next listbox item without obeying array order? ... Dim r As New Random ... Dim idx As Integer ... Still, the selection goes endless,never ends. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Random listbox item selection
    ... How can i select next listbox item without obeying array order? ... For random selection procedure; ... Dim r As New Random ... Dim idx As Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Random listbox item selection
    ... How can i select next listbox item without obeying array order? ... Dim r As New Random ... Dim idx As Integer ... It seems the random selection ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Opening multiple files with my applicaton
    ... i want their paths to be added into listbox in my ... This code works good when i try to open a "single" file with my app ... Dim cla As String= Environment.GetCommandLineArgs ... Dim idx as Integer ...
    (microsoft.public.dotnet.languages.vb)