Re: Set the CheckBox.Checked without the OnClick being called
- From: Fons <fonzzzNO@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 08 Jun 2007 20:01:26 +0200
Is there another way to set the CheckBox.Checked without the OnClick being called than:
procedure TForm.SetCheckBox(A : boolean);
var SaveOnClick : TNotifyEvent;
begin
SaveOnClick := CheckBox.OnClick;
CheckBox.OnClick := nil;
CheckBox.Checked := A;
CheckBox.OnClick := SaveOnClick;
end;
Maybe in one instruction ? Ok: I can make one procedure for the TCheckBox, one for the TEdit etc.
So I want the OnClick only when then user clicks.
You're over-complicating something which is very simple...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
runclickevent: boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
runclickevent := false;
checkbox1.Checked := true;
You forget:
runclickevent := true;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if RunClickEvent = false then exit;
showmessage('This is only shown when needed...');
end;
end.
I used the code you write. But I didn't like it. I think the following procedures I wrote are less complicated in use. You put them in a unit and call them. That's all. No extra variables (maybe one for every control; because of the structure of the code) needed.
Thanks,
Fons.
procedure SetControlData(Control : TCheckBox; Data : boolean);
var Save : TNotifyEvent;
begin
Save := Control.OnClick;
Control.OnClick := nil;
Control.Checked := Data;
Control.OnClick := Save;
end;
procedure SetControlData(Control : TEdit; Data : string); overload;
var Save : TNotifyEvent;
begin
Save := Control.OnChange;
Control.OnClick := nil;
Control.Text := Data;
Control.OnChange := Save;
end;
procedure SetControlData(Control : TRadioButton; Data : boolean); overload;
var Save : TNotifyEvent;
begin
Save := Control.OnClick;
Control.OnClick := nil;
Control.Checked := Data;
Control.OnClick := Save;
end;
procedure SetControlData(Control : TRadioGroup; Data : integer); overload;
var Save : TNotifyEvent;
begin
Save := Control.OnClick;
Control.OnClick := nil;
Control.ItemIndex := Data;
Control.OnClick := Save;
end;
procedure SetControlData(Control : TListBox; Data : integer); overload;
var Save : TNotifyEvent;
begin
Save := Control.OnClick;
Control.OnClick := nil;
Control.ItemIndex := Data;
Control.OnClick := Save;
end;
procedure SetControlData(Control : TScrollBar; Data : integer); overload;
var Save : TNotifyEvent;
begin
Save := Control.OnChange;
Control.OnChange := nil;
Control.Position := Data;
Control.OnChange := Save;
end;
.
- Follow-Ups:
- Never publish before you have tested !
- From: Fons
- Re: Set the CheckBox.Checked without the OnClick being called
- From: John Dough
- Never publish before you have tested !
- References:
- Prev by Date: Re: Set the CheckBox.Checked without the OnClick being called
- Next by Date: Re: ShowForm ?
- Previous by thread: Re: Set the CheckBox.Checked without the OnClick being called
- Next by thread: Re: Set the CheckBox.Checked without the OnClick being called
- Index(es):