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 write a custom TAction to control the visibility of a TStatusBar 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
26-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
96
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I am trying to write a custom action that will set the visible property of a 
TStatusBar on and off. I assigned this action to a menu item and when I select this 
menu item at runtime the status bar is hidden. The problem is that the menu item 
(connected to the action) is disabled, so I can't view the statusbar again. I think 
that it's a matter of how the TMenuActionLink behaves (the action controls the 
enabled property of the menu ). I tried to set the enabled property in the action 
to true , but no avail. The menu is still disabled. Is there any way to do this?

Answer:

I think that the best solution would be to write an action, which will have a 
StatusBar property and, in case this property was assigned, set the statusbar's 
visibility in the overridden Execute method. Here's an example:

1   { ... }
2   TMyAction = class(TAction)
3   protected
4     FStatusBar: TStatusBar;
5     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
6     procedure SetStatusBar(AValue: TStatusBar);
7   public
8     constructor Create(AOwner: TComponent); override;
9     function Execute: Boolean; override;
10  published
11    property StatusBar: TStatusBar read FStatusBar write SetStatusBar;
12  end;
13  
14  { ... }
15  
16  constructor TMyAction.Create(AOwner: TComponent);
17  begin
18    inherited Create(AOwner);
19    DisableIfNoHandler := false;
20    FStatusBar := nil;
21    Caption := 'Turn On/ Off Status Bar';
22  end;
23  
24  function TMyAction.Execute: Boolean;
25  begin
26    Result := inherited Execute;
27    if Assigned(FStatusBar) then
28    begin
29      FStatusBar.Visible := not FStatusBar.Visible;
30      Checked := FStatusBar.Visible;
31    end;
32  end;
33  
34  procedure TMyAction.Notification(AComponent: TComponent; Operation: TOperation);
35  begin
36    inherited Notification(AComponent, Operation);
37    if (Operation = opRemove) and (AComponent = StatusBar) then
38      StatusBar := nil;
39  end;
40  
41  procedure TMyAction.SetStatusBar(AValue: TStatusBar);
42  begin
43    if FStatusBar <> AValue then
44    begin
45      FStatusBar := AValue;
46      if Assigned(FStatusBar) then
47      begin
48        FStatusBar.FreeNotification(Self);
49        Checked := FStatusBar.Visible;
50      end
51      else
52        Checked := false;
53    end;
54  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