I am new to component creation and was experimenting with creating some of my own custom derived components using the standard issue VCL from Delphi.
I thought I could mix two components together, to create one singular one. Take below what I have so far, the idea is to put a TImage inside a TScrollBox:
unit MyComponent;
interface
uses
Windows,
Classes,
Controls,
Forms,
ExtCtrls;
type
TMyPanel = class(TScrollBox)
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TMyPanel]);
end;
{ TMyPanel }
constructor TMyPanel.Create(AOwner: TComponent);
var
AImage: TImage;
begin
inherited Create(AOwner);
AImage := TImage.Create(AOwner);
AImage.Align := alClient;
AImage.Parent := Self;
end;
destructor TMyPanel.Destroy;
begin
inherited;
end;
end.
If I compile and install the above into a package, the result is as shown below:
Problem
I would like my component to be registered as one single component. But the component should be a combination of both TScrollBox and TImage. The main component will be the TScrollBox, but it should now have access to the properties and events etc of the TImage aswell.
For example, TMyPanel could share the properties of TImage and TScrollBox together:
- AutoSize
- BorderStyle
- HorzScrollBar
- ParentBackground
- Picture
- VertScrollBar
I think it would be overkill to completely write a new component to do the behavior described above, that and I really wouldn't know where to begin. If this can be accomplished you could create some interesting components that are combined into one, but keep there original properties, methods and events etc.
This is what I want to achieve here with a TImage inside a TScrollBox.
Solution
The answer shown by Uwe Raabe works as expected. The TImage is now registered inside the TScrollBox, but appears as one component. The properties of the TImage are shown in the Object Inspector as Image. > which will reveal the properties of TImage :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…