Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Troubles with AddObject

Posted on 1998-02-28
1
Medium Priority
?
616 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 400 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

670 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