Change a LookUpCombobox according to another

0

I would like to make a LookUpCombobox in Delphi behave as follows:

  • When the user clicked on naturalness: Brazilian or Brazilian, Born Abroad or Naturalized, another LookUpCombobox was automatically selected as Brazil country and was unavailable for change.
  • When the user selected Foreign, the other LookUpCombobox would be blank and the user would have the option to choose the country, but could not choose Brazil.

When I click on Post to save the values, the Country field is blank and does not save when it is Brazil. I made a showmessage() in the variable and it returns the correct country code that is 76.

Follow the code:

procedure TformCadastroEstudantes.DBLookupComboBoxNacionalidadeCloseUp(
  Sender: TObject);
  var nacionalidade : Integer;
  var pais :   Integer;
  var enabled : Boolean;

  begin

    nacionalidade := DBLookupComboBoxNacionalidade.KeyValue;
    pais := DBLookupComboBoxPais.KeyValue;
    enabled := True;

    AtualizaPaises(nacionalidade, pais, enabled);

    DBLookupComboBoxPais.KeyValue := pais;
    DBLookupComboBoxPais.Enabled  := enabled;
  end;

Here is the procedure code:

procedure AtualizaPaises(var nacionalidade : Integer; var pais: Integer; var enabled : Boolean);

begin

     if ((nacionalidade = 1) OR (nacionalidade = 2)) then
     begin
       pais := 76;
       enabled := False;

       with dm.sqlPaises do
       begin
         Close;
         SQL.Clear;
         SQL.Add('select * from PAISES');
         SQL.Add('where CODIGO_PAIS like ''76''');
         SQL.Add('order by NOME_PAIS');
         Open;
       end;

     end

    else
    begin
       pais := 0;
       enabled := True;

       with dm.sqlPaises do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from PAISES');
          SQL.Add('where CODIGO_PAIS not like ''76''');
          SQL.Add('order by NOME_PAIS');
          Open;
        end;
    end;
 end;
    
asked by anonymous 04.02.2016 / 12:59

1 answer

0

I've never worked with lookupcombobox but try to do it as follows.

In the one-click event of the first combo, validate the following

if DBLookupComboBox1.listField = 'Brasileira' then
   begin
      DBLookupComboBox2.enabled := False;
      DBLookupComboBox2.listfieldIndex := Valor Do Pais;  // provavelmente deve ser o id do mesmo   
   end
else 
   begin
      DBLookupComboBox2.enabled := True;
      DBLookupComboBox2.listFieldIndex := 0;
   end;

I usually work with the same combobox, where I fill in the same at runtime together with FireDac where it ends up leaving the application even faster than that way using with DB components.

But the idea is the same, locate the index for the record you want for a certain action taken inside the system.

    
09.02.2016 / 15:38