[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 858
  • Last Modified:

Borland 5.02 combobox database

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
atsac
Asked:
atsac
  • 8
  • 5
  • 5
1 Solution
 
md041797Commented:
Have you checked \BC5\examples\vdbt\*.*
0
 
msmitsCommented:
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
 
atsacAuthor Commented:
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
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!

 
msmitsCommented:
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
 
atsacAuthor Commented:
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
 
md041797Commented:
Show your code.
Post as much code as you need to show what's going on.
0
 
msmitsCommented:
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
 
atsacAuthor Commented:
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
 
md041797Commented:
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
 
atsacAuthor Commented:
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
 
atsacAuthor Commented:
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
 
md041797Commented:
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
 
msmitsCommented:
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
 
md041797Commented:
msmits has the better answer.  Please give me an F so he can insert as an answer.
0
 
atsacAuthor Commented:
md, thanks for trying. I'm know i'll have more questions so keep checking back.
0
 
msmitsCommented:
OK, the answer is already provided in my last comment.

md: thanx for the compliment.
0
 
atsacAuthor Commented:
Adjusted points to 310
0
 
atsacAuthor Commented:
Thanks msmits for all the help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now