Recent

Author Topic: [SOLVED] TColorButton cancel OnClick event  (Read 1312 times)

petevick

  • Sr. Member
  • ****
  • Posts: 419
[SOLVED] TColorButton cancel OnClick event
« on: October 30, 2022, 11:25:16 am »
I'd like to cancel the OnClick event of a TColorButton under certain conditions so that the color dialogue box is not displayed. I was expecting the following to have worked....
Code: Pascal  [Select][+][-]
  1. AColorButton.OnClick:=Nil;
...but it doesn't. Is it simply not possible ?
« Last Edit: October 30, 2022, 12:28:08 pm by petevick »
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

paweld

  • Hero Member
  • *****
  • Posts: 1419
Re: TColorButton cancel OnClick event
« Reply #1 on: October 30, 2022, 12:18:55 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ColorButton1Click(Sender: TObject);
  2. begin
  3.   if Condition then  
  4.     Abort;
  5. end;
Best regards / Pozdrawiam
paweld

petevick

  • Sr. Member
  • ****
  • Posts: 419
Re: TColorButton cancel OnClick event
« Reply #2 on: October 30, 2022, 12:27:49 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ColorButton1Click(Sender: TObject);
  2. begin
  3.   if Condition then  
  4.     Abort;
  5. end;
That does it  ;D ;D Thanks paweld for the prompt reply  ;)
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6953
Re: [SOLVED] TColorButton cancel OnClick event
« Reply #3 on: October 30, 2022, 05:52:32 pm »
Would you mind sharing as to how you resolved this?
 
Last time I checked there was no direct method of avoiding the dialog during the Onclick event.

 However, you can of course overlay the button with a Tgraphics type of control and enable it when needed to hog the events.

  Also, you could use the External Dialog option and simple implement the OnShow event of that dialog and close it there. But that may generate a little flicker.
The only true wisdom is knowing you know nothing

petevick

  • Sr. Member
  • ****
  • Posts: 419
Re: [SOLVED] TColorButton cancel OnClick event
« Reply #4 on: October 30, 2022, 05:58:14 pm »
Would you mind sharing as to how you resolved this?
 
Last time I checked there was no direct method of avoiding the dialog during the Onclick event.

 However, you can of course overlay the button with a Tgraphics type of control and enable it when needed to hog the events.

  Also, you could use the External Dialog option and simple implement the OnShow event of that dialog and close it there. But that may generate a little flicker.
I used the Abort command as shown in the code that paweld supplied above !!
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6953
Re: [SOLVED] TColorButton cancel OnClick event
« Reply #5 on: October 30, 2022, 06:12:34 pm »
Ok, I thought that was some sort general speak reference !  :)
The only true wisdom is knowing you know nothing

Nicole

  • Hero Member
  • *****
  • Posts: 1165
Re: [SOLVED] TColorButton cancel OnClick event
« Reply #6 on: October 31, 2022, 12:27:51 pm »
Is there a difference between:
abort
and
exit
?

petevick

  • Sr. Member
  • ****
  • Posts: 419
Re: [SOLVED] TColorButton cancel OnClick event
« Reply #7 on: October 31, 2022, 12:40:15 pm »
Is there a difference between:
abort
and
exit
?
There must be as Exit does not prevent the colour picker dialogue from being displayed, whereas Abort does.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6953
Re: [SOLVED] TColorButton cancel OnClick event
« Reply #8 on: October 31, 2022, 10:36:37 pm »
There is a TRY .... FINALLY .. END.
in the control's code before it calls the OnClick event.

 So while you are within this OnClick Event the calling code is currently somewhere in the TRY section.

After the OnClick returns, it then pops up the dialog before it reaches the FINALLY section.

 However, if you use ABORT, the code will return at that point starting at the Finally section and all other finally sections before that.

 Thus it skips the part where it starts the Dialog and free's everything needed in the Finally section.

 This means, the code needs to test for a Free and NIL for the internal dialog and do nothing for the external dialog.
The only true wisdom is knowing you know nothing

Nicole

  • Hero Member
  • *****
  • Posts: 1165
Re: [SOLVED] TColorButton cancel OnClick event
« Reply #9 on: November 01, 2022, 07:11:14 am »
Thanks, how interesting.

I rarely use try finally, too costly and too few advantages.
But if I do, I shall change my exits to abort.

 

TinyPortal © 2005-2018