Solved

Component inside another component...

Posted on 2001-08-09
10
283 Views
Last Modified: 2010-04-06
Hi all.

Here is my question : I'am writing an component than owns a TPanel(called borderPanel). I would like the user being abble to access to all properties of the borderPanel within the Object Inspector.
The final goal should be something like the font property.

How should I declare the BorderPanel property ?

hoping i was clear...

Regards

Mike
0
Comment
Question by:gklux
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 6367473
If you want it to appear in the Object Inspector, you will have to write a property editor for type TPanel.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6367478
(I think)
0
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6367608
try declaring the panel as published. i think all published properties of the panel should be visible in the object inspector.

Jo
0
 

Author Comment

by:gklux
ID: 6367650
first of all, thanks for interesting into my question.

scrapdog : I did something like this few years ago, and as far as I remember, there is no need to write a poperty editor, but off course, no way to get this previous source neither as remember how i did...


nnbbb09 : sorry, it doesn't works.


regards

Mike
0
 

Author Comment

by:gklux
ID: 6367661
note : I remember where I have learned how to do : it was in the book "secrets d'exerts" (maybe english title was Experts secrets) as far as i remember the author is Dick Lantim. But i don't have this book anymore... if somebody may have this.

Mike
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:trex_fire
ID: 6368052
You can redeclare your TPanel and redeclare the properies you want in the published section like:

type
  MyPanel = class(TPanel)
  published
   property Prop1;
   property Prop2;
   property Prop3;
   property Prop4;
   property Prop5;
  end;

This way you only change the visibility of your properties and keep a functionnal TPanel that you can customise on need.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6368178
Hi gklux,

to make "included" control's property visible in object inspector while you are editing "parent" control you should build some inteface object derived from TPersistent.


here is small sample:

type
  TWinCtlProp = class(TPersistent)
  private
    FWinControl: TWinControl;
    // width
    function GetWidth: Integer;
    procedure SetWidth(V: Integer);
    // height
    procedure SetHeight(Value: Integer);
    function GetHeight: Integer;
    // rest of Get... Set...
  published
    property Width: Integer read GetWidth write SetWidth;
    property Height: Integer read GetHeight write SetHeight;
    // .... rest of properties
  end;

  // here is your own control that has internal TEdit
  TPanel1 = class(TPanel)
  private
    FEdit: TEdit;
    FProp: TWinCtlProp;
  public
    constructor Create(O: TComponent); override;
    destructor Destroy; override;
  published
    property EditProp: TWinCtlProp read FProp;
  end;


implementation


//------------------------------------------------------------------------------
function TWinCtlProp.GetWidth: Integer;
begin
  Result := FWinControl.Width;
end;

procedure TWinCtlProp.SetWidth(V: Integer);
begin
 FWinControl.Width := V;
end;

procedure TWinCtlProp.SetHeight(Value: Integer);
begin
  FWinControl.Height := Value;
end;

function TWinCtlProp.GetHeight: Integer;
begin
  Result := FWinControl.Height;
end;

//------------------------------------------------------------------------------
constructor TPanel1.Create(O: TComponent);
begin
  inherited;
  FEdit := TEdit.Create(Self);
  FEdit.Parent := Self;

  FProp := TWinCtlProp.Create;
  FProp.FWinControl := FEdit;
end;

destructor TPanel1.Destroy;
begin
  FProp.Free;
  FEdit.Free;
  inherited;
end;


-----
Igor.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6370253
listening :-)
0
 
LVL 9

Accepted Solution

by:
ITugay earned 50 total points
ID: 6372638
hi Gwena,

seems you are interesting in it, so, here is my "secret"  way to show all "subcomponents" properties in object inspector and store it into .DFM file.

Enjoy :-)

---------
Igor


uses
  ....DsgnIntf.....

type
  TMyPanel = class(TPanel)
  private
    FEdit: TEdit;
  protected
    procedure WriteEditBin(Stream: TStream);
    procedure ReadEditBin(Stream: TStream);
    procedure DefineProperties(Filer: TFiler); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Edit: TEdit read FEdit;
  end;


procedure Register;

implementation

procedure Register;
begin
  // changing property editor for Edit, it allow you to see and modify
  // all components property in object inspector by the same way as for TFont
  RegisterPropertyEditor(TypeInfo(TEdit), TMyPanel, 'Edit', TClassProperty);

  RegisterComponents('Samples', [TMyPanel]);
end;


constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;
  FEdit := TEdit.Create(Self);
  FEdit.Parent := Self;
end;

destructor TMyPanel.Destroy;
begin
  FEdit.Free;
  inherited;
end;

procedure TMyPanel.WriteEditBin(Stream: TStream);
begin
  Stream.WriteComponent(FEdit);
end;

procedure TMyPanel.ReadEditBin(Stream: TStream);
begin
  Stream.ReadComponent(FEdit);
end;

procedure TMyPanel.DefineProperties(Filer: TFiler);
begin
  inherited;
  // here is the way to store all properties of Edit in .DFM file
  // as you see, property name is "FEdit", it should be any other name,
  // but not the same as published property name.
  Filer.DefineBinaryProperty('FEdit', ReadEditBin, WriteEditBin, true);
end;
0
 

Author Comment

by:gklux
ID: 6378676
THANKS A LOT
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

17 Experts available now in Live!

Get 1:1 Help Now