1

我正在处理的程序使用 if 语句在 SQL 中添加一行以获取另一个组合框的内容

procedure TFmNewGarage.ComboBoxCountryEnter(Sender: TObject);
begin
  ADOQueryCountry.SQL.Clear;
  ADOQueryCountry.SQL.Add('SELECT DISTINCT Country');
  ADOQueryCountry.SQL.Add(' FROM TblBaseCar');
  ADOQueryCountry.Open;
  while not ADOQueryCountry.Eof do
  begin
  ComboBoxCountry.Items.Add(ADOQueryCountry['Country']);
  ADOQueryCountry.Next;
  end;
end;

procedure TFmNewGarage.ComboBoxCountryChange(Sender: TObject);
begin
  SelA:=True;
  ComboBoxManufacturer.Show;
  ComboBoxCountry.Hide;
end;

procedure TFmNewGarage.ComboBoxManufacturerEnter(Sender: TObject);
begin
  ADOQueryManufacturer.SQL.Clear;
  ADOQueryManufacturer.SQL.Add('SELECT DISTINCT Manufacturer');
  ADOQueryManufacturer.SQL.Add(' FROM TblBaseCar');
  if SelA=true then
  ADOQueryManufacturer.SQL.Add(' WHERE Country=(ComboBoxCountry.seltext)');
  ADOQueryManufacturer.Open;
  while not ADOQueryManufacturer.Eof do
  begin
  ComboBoxManufacturer.Items.Add(ADOQueryManufacturer['Manufacturer']);
  ADOQueryManufacturer.Next;
  end;
end;

在运行时,这会导致错误 ComboBoxCountry.seltext has no default value,谁能帮我纠正这个错误?

4

1 回答 1

1

SelText不是您应该使用的属性。您需要Items选择的组合框值ItemIndex

var
 Country: string;
begin
  ...
  if ComboBoxCountry.ItemIndex <> -1 then
  begin
    Country := ComboBoxCountryItems[ComboBoxCountry.ItemIndex];
    ADOQueryManufacturer.SQL.Add('WHERE Country = ' + QuotedStr(Country));
  end;
end;
于 2013-04-08T16:01:18.523 回答