Solved

Troubles with AddObject

Posted on 1998-02-28
1
608 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

19 Experts available now in Live!

Get 1:1 Help Now