Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

Component inside another component...

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
gklux
Asked:
gklux
  • 3
  • 2
  • 2
  • +3
1 Solution
 
scrapdogCommented:
If you want it to appear in the Object Inspector, you will have to write a property editor for type TPanel.
0
 
scrapdogCommented:
(I think)
0
 
nnbbb09Commented:
try declaring the panel as published. i think all published properties of the panel should be visible in the object inspector.

Jo
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
gkluxAuthor Commented:
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
 
gkluxAuthor Commented:
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
 
trex_fireCommented:
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
 
ITugayCommented:
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
 
GwenaCommented:
listening :-)
0
 
ITugayCommented:
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
 
gkluxAuthor Commented:
THANKS A LOT
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now