[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Create a Component that ..

Posted on 1999-12-27
12
Medium Priority
?
197 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:k6__
  • 3
  • 3
  • 2
  • +3
12 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2308813
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
 
LVL 17

Expert Comment

by:inthe
ID: 2308814
whoops made a typo ...  TEdit).Color indeed :-)
0
 

Expert Comment

by:aacrg
ID: 2309251
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
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
LVL 2

Author Comment

by:k6__
ID: 2309501
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
 
LVL 1

Expert Comment

by:bozo7
ID: 2309567
listening...
0
 

Expert Comment

by:aacrg
ID: 2309584
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
 
LVL 13

Expert Comment

by:Epsylon
ID: 2309989
If you have Delphi 5 you can use frames...
0
 
LVL 2

Author Comment

by:k6__
ID: 2310654
|--------|
||------||
||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
 

Expert Comment

by:aacrg
ID: 2311662
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
 
LVL 3

Accepted Solution

by:
Stefaan earned 150 total points
ID: 2311711
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
 
LVL 2

Author Comment

by:k6__
ID: 2313629
Thanx ... i'll find the rest.. btw
do you know how to assign the button
OnClink Property to the Panel OnClick
Property ?

0
 
LVL 3

Expert Comment

by:Stefaan
ID: 2314267
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

591 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