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;