Solved

Troubles with AddObject

Posted on 1998-02-28
1
611 Views
Last Modified: 2012-06-27
My trouble is in C++ Builder but if you tell me something about Delphi Im vey grateful.

Well, I wish associate each item of a ComboBox (Client Name)  with another text (Client Code), I think that i must do it with the method AddObject from Items, its prototipe is AddOboject(AnsiString,TObject), the code is

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    AnsiString SQLText;
    int indice;

    SQLText = "SELECT * FROM CLIENTES WHERE     NOMBRE LIKE '";
    SQLText = SQLText + ComboBox1->Text + "%'";
    Query1->SQL->Text = SQLText;
    Query1->Active = true;
    if (!Query1->Eof)
    {
      while (!Query1->Eof)
        {
        indice =   ComboBox1->Items->AddObject(Query1->FieldByName("N         OMBRE")->AsString
        ,Query1->FieldByName("CODIGO"));
        Query1->Next();
        }
    }
    Query1->Active = false;
}

Both ClientName, as CodeClient are on a database, as you see i associate the clientname(first parameter) with a TField Object, my trouble is that ...indice is ever the same!! ( indice ever has value equal to one, two...) and when i want retrieve from my Form. just stand the last item :((.

Thank you
0
Comment
Question by:dpina
1 Comment
 
LVL 4

Accepted Solution

by:
erajoj earned 200 total points
ID: 1359904
Of course "indice" always has the same value after the while-loop (at least as long as the database contents is constant).
I really do not understand what the "indice" variable does in your code, unless you want to find the index of the last item in the combobox.
If you want the "object" associated with an item in the combobox, you just do:

var
  MyObject: TObject;
// TObject MyObject;
     ...
  MyObject := Combo1.Items.Objects[ iIndex ];
//  MyObject = Combo1->Items->Objects[ iIndex ];
  if Assigned( MyObject ) then ...
//  if ( MyObject != NULL ) { ...

Probably not the answer for your question, but...

/// John

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 302
proper way to parse url in delphi 2 191
Sending Gmail through Delphi 3 102
Dev Express grid collapse 2 44
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now