Solved

Two Speedbuttons that are friends...

Posted on 2000-02-22
14
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 62
Strange behavior when a form is closed 6 68
select query - oracle 16 101
MS Access from Delphi 31 79
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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