delphi - How do I associate a record with a TListBox item? -


I have a record type, I want to add that record type variable to TListbox and retrieve it on click event of TListbox Want to do Is this possible? If yes then how?

I've added it using

  lstbox.AddItem (data, Myrek);  

This is an error of incompatible types of data and the Myreck is the variable of MyRecord that I have created

to add:

 < Code> new (fptr1); ZeroMemory (fptr1, sizeof (fptr1 ^)); Fptr1 ^: = fptr ^; LstboxLeft.AddItem (path, TObject (fptr1));  

To retrieve:

  fptr: = PData (lstboxLeft.Items [lstboxLeft.ItemIndex]); Additem takes one tobject as the second parameter and one record is not an object  

You can either create your own record instead of an object (usually the best solution), or put the record into an object.

Here's an example using the record:

  type PMIRC = ^ TMyRec; TMyRec = Record I: Integer; End; Process TForm1.FormCreate (Sender: TObject); Var P: PMIRAC; New (P) start; P. I: = 42; ListBox1.AddItem ('A', TOBject (P)); End; Process TForm1.FormDestroy (Sender: Tubect); Var I: integer; Get started: Free memory for ListBox 1 from I: = 0 Setting Items.Count - 1 (PMIECC (List item 1. Item object [i]); End; Process TForm1.ListBox1Click (Sender: Tubbed); Var P: PMIRAC; Start P: = PMIRECE (Listblock 1. Items.Obsites [List Box 1. ITM Index]); Show message (intositor (PI)); End;  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -