Solved

Troubles with AddObject

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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…

758 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

16 Experts available now in Live!

Get 1:1 Help Now