Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to set properties without triggering an event Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Set properties without triggering an event 09-Aug-04
Category
VCL-General
Language
Delphi All Versions
Views
268
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Philipp, Steve
Reference URL:
Steve Philipp
			1   //Some components will trigger OnChange, OnClick, etc. events
2   //even if a property is changed programmatically,
3   //not by the user.
4   unit Unit1;
5   
6   interface
7   
8   uses
9     Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
10    Dialogs, StdCtrls,Menus,ComCtrls;
11  
12  type
13    TForm1 = class(TForm)
14      CheckBox1: TCheckBox;
15      Button1: TButton;
16      procedure CheckBox1Click(Sender: TObject);
17      procedure Button1Click(Sender: TObject);
18    private
19      { Private declarations }
20    public
21      { Public declarations }
22    end;
23  
24  var
25    Form1: TForm1;
26  
27  implementation
28  
29  {$R *.dfm}
30  //Here are some examples how to avoid these events.
31  
32  procedure SetCheckBox(C: TCheckBox; V: Boolean);
33  var
34    N: TNotifyEvent;
35  begin
36    with C do
37    begin
38      N:= OnClick;
39      OnClick:= nil;
40      Checked:= V;
41      OnClick:= N;
42    end;
43  end;
44  
45  procedure SetMenuCheck(C: TMenuItem; V: Boolean);
46  var
47    N: TNotifyEvent;
48  begin
49    with C do
50    begin
51      N:= OnClick;
52      OnClick:= nil;
53      Checked:= V;
54      OnClick:= N;
55    end;
56  end;
57  
58  procedure TrackPos(C: TTrackBar; V: Integer);
59  var
60    N: TNotifyEvent;
61  begin
62    with C do
63    begin
64      N:= OnChange;
65      OnChange:= nil;
66      Position:= V;
67      OnChange:= N;
68    end;
69  end;
70  
71  
72  procedure TForm1.CheckBox1Click(Sender: TObject);
73  begin
74  Showmessage('Clicked');
75  end;
76   //Test:
77  procedure TForm1.Button1Click(Sender: TObject);
78  begin
79    SetCheckBox(CheckBox1, True);
80  end;
81  
82  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC