Assign value to a Boolean variable according to selected Radio Button

Asked

Viewed 469 times

0

I’m trying to implement my application, where the table empresa won a new column called status, which would be completed in accordance with Radio Button this would serve so that when generating the reports of linked clients, the same only bring me customers with Status = Assets, I’m a beginner in Delphi, so I’m not succeeding, according to Radio Button fill this column. I have already form of register of companies add the Radio Buttons thus leaving the screen:

inserir a descrição da imagem aqui

The part where you save that information in the bank today is that way:

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 verify which of the Radio Buttons is selected to assign to the bank if Status = true or false

1 answer

1


You can check the property Checked of RadioButton. It would be something like that:

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

In your case, by uploading customer data to ClientDataSet you should check the column Status and mark the RadioButton corresponding, in the same way when applying the changes made you should check which RadioButton was selected and properly mount the SQL statement.

I recommend you to use the component DBRadioGroupyou will get less work. It is similar to the Dataware components you are already using (Dbedits). You need to define the properties DataSource and DataField as you did in Dbedits, after that you add the Radiobuttons in the property Itemns, in it you enter one item below the other as in a list. Then you define the property Values with the values that will be saved in the field.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.