Uncheck Checkbox With Password Only

Asked

Viewed 56 times

0

I have a system and in a precise part only support members can deselect a checkbox.

I have tried several codes but there is always the same problem : The Checkbox by default when clicked it is marked or unchecked and I could not find a way to stop this process and only continue with the password.

Last Code I tried :

procedure TFEncerramentoPeriodo.CBFinanceiroClick(Sender: TObject);
var senha,senhad : String;
begin
senha := '328Cont';
 if CBFinanceiro.Checked = true then
 begin
   if not(InputQuery('Digite a Senha', 'Senha', Senhad))
  then
  exit;

    if (SenhaD=Senha) then
    begin
      CBFinanceiro.Checked := False;
    end
    else
    begin
      ShowMessage('Senha Incorreta! Somente Membros do Suporte Podem Desmarcar Essa Opção!');
      CBFinanceiro.Checked := True;
    end;
 end

I searched several places and even here in the OR and I did not find anyone with the same doubt or problem or similar.

  • 1

    Password independent, in conventional code, how do you make the checkbox read-only?

  • enabled property....

  • what happens is this, I want the user to be able to enable the check box, but can not disable it without first contacting the support. Because with this form it will trigger a chain reaction in other forms, changing the way they will work

  • Well, nothing prevents enable if unchecked, and disable when checking. If successful, post as response in the field below. Remember that you can [dit] the post to improve. Learning to make a [mcve] is important too. This link can help in the best use of the site: Stack Overflow Survival Guide in English

  • Okay, I’m going to design a skim! Thanks for the tips!

2 answers

1


I managed to do it with this code, using the Onmousedown and Onkeydown Checkbox events:

procedure TForm3.CheckBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  senha, senhad: string;
  b: boolean;
begin
  senha := '328Cont';
  if CheckBox1.Checked then
  begin
    b := InputQuery('Digite a senha', 'Senha', Senhad);
    CheckBox1.Checked := not (b and (senhad = senha));
  end;
end;

procedure TForm3.CheckBox1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  senha, senhad: string;
  b: boolean;
begin
  if Key <> VK_SPACE then
    exit;
  Key := 0;
  senha := '328Cont';
  if CheckBox1.Checked then
  begin
    b := InputQuery('Digite a senha', 'Senha', Senhad);
    CheckBox1.Checked := not (b and (senhad = senha));
  end;
end;

1

I think you’re doing the wrong IF for the combo. When you have the combo checked and click on it, it enters this method already with checked=false and not checked=true. So your code works by changing to

if CBFinanceiro.Checked = false then
begin
  if not(InputQuery('Digite a Senha', 'Senha', Senhad)) then
     CBFinanceiro.Checked := true;

The only thing less good is that the box appears unchecked when the prompt appears, but then it looks good... I don’t know if it’s a problem.

Browser other questions tagged

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