You start by adding a single string, with no associated object to the combo
box.
Then you add a second string (which will be 'id') to the combo box,
attaching an object to this string.
Then you try to access the object associated with the selected string.
But only every second string (the ones which are 'id') has an associated
object, so on the odd numbered strings you get an access violation.
I suspect you don't really want to be adding 'id' strings to the combo box.
In which case I would suggest:
New(pNewRec);
pNewRec^.ID:=rs.rdoColumns[0];
Combo.Items.AddObject(rs.rdoColumns[1], TObject(pNewRec));
Naturally I assume you will free the pNewRec objects you created when you
are finished with the combo?
David.
DB Solutions.
> Combo.Items.AddObject('id',);
> HI all.
>
> I am wanting to add an integer to an Item in a combobox as I add the item.
>
> (I am using a pointer to a record here too, and the only item in the
record is ID :Integer)
>
> Combo.Items.Add(rs.rdoColumns[1]);
>
> New(pNewRec);
> pNewRec^.ID:=rs.rdoColumns[0];
> Combo.Items.AddObject('id',TObject(pNewRec));
>
> this seems ok, BUT when I do the following
>
> ll_Provider:=pRec(cmbReadonly.items.Objects[cmbReadonly.ItemIndex])^.ID;
>
> if I do this, I get an Access violation.....can anyone see what I am doing
worng....OR suggest a better wat to do it ?
>
> Cheers, Jeremy Coulter
>
>
>
>
> Jeremy Coulter (Manager)
> Visual Software Solutions
> Christchurch, New Zealand
> PH 03-3521595
> FAX 03-3521596
> MOBILE 021-2533214
> www.vss.co.nz
>
> --------------------------------------------------------------------------
-
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"