We help IT Professionals succeed at work.

On Click Event

RalphPorter
RalphPorter asked
on
Hi Folks,

        How can I prevent the onclick event (or the code within the event) of a checkbox item occuring when I scroll to a different database record? I want to action the code in the events when the user physically clicks the buttons but not when positioning the database. Thank you very much.

Regards,

         Ralph.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004

Commented:
? do you mean the onchange-event or the onclick-event?
Commented:
There is no OnChange for a TCheckBox.  This is not a particularly wonderful way of doing this, but have a look at this example and see if you can get what you need from it..... (unit code and dfm text).


/////////////////////   Unit Code   /////////////////////////
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, QControls;

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1                    : TForm1;
     ButtonClick     : Boolean;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
     CheckBox1.Checked:=not CheckBox1.Checked;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
     if not ButtonClick then
          ShowMessage('Clicked');
end;

procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
     ButtonClick:=True;
end;

procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
     ButtonClick:=False;
end;

end.



/////////////////////   DFM Text   /////////////////////////
object Form1: TForm1
  Left = 256
  Top = 107
  Width = 158
  Height = 128
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object CheckBox1: TCheckBox
    Left = 16
    Top = 20
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 0
    OnClick = CheckBox1Click
  end
  object Button1: TButton
    Left = 16
    Top = 52
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
    OnMouseDown = Button1MouseDown
    OnMouseUp = Button1MouseUp
  end
end
/////////////////////  End  /////////////////////////

Have a go with that.

John.

Author

Commented:
Cheers John,

           This works just fine for me - I will stick with that solution. Thank you very much.

Regards,

       Ralph.

Commented:
You're welcome Ralph.  Glad to help out.

Good luck,

John.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.