Solved

Borland 5.02 combobox database

Posted on 1997-08-12
18
853 Views
Last Modified: 2013-12-26
I'm trying to get a dialog box to retrieve data from a database to a combobox.  Then select an item from the combobox and pull up the information related to the item into another dialog box.  I'm new to OWL programming so code would be very helpful. Do I need to use the TDBLookupCombo function?  Can anyone help me?
0
Comment
Question by:atsac
[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
  • 8
  • 5
  • 5
18 Comments
 
LVL 4

Expert Comment

by:md041797
ID: 1299333
Have you checked \BC5\examples\vdbt\*.*
0
 
LVL 3

Expert Comment

by:msmits
ID: 1299334
I would guess that creating a function for the select action in the TDBLookupCombo which creates the other dialog box (with the selected item as a parameter for the constructor).
The Init function for the new dialog will set all the new controls to the correct item in the database.

0
 

Author Comment

by:atsac
ID: 1299335
I haven't checked \vdbt\*.*, but I will now.
I have an idea of how the flow chart looks, but I/m not sure how to the source code will look.  I'm trying to retrieve a column (let say column 1) from a database, put the info in the combobox and then select an item (column 1, row 3 in database)and retieve the other 3 columns in row 3 into another dialog box.  I'm learning on my own so it's very tough.
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 3

Expert Comment

by:msmits
ID: 1299336
I can try to create some example source code for you and post it here as an answer including some instructions on the dialog creation.

0
 

Author Comment

by:atsac
ID: 1299337
I have created a dialog box and in my RC file I have a TDBLookupCombo in my dialog box.  Now I'm stuck. I can't seem to get the source code to compile the call to the dialog box when the TDBLookupCombo is present.
0
 
LVL 4

Expert Comment

by:md041797
ID: 1299338
Show your code.
Post as much code as you need to show what's going on.
0
 
LVL 3

Expert Comment

by:msmits
ID: 1299339
The TDBLookupCombo is not the control to use for what you want. Actually none of the Data-Aware controls do exactly what you want. The Grid control can be co-erced to the functionality, but it is dog slow.
You must create a Dialog with a normal TComboBox and fill it from a TTable (actually I currently use a hidden TDBText and manipulate the TTable). I am having a little trouble with linking the code and instability in the BC++ 5.02 environment which I assume are with the VBX stuff. I constantly get crashes of the IDE. I will try this weekend on my other machine.
0
 

Author Comment

by:atsac
ID: 1299340
class TAtsacDial : public TDialog { //class for combobox
  public:
    TAtsacDial(TWindow* parent, TResId res_id);
    ~TAtsacDial(){delete ComboBox; delete EditText1; }
  protected:
    void SetupWindow();
    static const int TextLen;
    TComboBox* ComboBox;
    TStatic* EditText1;

TAtsacDial :: TAtsacDial(TWindow* parent, TResId res_id) //combobox creation
             :TDialog(parent, res_id)
{
  ComboBox=new TComboBox(this, IDC_COMBOBOX1);
  EditText1=new TStatic(this, IDC_LISTBOX1);
}
const int TAtsacDial::TextLen = 50;

void TAtsacDial::SetupWindow()  //set data to combobox
{
  ComboBox->Create();
  ComboBox->AddString("123");
 
  char buf[TextLen]="";
  int index = ComboBox->GetSelIndex();
  int strLen;

  ComboBox->GetString(buf,index);
  strLen = ComboBox->GetStringLen(index);
  EditText1->SetText(buf);  //trying to get string 123 to print from                                              combobox to edit box in same                                                      dialog box, but not working.
}

This is part of my code. I wanted to make sure i could write to a combobox, but i select 123 and nothing happens.  I wanted to write the string length to the edit box contained in the same dialog box.  This was just a simple test.  If I need to use the combo box with TTable, how do I do that?  Since this seems to be a muliti-step problem, I really want to focus on how to get a database into a combobox.  Then after that proceed to the next step.
0
 
LVL 4

Expert Comment

by:md041797
ID: 1299341
You have stumbled on a really hard / really common problem in OWL.  You forgot to call the base class SetupWindow().  This is guaranteed to cause freky problems.

void TAtsacDial::SetupWindow() //set data to combobox
{
  TDialog::SetupWindow();  <---------------HERE
//  ComboBox->Create(); <-------Also, this is not done in a dialog.  Its done by TDialog::SetupWindow().

  ComboBox->AddString("123");
           
  char buf[TextLen]="";

  int index = ComboBox->GetSelIndex();
  int strLen;

  ComboBox->GetString(buf,index);
  strLen = ComboBox->GetStringLen(index);
  EditText1->SetText(buf);

  }
0
 

Author Comment

by:atsac
ID: 1299342
md, thanks for the helpful tip, but i also need some code to help me read from a database.  This code was just a simple setup program to see if I could do it.  I still a little more code on importing a database to the Combobox.
0
 

Author Comment

by:atsac
ID: 1299343
md, sorry I had to reject your answer but, I need to unlock the question so msmits can reply to the question.  I need more info. on database importing to a dialog box.
0
 
LVL 4

Expert Comment

by:md041797
ID: 1299344
No problem.  I didn't answer your original question.  How's this:

Put a TTable object in your dialog box.  In you code do this:

TTable Table1 (*this, IDC_TTABLE1);

void MyDialog::SetupWindow () {
  TDialog::SetupWindow();
try {
  Table1.Open();
  Table1.First();
  while (!Table1.AtEOF) {
    string text = Table1.FieldByName( "CustNo" )->AsString;
    // store in combobox
    }
}
catch( EDatabaseError x ) {
      // The dataset could not be opened
      x.Show( );
}



void MyDialog::ComboSelected () {
  Table1.Open();
  string text = TheCombo->GetSelIndex(); // I think??
  TVarRecs values;
  values.Add(text.c_str());
  CustTable.FindKey(values);
  //display data.
  }




0
 
LVL 3

Expert Comment

by:msmits
ID: 1299345
I already answer the question to atsac via email (including full source code of the example program) as follows:

First create a dialog with the following elements:

  ComboBox
    type: drop-down list
  TTable
    set DatabaseName to your database
    set TableName to your table
    set Active to True
  TDataSource
    set DataSet to your TTable
  TDBText
    set DataSource to your TDataSource
    set DataField to some index field in your
      data table
    set Visible to False

  In the class expert add 'instance variable's for the ComboBox,
TTable and TDBText. The class definition and constructor function
of the dialog class will be updated by BC++.
  Now you have to fill the ComboBox with data. Do this with the
following code in SetupWindow (after the TDialog::SetupWindow()):

  myDBTable->First();
  while (! myDBTable->AtEOF) {
    myComboBox->AddString(((string)myDBText->Caption).c_str());
    ((TDataSet *)myDBTable)->Next();
  }

Second create a dataview dialog with the following elements:

  TTable
    set DatabaseName to your database
    set TableName to your table
    set Active to True
  TDataSource
    set DataSet to your TTable
  TDBText1
    set DataSource to your TDataSource
    set DataField to some interresting field in your
      data table
  TDBText2
    set DataSource to your TDataSource
    set DataField to some interresting field in your
      data table

  In the class expert add 'instance variable's for the TTable and
the two TDBText controls. The class definition and constructor
function of the dataview dialog class will be updated.
  To provide synchronisation add the following function to the
dataview class:

  void TDBDataViewDlg::SetCurrent(const char *key)
  {
    myDBTable->SetKey();
    myDBTable->FieldByName("Site No")->AsString = key;
    myDBTable->GotoKey();
  }

  Now goto the original dialog with the ComboBox and add a handler
function for the selection change for this combobox. The function
should look like this:

  void TDBLookupDlgClient::CBNSelchange()
  {
    char key[256];

    myComboBox->GetString(key, myComboBox->GetSelIndex());
    myDataView->SetCurrent(key);
  }

  Lastly, to create the dataview dialog box, you must add the
following code to the SetupWindow function of the main dialog
class (after the previously mentioned code):

  myDataView = new TDBDataViewDlg(this);
  myDataView->Create();

  myComboBox->SetSelIndex(0);
  CBNSelchange();

  The type of 'myDataView' is the dialog class of the dataview
dialog and should be added as such in the class header file as
member variable:

    TDBDataViewDlg *myDataView;

  I noticed that you have to add some libraries to build this all
correctly. In the TargetExpert you have to select VBX and OLE.
You also have to add manually the following lib's:

  bdtaf.lib
  bdtcf.lib
  bdtof.lib

  Now you can build and run to see things going.

0
 
LVL 4

Expert Comment

by:md041797
ID: 1299346
msmits has the better answer.  Please give me an F so he can insert as an answer.
0
 

Author Comment

by:atsac
ID: 1299347
md, thanks for trying. I'm know i'll have more questions so keep checking back.
0
 
LVL 3

Accepted Solution

by:
msmits earned 155 total points
ID: 1299348
OK, the answer is already provided in my last comment.

md: thanx for the compliment.
0
 

Author Comment

by:atsac
ID: 1299349
Adjusted points to 310
0
 

Author Comment

by:atsac
ID: 1299350
Thanks msmits for all the help!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

691 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