Assign a value to a Boolean variable according to Radio Button selected

0

I'm trying to implement my application, where the empresa table has gained a new column named status , which would be populated according to Radio Button so that when generating linked client reports, the even if it only brings me the clients with Status = Active , I'm a beginner in Delphi, which is why I can not, according to Radio Button fill this column. I have already been able to add the Radio Buttons to the form

The part where you save this information in the bank today looks like this:

begin
    sdsEmpresaCadastro.Close;
    sdsEmpresaCadastro.CommandText := 'select * from Empresa where Nome = '''+cdsEmpresaNOME.AsString + '''';
    sdsEmpresaCadastro.Open;

    if not sdsEmpresaCadastro.IsEmpty then
       raise  Exception.Create('Empresa já incluída');
    cdsEmpresaCODIGO.AsInteger := dmDatabase.NextID('EMPRESA');

    dmDatabase.SQLConnection.Execute('INSERT INTO Empresa (CODIGO, NOME, VALORIMPRESSAO, '+
         'VALORDIGITALIZACAO, VALORIMPRESSAOEXCEDENTE, CONTATO, NOMEREDUZIDO, CNPJ, ENDERECO, BAIRRO, CEP, '+
         'CIDADE, TEFONE, UF, INSCRICAOESTADUAL, CONTATONF, EMAIL, EMAILNF, OBSERVACAO, '+
         'FRANQUIADIGITALIZACAO, VALORDIGITALIZACAOEXCEDENTE, STATUS) VALUES ('+
         cdsEmpresaCODIGO.AsString+','''+cdsEmpresaNOME.AsString+''','+
         TrocaVirgPPto(cdsEmpresaVALORIMPRESSAO.AsString)+','+
         iif(cdsEmpresaVALORDIGITALIZACAO.AsString='','0', TrocaVirgPPto(cdsEmpresaVALORDIGITALIZACAO.AsString))+','+
         iif(cdsEmpresaVALORIMPRESSAOEXCEDENTE.AsString='','0', TrocaVirgPPto(cdsEmpresaVALORIMPRESSAOEXCEDENTE.AsString))+
         ','''+cdsEmpresaCONTATO.AsString+''','''+cdsEmpresaNOMEREDUZIDO.AsString+ ''','''+
         cdsEmpresaCNPJ.AsString +''','''+cdsEmpresaENDERECO.AsString+''','''+
         cdsEmpresaBAIRRO.AsString +''','''+cdsEmpresaCEP.AsString+ ''','''+
         cdsEmpresaCIDADE.AsString+''','''+cdsEmpresaTEFONE.AsString+''','''+
         cdsEmpresaUF.AsString+''','''+cdsEmpresaINSCRICAOESTADUAL.AsString+ ''','''+
         cdsEmpresaCONTATONF.AsString+ ''','''+ cdsEmpresaEMAIL.AsString + ''','''+
         cdsEmpresaOBSERVACAO.AsString + ''','''+ cdsEmpresaEMAILNF.AsString+''','+
         iif(cdsEmpresaFRANQUIADIGITALIZACAO.AsString='','0', cdsEmpresaFRANQUIADIGITALIZACAO.AsString)+','+
         iif(cdsEmpresaVALORDIGITALIZACAOEXCEDENTE.AsString='','0', TrocaVirgPPto(cdsEmpresaVALORDIGITALIZACAOEXCEDENTE.AsString))+')', nil);
  end

My question then is: How to check which of the Radio Buttons is selected, in order to assign the bank Status = true or false     

asked by anonymous 01.12.2016 / 19:17

1 answer

1

You can check the Checked property of RadioButton . It would look something like this:

if RadioButton1.Checked then
  ShowMessage('Ativo!')
else
  ShowMessage('Inativo!');

In your case, when loading client data in ClientDataSet you should check the Status column and mark the corresponding RadioButton , likewise when applying the changes made you should check which RadioButton was selected and properly mount the SQL statement.

I suggest you use the DBRadioGroup component you will get less work. It looks like the dataware components it is already using (DBEdits). You need to set the DataSource and DataField properties as you did in DBEdits, after which you add the RadioButtons in the Itemns property, in which you inform one item below the other as in a list. Then you set the Values property to the values that will be written to the field.

    
03.12.2016 / 01:19