Retrieving Data From TDBLookupComboBox. Example

Applies to TestComplete 14.70, last modified on April 22, 2021

This example illustrates how to retrieve items of a TDBLookupComboBox control from a script. The TestDBLookupComboBox script routine posts the contents of a TDBLookupComboBox object to the test log.

The example works with the Mastapp sample application that is installed with Borland Delphi or C++Builder, and has the following requirements:

  • The Delphi and C++Builder Application Support plugin must be installed in TestComplete,

  • The Mastapp application must be compiled with debug information included (for instructions on how to do this, see Debug Info Agent).

JavaScript, JScript

function TestDBLookupComboBox()
{
  var p, w, s, CompanyCombo, DataSet, Field, B;

  // Obtain the process
  p = Sys.Process("mastapp");
  // Obtain the main form of the Mastapp application
  w = p.MainForm;
  // Bring up the main form
  // Press the Orders button
  w.OrderBtn.Click();
  // Obtain the Edit Order form
  w = p.EdOrderForm;
  // CompanyCombo is a TDBLookupComboBox control
  CompanyCombo = w.HeaderPanel.CompanyCombo;
  // Return the dataset and field
  DataSet = CompanyCombo.ListSource.DataSet;
  Field = DataSet.FieldByName(CompanyCombo.ListField);
  s = "";
  // Scan the dataset and save field values to a variable
  B = Dataset.RecNo;
  Dataset.DisableControls();
  Dataset.First();
  while (! Dataset.EOF)
  {
    s = s + Field.AsVariant + "\r\n";
    Dataset.Next();
  }
  Dataset.RecNo = B;
  Dataset.EnableControls();
  // Post results to the test log
  Log.Message("Items of the CompanyCombo", s);
}

Python

def TestDBLookupComboBox():

  # Obtain the process
  p = Sys.Process("mastapp")
  # Obtain the main form of the Mastapp application
  w = p.MainForm
  # Bring up the main form
  # Press the Orders button
  w.OrderBtn.Click()
  # Obtain the Edit Order form
  w = p.EdOrderForm
  # CompanyCombo is a TDBLookupComboBox control
  CompanyCombo = w.HeaderPanel.CompanyCombo
  # Return the dataset and field
  DataSet = CompanyCombo.ListSource.DataSet
  Field = DataSet.FieldByName(CompanyCombo.ListField)
  s = ""
  # Scan the dataset and save field values to a variable
  B = Dataset.RecNo
  Dataset.DisableControls()
  Dataset.First()
  while not Dataset.EOF:
    s = s + Field.AsVariant + "\r\n"
    Dataset.Next()
  Dataset.RecNo = B
  Dataset.EnableControls()
  # Post results to the test log
  Log.Message("Items of the CompanyCombo", s)

VBScript

Sub TestDBLookupComboBox
  Dim p, w, s, CompanyCombo, DataSet, Field, B

  ' Obtain the process
  Set p = Sys.Process("mastapp")
  ' Obtain the main form of the Mastapp application
  Set w = p.MainForm
  ' Bring up the main form
  ' Press the Orders button
  w.OrderBtn.Click
  ' Obtain the Edit Order form
  Set w = p.EdOrderForm
  ' CompanyCombo is a TDBLookupComboBox control
  Set CompanyCombo = w.HeaderPanel.CompanyCombo
  ' Return the dataset and field
  Set DataSet = CompanyCombo.ListSource.DataSet
  Set Field = DataSet.FieldByName(CompanyCombo.ListField)
  s = ""
  ' Scan the dataset and save field values to a variable
  B = Dataset.RecNo
  Dataset.DisableControls
  Dataset.First
  Do While Not Dataset.EOF
    s = s & Field.AsVariant & vbCrLf
    Dataset.Next
  Loop
  Dataset.RecNo = B
  Dataset.EnableControls
  ' Post results to the test log
  Log.Message "Items of the CompanyCombo", s
End Sub

DelphiScript

procedure TestDBLookupComboBox;
var p, w, s, CompanyCombo, DataSet, Field, B;
begin
  // Obtain the process
  p := Sys.Process('mastapp');
  // Obtain the main form of the Mastapp application
  w := p.MainForm;
  // Bring up the main form
  // Press the Orders button
  w.OrderBtn.Click;
  // Obtain the Edit Order form
  w := p.EdOrderForm;
  // CompanyCombo is a TDBLookupComboBox control
  CompanyCombo := w.HeaderPanel.CompanyCombo;
  // Return the dataset and field
  DataSet := CompanyCombo.ListSource.DataSet;
  Field := DataSet.FieldByName(CompanyCombo.ListField);
  s := '';
  // Scan the dataset and save field values to a variable
  B := Dataset.RecNo;
  Dataset.DisableControls;
  Dataset.First;
  while not aqConvert.VarToBool(Dataset.EOF) do
  begin
    s := s + Field.AsVariant + #13#10;
    Dataset.Next;
  end;
  Dataset.RecNo := B;
  Dataset.EnableControls;
  // Post results to the test log
  Log.Message('Items of the CompanyCombo', s);
end;

C++Script, C#Script

function TestDBLookupComboBox()
{
  var p, w, s, CompanyCombo, DataSet, Field, B;

  // Obtain the process
  p = Sys["Process"]("mastapp");
  // Obtain the main form of the Mastapp application
  w = p["MainForm"];
  // Bring up the main form
  // Press the Orders button
  w["OrderBtn"]["Click"]();
  // Obtain the Edit Order form
  w = p["EdOrderForm"];
  // CompanyCombo is a TDBLookupComboBox control
  CompanyCombo = w["HeaderPanel"]["CompanyCombo"];
  // Return the dataset and field
  DataSet = CompanyCombo["ListSource"]["DataSet"];
  Field = DataSet["FieldByName"](CompanyCombo["ListField"]);
  s = "";
  // Scan the dataset and save field values to a variable
  B = Dataset["RecNo"];
  Dataset["DisableControls"]();
  Dataset["First"]();
  while (! Dataset["EOF"])
  {
    s = s + Field["AsVariant"] + "\r\n";
    Dataset["Next"]();
  }
  Dataset["RecNo"] = B;
  Dataset["EnableControls"]();
  // Post results to the test log
  Log["Message"]("Items of the CompanyCombo", s);
}

Highlight search results