ChrisChuah 0 Posted December 14, 2020 Hi Is there a function when there is switch event, to disallow the component from switching from off to on? In my function, when the user activate the OnSwitch event, i will prompt the user to turn off? if the user said no, then the switch should remain at On. However, now the switch will auto turn off even though i set the IsCheck to true any ideas? regards chris Share this post Link to post
Dave Nottage 557 Posted December 14, 2020 1 hour ago, ChrisChuah said: Is there a function when there is switch event, to disallow the component from switching from off to on? Why not just set Enabled to False? Share this post Link to post
Guest Posted December 14, 2020 (edited) 1 hour ago, ChrisChuah said: ... any ideas? many! but let's use this my sample to explan a little bit: uses FMX.DialogService; var lAnswerYes_or_Not_to_Switch: boolean = false; procedure TForm2.Switch1Click(Sender: TObject); begin Memo1.Lines.Add('(occurr first than OnSwitch... OnClick ' + DateTimeToStr(now)); // TDialogService.MessageDialog('Let checked or not', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], TMsgDlgBtn.mbYes, 0, { } procedure(const AResult: TModalResult) begin lAnswerYes_or_Not_to_Switch := true; // if not(AResult = mrYes) then lAnswerYes_or_Not_to_Switch := false end); end; procedure TForm2.Switch1Switch(Sender: TObject); begin // // Occurs immediately after you change the state of this switch component from on to off and vice versa. <--- then it should be these event to use! // // if (Sender as TSwitch).IsChecked then if not lAnswerYes_or_Not_to_Switch then begin Memo1.Lines.Add('OnSwitch im checked!!! ' + DateTimeToStr(now)); (Sender as TSwitch).IsChecked := false; end else (Sender as TSwitch).IsChecked := true; // be "true" or "false" works, but ... the "Presentation" dont look that, then is necessary re-call it! // (Sender as TSwitch).ReloadPresentation; // the "magic" to change the screen-presentation is here! // Memo1.Lines.Add('OnSwitch ' + DateTimeToStr(now)); end; hug Edited December 14, 2020 by Guest Share this post Link to post
Guest Posted December 14, 2020 (edited) 3 minutes ago, Dave Nottage said: Why not just set Enabled to False? on "Event" itself dont works like he want! Edited December 14, 2020 by Guest Share this post Link to post
ChrisChuah 0 Posted December 14, 2020 Thank you very much. i will try this out. regards chris Share this post Link to post