Create a Component that ..

I want to create a component that
it do this:

put a panel and above the panel a speedbutton.. and to have access to both
of their properties.. eg panels color
etc...

any ideas ?

Thanx
LVL 2
k6__Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
Hi
well i dunno if you can use componentcount property of the form something like:

var
  i : integer;
begin
  for i := 0 to ComponentCount-1 do
    begin
      if( Components[i] is TPanel )then
      begin
        (Components[i] as TEdit).Color := clred;
      end;
  end

or in your compoennt:

procedure TMyClass.GetChildren(Proc: TGetChildProc);
var
  i: Integer;
begin
  for i := 0 to ComponentCount - 1 do Proc(Components[i]);
end;

maybe some ideas..
Regards Barry
0
intheCommented:
whoops made a typo ...  TEdit).Color indeed :-)
0
aacrgCommented:
Do you want to create a non visual component that is able to create a panel with a speedbutton on it or do you want to create a panel that contains a speedbutton and you have access to all its properties?

If you want to do the second then do this:

Create a class derrived from TPanel. Create the SpeedButton on create of the panel set its properties to some default values (eg. SpeedButton.Parent=Self).
The instance (object) pointer of the Speedbutton you save in a private variable that is published as property. Now you have to define a property editor (derrived from TClassProperty) for this property. Like this you will have all access to the properties of this component.

Regars, rg.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

k6__Author Commented:
aacrg i want to do a Visible(Visual)
component so i can click on the component
and that it will create a panel & a
speed button over it..

Can you post some example ? =)

Thanx
0
bozo7Commented:
listening...
0
aacrgCommented:
Can you be a bit more specific, where has this panel to be created and what size? In design time or runtime? If in runtime, why must you have access to the properties of the button and the panel?
0
EpsylonCommented:
If you have Delphi 5 you can use frames...
0
k6__Author Commented:
|--------|
||------||
||Button||<- Panel
||------||  
|--------|

1) Create a Panel
2) Create a Speed Button inside Panel
3) Must Have Access To Panel & Button
   Properties Both in Design and Runtime
4) Also If i Resize the Panel The
   button will resize too (something
   like Client Align)

Hope this helps a bit ? =)
0
aacrgCommented:
So, what you want is a TPanel descend that has a TSpeedButton on it and you have access to the SpeedButtons properties in the object inspector. (?)
0
StefaanCommented:
Hi,

Like AACRQ told, you should create a new component, descending from the TPanel component (or TCustomPanel).

You should override the Create (constructor) and the Destroy (Destructor), to implement the creation of the SpeedButton, and Override the paint procedure if you want the button to be resised to the sise of the panel.

Second thing you will need to do is create a property editor to be able to modify the properties from the SpeedButton.

I have created a sample for this component.  I will put the Full Source Code for the component and the property editor in here, so it can be quite long.

Of course this is just the basics, if the component needs other functionality you will have to modify it yourself, and you could create a more sophisticated property editry for the SpeedButton too since I've used the default one available.

This is the source code for the unit, just add it to a package, compile it and install it and it should be there on the Samples tab :



unit MyPanel;

interface

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

type
  TMyPanel = class(TPanel)
    FButton : TSpeedbutton;
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Paint; override;
  published
    { Published declarations }
    property Button: TSpeedButton read FButton;
  end;

  TPanelButtonProperty = class(TClassProperty)
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TMyPanel]);
  RegisterPropertyEditor( TypeInfo( TSpeedButton ), nil, '', TPanelButtonProperty);
end;

{ TMyPanel }

constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;
  FButton := TSpeedButton.Create(Self);
  FButton.Parent := Self;
  FButton.Left := 1;
  FButton.Top := 1;
  FButton.Width := self.Width;
  FButton.Height := Self.Height;
end;

destructor TMyPanel.Destroy;
begin
  FButton.Free;
  FButton := Nil;
  inherited;
end;
 
procedure TMyPanel.Paint;
begin
  inherited;
  FButton.Top := 1;
  FButton.Left := 1;
  FButton.Width := Self.Width;
  FButton.Height := Self.Height;
end;

{ TPanelButtonProperty }

procedure TPanelButtonProperty.Edit;
begin
  inherited;

end;

function TPanelButtonProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paSubProperties];
end;

end.




Voila, this should do the trick.

Best regards,


Stefaan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
k6__Author Commented:
Thanx ... i'll find the rest.. btw
do you know how to assign the button
OnClink Property to the Panel OnClick
Property ?

0
StefaanCommented:
Hi,

Sure, you just have to modify the source code as follows :

....

  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Paint; override;
    procedure ButtonClicked (Sender: TObject);

....

procedure TMyPanel.ButtonClicked(Sender: TObject);
begin
  FButton.Click;
  Self.Click;
end;

constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;
  FButton := TSpeedButton.Create(Self);
  FButton.Parent := Self;
  FButton.Left := 1;
  FButton.Top := 1;
  FButton.Width := self.Width;
  FButton.Height := Self.Height;
  FButton.OnClick := ButtonClicked;
end;

destructor TMyPanel.Destroy;
begin
  FButton.OnClick := Nil;
  FButton.Free;
  FButton := Nil;
  inherited;
end;

....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.