Solved

Troubles with AddObject

Posted on 1998-02-28
1
615 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month5 days, 3 hours left to enroll

635 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