BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TCheckListBox Items tag

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
JVines
Guest





PostPosted: Wed Sep 06, 2006 1:13 am    Post subject: TCheckListBox Items tag Reply with quote



What is the best way of attaching an int to each item in a TCheckListBox
or anything else that uses TStrings?
(I am populating a list box from a database table and would like to
associate an index with each item.)
Back to top
Clayton Arends
Guest





PostPosted: Wed Sep 06, 2006 2:12 am    Post subject: Re: TCheckListBox Items tag Reply with quote



I use the "Object" member for that. Usually I reinterpret_cast a pointer to
my real struct associated with the string but it will work just fine for a
numerical value.

Strings->AddObject(str, index);

- Clayton
Back to top
JVines
Guest





PostPosted: Wed Sep 06, 2006 8:11 am    Post subject: Re: TCheckListBox Items tag Reply with quote



This does not work. The item being associated with the string has to be
a TObject descendant. I need to be able to associate a simple int value.
Back to top
JD
Guest





PostPosted: Wed Sep 06, 2006 1:40 pm    Post subject: Re: TCheckListBox Items tag Reply with quote

JVines <dev_support (AT) phoenixresearch (DOT) biz> wrote:
Quote:

This does not work.

The example that Clayton provided needed some casting but it
does work.

Quote:
The item being associated with the string has to be a
TObject descendant.

To be more precise, is needs to be a TObject pointer.

Quote:
I need to be able to associate a simple int value.

A pointer is 32 bits as is an int so just cast the int as a
TObject* when you set it and cast the TObject* as an int when
you get it. For example:

set
Strings->AddObject( "SomeString", reinterpret_cast<TObject*>(SomeIndex) );
or
Strings->Objects[x] = reinterpret_cast<TObject*>( SomeIndex );

get
int Index = reinterpret_cast<int>( Strings->Objects[x] );

~ JD
Back to top
JVines
Guest





PostPosted: Fri Sep 08, 2006 2:58 am    Post subject: Re: TCheckListBox Items tag Reply with quote

[c++ Error] File.cpp(#): E2031 Cannot cast from 'Variant' to 'TObject *'

When the following line is used:

CheckListBox->Items->AddObject(TTable_Tbl->FieldValues["string"],
reinterpret_cast<TObject*>(TTable_Tbl->FieldValues["index"]);

Note: DataType for "index" is ftAutoInc
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Sep 08, 2006 3:02 am    Post subject: Re: TCheckListBox Items tag Reply with quote

"JVines" <dev_support (AT) phoenixresearch (DOT) biz> wrote in message
news:4500961d$3 (AT) newsgroups (DOT) borland.com...

Quote:
[c++ Error] File.cpp(#): E2031 Cannot cast from 'Variant' to 'TObject *'

When the following line is used:

CheckListBox->Items->AddObject(TTable_Tbl->FieldValues["string"],
reinterpret_cast<TObject*>(TTable_Tbl->FieldValues["index"]);

The FieldValues[] property uses a Variant. You cannot store that into the
TStrings::Objects[] property directly.

Quote:
Note: DataType for "index" is ftAutoInc

ftAutoInc is a 32-bit integer value, so simply store the value of the
FieldValues[] property into an 'int' variable, and then store that into the
Objects[] property, ie:

int index = TTable_Tbl->FieldValues["index"];
CheckListBox->Items->AddObject(TTable_Tbl->FieldValues["string"],
reinterpret_cast<TObject*>(index));


Gambit
Back to top
DreamChaser
Guest





PostPosted: Wed Feb 28, 2007 8:28 am    Post subject: Re: TCheckListBox Items tag Reply with quote

Quote:

When the following line is used:

CheckListBox->Items->AddObject(TTable_Tbl->FieldValues["string"],
You could change this part
reinterpret_cast<TObject*>(TTable_Tbl->FieldValues["index"]);
to:

reinterpret_cast<TObject*>(TTable_Tbl->FieldByName("index")->AsInteger);

I believe :)

DC
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.