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 override the standard OnClick event of a TDBCheckBox 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
28-Aug-02
Category
Database-VCL
Language
Delphi 2.x
Views
143
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

When showing a form with checkboxes connected to a database table it seems the 
OnClick event of the checkboxes is being run when the form is shown but before 
OnActivate is run. Does anyone know what can cause this? I have code in the OnClick 
to enable certain other controls etc. and I am having to disable them conditionally 
if the checkbox has focus.

Answer:

Unfortunately the OnClick event executes when the value of the checkbox changes, 
not just when the object is "clicked". So if you scroll from a record that is True 
to one that is False, the event will be triggered. This is because the component 
sets the State of the check box after each record is scrolled. That in turn fires 
the Click event. You can override this behavior by subclassing from TDBCheckBox and 
override the property ClicksDisabled which is defined in TButtonControl. You'll 
also need to override the WndProc method and reset the var FClicksDisabled to True. 
This should keep the OnClick executing only when the mouse is clicked and not when 
the data is scrolled to a new value. I have no idea why the CheckBox was 
implemented this way, it really doesn't make much sense to me.

Here's one that should only fire the onClick event when the mouse is clicked.

1   { ... }
2   type
3     TMyDBCheckBox = class(TDBCheckBox)
4     private
5       { Private declarations }
6       FClickOK: Boolean;
7     protected
8       { Protected declarations }
9       procedure WndProc(var message: TMessage); override;
10      procedure Click; override;
11    public
12      { Public declarations }
13      constructor Create(AOwner: TComponent); override;
14    published
15      { Published declarations }
16    end;
17  
18  procedure register;
19  
20  implementation
21  
22  procedure TMyDBCheckBox.WndProc(var message: TMessage);
23  begin
24    inherited;
25    case message.Msg of
26      WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
27        FClickOK := True;
28    end;
29  end;
30  
31  constructor TMyDBCheckBox.Create(AOwner: TComponent);
32  begin
33    inherited;
34    FClickOK := False;
35  end;
36  
37  procedure TMyDBCheckBox.Click;
38  begin
39    try
40      if FClickOK then
41        inherited;
42    finally
43      FClickOK := False;
44    end;
45  end;
46  
47  procedure register;
48  begin
49    RegisterComponents('Custom', [TMyDBCheckBox]);
50  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