Solved

Two Speedbuttons that are friends...

Posted on 2000-02-22
14
245 Views
Last Modified: 2010-04-04
I have two flat TSpeedButtons on a form. I would like the bevel around them to appear simultaneously; that is, when I move the mouse over one of them both buttons should indicate that.
Any advice?

>Daniel
0
Comment
Question by:Dippen
  • 5
  • 5
  • 2
  • +2
14 Comments
 

Expert Comment

by:manjushan
ID: 2545617
U can use the same function in both buttons onmouseover event.Or put both of them on a pannel and write an event of the pannel.Or u can use toolbar.Since speedbuttons dont have onmouseover events it will be better if u write your own component.
            Good luck.
                                               Manju.
0
 
LVL 2

Expert Comment

by:florisb
ID: 2545628
Hmmm, saw something in help, but that didn;t work:

speedbutton1.MouseInControl; //check help, doesn;t seem to work.

detect in form-mousemove event:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if speedbutton1.MouseInControl then
  begin
  speedbutton1.Enabled := true; //?
  speedbutton2.Enabled := true;
  end
else
  begin
  speedbutton1.Enabled := false;
  speedbutton2.Enabled := false;
  end;
end;

Floris.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2546065
This isn't ideal but it'll do what you want it to do.

For each of your speedbuttons, change the GroupIndex value to something unique (e.g. SpeedButton1.GroupIndex = 1, SpeedButton2.GroupIndex = 2...). Make sure that the AllowAllUp property is set to TRUE for all of them.

Then in your MouseMove event for SpeedButton1, add the following:

  SpeedButton1.Down := TRUE;
  SpeedButton2.Down := TRUE;

Then in the MouseMove event for the FORM (or whatever your buttons are on top of), add the following:

  SpeedButton1.Down := FALSE;
  SpeedButton2.Down := FALSE;

Like I said, it isn;t ideal but when you move over Speedbutton1, BOTH buttons will have their bevels displayed

The Neil
0
 

Author Comment

by:Dippen
ID: 2549338
The bevel I'm referring to is the one that's displayed to indicate that if I click with the mouse, the button will be activated. It only applies to flat buttons. Therefore, the Down property is of no interest.
I think the right way is to send a Windows message in some way to the button that is not affected by the mouse cursor. Unfortunately, I'm not an expert of Windows messaging.
0
 

Author Comment

by:Dippen
ID: 2549344
Adjusted points to 100
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2549571
Dippen,

You CAN use a WIndow message system but my solution will raise the bevel around both buttons. Stop trying to make things overly complex

The Neil
0
 

Author Comment

by:Dippen
ID: 2551693
I'm not making things overly complex, you're just not right about this. When I change the Down property to Down the button also changes color and gets a little bit lighter. That's not what I'm looking for. I'm very well aware of what I'm looking for!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2553486
hi dippen,

try this descandend component
(not tested in all cases)

unit FriendSpeedButton;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons;

type
  TFriendSpeedButton = class(TSpeedButton)
  private
    FFriendButton : TFriendSpeedButton;

    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  published
    { Published declarations }
    property FriendButton : TFriendSpeedButton read FFriendButton write FFriendButton;
  end;

procedure Register;

implementation

procedure TFriendSpeedButton.CMMouseEnter(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then
  begin
    If M.WParam <> 1 then
    begin
      M.WParam := 1;
      FFriendButton.CMMouseEnter(M);
    end;
  end;
end;

procedure TFriendSpeedButton.CMMouseLeave(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then
  begin
    If M.WParam <> 1 then
    begin
      M.WParam := 1;
      FFriendButton.CMMouseLeave(M);
    end;
  end;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TFriendSpeedButton]);
end;

end.

meikl
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 2553562
hi again,

a bit modification, to allow more than two friends:

unit FriendSpeedButton;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons;

type
  TFriendSpeedButton = class(TSpeedButton)
  private
    FFriendButton : TFriendSpeedButton;

    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  published
    { Published declarations }
    property FriendButton : TFriendSpeedButton read FFriendButton write FFriendButton;
  end;

procedure Register;

implementation

procedure TFriendSpeedButton.CMMouseEnter(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then      //is there a friend
  begin
    If (M.WParam = 0) then             //am i the first then
      M.WParam := Integer(self);       //remember me
    if (M.WParam <> Integer(FFriendButton)) then  //if not my Friend the first then
      FFriendButton.CMMouseEnter(M);              //tell him the event
  end;
end;

procedure TFriendSpeedButton.CMMouseLeave(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then     //is there a friend
  begin
    If (M.WParam = 0) then            //am i the first then
      M.WParam := Integer(self);      //remember me
    if (M.WParam <> Integer(FFriendButton)) then //if not my Friend the first then
      FFriendButton.CMMouseLeave(M);             //tell him the event
  end;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TFriendSpeedButton]);
end;

end.

connect the friends with the friendbutton-property

two ways are possible:
circular chain : f1-f2-f3-f1
open chain : f1-f2-f3 (f3 has no friend)

the effect is a bit different

meikl
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2554910
appendix,

there is one bug:
if you at designmode delete a friend, which is assigned on another friend as friend, you will get an accessviolation on the other friend by selecting the friend-property.

the component must be expanded by a component-notification (one additional procedure)

if it from interest, i will post the changes here

meikl
0
 

Author Comment

by:Dippen
ID: 2554945
Perfect! Exactly the behavior I was looking for!
Thanks a bunch, meikl!!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2555013
well, dippen,
glad to helped you :-)
will post tomorow the solve
of the destroyed friend
problem at designmode
good luck again
meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2556918
hi again,

here the change

unit FriendSpeedButton;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons;

type
  TFriendSpeedButton = class(TSpeedButton)
  private
    FFriendButton : TFriendSpeedButton;

    { Private declarations }
  protected
    { Protected declarations }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    { Public declarations }
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  published
    { Published declarations }
    property FriendButton : TFriendSpeedButton read FFriendButton write FFriendButton;
  end;

procedure Register;

implementation

procedure TFriendSpeedButton.CMMouseEnter(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then      //is there a friend
  begin
    If (M.WParam = 0) then             //am i the first then
      M.WParam := Integer(self);       //remember me
    if (M.WParam <> Integer(FFriendButton)) then  //if not my Friend the first then
      FFriendButton.CMMouseEnter(M);              //tell him the event
  end;
end;

procedure TFriendSpeedButton.CMMouseLeave(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then     //is there a friend
  begin
    If (M.WParam = 0) then            //am i the first then
      M.WParam := Integer(self);      //remember me
    if (M.WParam <> Integer(FFriendButton)) then //if not my Friend the first then
      FFriendButton.CMMouseLeave(M);             //tell him the event
  end;
end;

procedure TFriendSpeedButton.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited  Notification(AComponent, Operation);
  If Operation = opRemove then          //will be removed something then
    If AComponent = FFriendButton then  //is it my friend then
       FFriendButton := Nil;            //my friend is gone
end;

procedure Register;
begin
  RegisterComponents('Samples', [TFriendSpeedButton]);
end;

end.

meikl
0
 

Author Comment

by:Dippen
ID: 2559985
Note taken! Thanks again!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now