Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2003.08.21;
Скачать: [xml.tar.bz2];

Вниз

Подмена Parent компонента   Найти похожие ветки 

 
XanderMan   (2003-08-08 10:33) [0]

Здравствуйте. Создаю компонент:

TDropPanel = class(TCustomPanel)
private
FTopPanel: TPanel; - узкая панель с кнопкой показа/скрытия клиентской части
FClientPanel: TPanel; - клиентская часть
...
public
constructor Create(AOwner: TComponent); override;
...
end;

...

constructor TDropPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
...
FTopPanel := TPanel.Create(self);
with FTopPanel do begin
Parent := self;
Align := alTop;
...
end;

FClientPanel := TPanel.Create(self);
with FClientPanel do begin
Parent := self;
Align := alClient;
( self) Здравствуйте. Создаю компонент:

TDropPanel = class(TCustomPanel)
private
FTopPanel: TPanel; - узкая панель с кнопкой показа/скрытия клиентской части
FClientPanel: TPanel; - клиентская часть
...
public
constructor Create(AOwner: TComponent); override;
...
end;

...

constructor TDropPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
...
FTopPanel := TPanel.Create(self);
with FTopPanel do begin
Parent := self;
Align := alTop;
...
end;

FClientPanel := TPanel.Create(self);
with FClientPanel do begin
Parent := self;
Align := alClient;
...
end;
...
end;

Т.е. компонент является контейнером для двух панелей, которые занимают всю его площадь. Вопрос в

следующем:

1. В DesignTime бросаю на этот компонент, например, панель. При запуске панели нет. Она даже не создается. Вопрос: почему?

2. В RunTime создаю панель и указываю в качестве Parent данный компонент:

with TPanel.Create(self) do begin
Caption := "1111111111111";
Parent := DropPanel1;
Align := alBottom;
end;

Панель честно создается именно на DropPanel1. Вопрос: как сделать так, чтобы при указании TDropPanel в качестве Parent для другого компонента, свойство Parent этого компонента подменялось на

FClientPanel.

С уважением


 
sts   (2003-08-08 10:44) [1]

можно попробовать SetSubComponent


 
XanderMan   (2003-08-08 10:47) [2]

A subcomponent is a component whose Owner is a component other than the form or data module in which it resides.

Здесь нет ничего о Parent. Не могли бы Вы объяснить подробнее.

С уважением


 
sts   (2003-08-08 11:04) [3]

М.б. если сделать FClientPanel.SetSubComponent(true), то когда в design-time будут класть контролы на clientpanel, то в dfm парентом будет прописана clientpanel ?

Просто иначе не понятно как: SetParent вызывает Parent.InsertControl , которая вызывает Insert и все они не виртуальные, так что...


 
XanderMan   (2003-08-08 11:43) [4]

> М.б. если сделать FClientPanel.SetSubComponent(true), то когда в design-time будут класть контролы на clientpanel, то в dfm парентом будет прописана clientpanel ?

Сделал. Все равно ничего не получается. Даже если сохранить проект, а потом открыть, то панели, которую я бросил на DropPanel, не видно.


 
XanderMan   (2003-08-08 12:38) [5]

type
TPanelState = (pnsOpened, pnsClosed);

TDropPanel = class(TCustomPanel)
private
FTopPanel: TPanel;
FClientPanel: TPanel;
FSTateButton: TSpeedButton;
FPanelState: TPanelState;
FHeight: integer;
FOpenedHeight: integer;
FOnDropDown: TNotifyEvent;
FOnCloseUp: TNotifyEvent;
procedure ButtonClick(Sender: TObject);
function GetCaption: TCaption;
procedure SetCaption(const Value: TCaption);
procedure SetPanelState(const Value: TPanelState); virtual;
procedure SetOpenedHeight(Value: integer);
procedure SetAlignment(const Value: TAlignment);
procedure SetAlign(const Value: TAlign);
function GetAlignment: TAlignment;
function GetAlign: TAlign;
function GetHeight: integer;
procedure SetHeight(Value: integer);
function GetBevelInner: TBevelCut;
procedure SetBevelInner(const Value: TBevelCut);
function GetBevelOuter: TBevelCut;
procedure SetBevelOuter(const Value: TBevelCut);
protected
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
( AOwner: TComponent) type
TPanelState = (pnsOpened, pnsClosed);

TDropPanel = class(TCustomPanel)
private
FTopPanel: TPanel;
FClientPanel: TPanel;
FSTateButton: TSpeedButton;
FPanelState: TPanelState;
FHeight: integer;
FOpenedHeight: integer;
FOnDropDown: TNotifyEvent;
FOnCloseUp: TNotifyEvent;
procedure ButtonClick(Sender: TObject);
function GetCaption: TCaption;
procedure SetCaption(const Value: TCaption);
procedure SetPanelState(const Value: TPanelState); virtual;
procedure SetOpenedHeight(Value: integer);
procedure SetAlignment(const Value: TAlignment);
procedure SetAlign(const Value: TAlign);
function GetAlignment: TAlignment;
function GetAlign: TAlign;
function GetHeight: integer;
procedure SetHeight(Value: integer);
function GetBevelInner: TBevelCut;
procedure SetBevelInner(const Value: TBevelCut);
function GetBevelOuter: TBevelCut;
procedure SetBevelOuter(const Value: TBevelCut);
protected
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Align: TAlign read GetAlign write SetAlign;
property Alignment: TAlignment read GetAlignment write SetAlignment;
property Anchors;
property AutoSize;
property BevelInner: TBevelCut read GetBevelInner write SetBevelInner;
property BevelOuter: TBevelCut read GetBevelOuter write SetBevelOuter;
property BevelWidth;
property BiDiMode;
property BorderWidth;
property BorderStyle;
property Caption: TCaption read GetCaption write SetCaption;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Height: integer read GetHeight write SetHeight;
property Locked;
property OpenedHeight: integer read FOpenedHeight write SetOpenedHeight;
property PanelState: TPanelState read FPanelState write SetPanelState;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property OnDropDown: TNotifyEvent read FOnDropDown write FOnDropDown;
property OnCloseUp: TNotifyEvent read FOnCloseUp write FOnCloseUp;
end;



 
XanderMan   (2003-08-08 12:39) [6]

implementation

{ TDropPanel }

procedure TDropPanel.ButtonClick(Sender: TObject);
begin
if FPanelState = pnsOpened
then PanelState := pnsClosed else PanelState := pnsOpened;
end;

constructor TDropPanel.Create(AOwner: TComponent);
var
bm: TBitMap;
begin
inherited Create(AOwner);
bm := TBitMap.Create;
try
FOpenedHeight := 150;
inherited Height := FOpenedHeight;
inherited BevelOuter := bvNone;
Constraints.MinHeight := TopPanelHeight;
ControlStyle := ControlStyle-[csAcceptsControls];

FTopPanel := TPanel.Create(self);
with FTopPanel do begin
Parent := self;
Align := alTop;
Height := TopPanelHeight;
BevelInner := bvLowered;
BevelOuter := bvRaised;
Font.Style := [fsBold];
OnDblClick := ButtonClick;
end;

FClientPanel := TPanel.Create(self);
with FClientPanel do begin
Parent := self;
Align := alClient;
BevelInner := bvNone;
BevelOuter := bvNone;
end;

FStateButton := TSpeedButton.Create(FTopPanel);
with FStateButton do begin
Parent := FTopPanel;
Left := 2;
Top := 2;
Width := 20;
Height := 20;
GroupIndex := 7865;
AllowAllUp := True;
OnClick := ButtonClick;
Glyph.LoadFromResourceName(HInstance,"BUTTON");
NumGlyphs := 4;
end;

if csDesigning in ComponentState
then PanelState := pnsOpened
else PanelState := pnsClosed;
finally
bm.Free;
end;
end;

function TDropPanel.GetCaption: TCaption;
begin
Result := FTopPanel.Caption;
end;

procedure TDropPanel.SetCaption(const Value: TCaption);
begin
FTopPanel.Caption := Value;
end;

function TDropPanel.GetAlignment: TAlignment;
begin
Result := FTopPanel.Alignment;
end;

procedure TDropPanel.SetAlignment(const Value: TAlignment);
begin
FTopPanel.Alignment := Value;
end;

procedure TDropPanel.SetOpenedHeight(Value: integer);
begin
if Value < TopPanelHeight then Value := TopPanelHeight;
if FOpenedHeight <> Value then begin
FOpenedHeight := Value;
if PanelState = pnsOpened then begin
FHeight := Value;
inherited Height := Value;
end;
end;
end;

procedure TDropPanel.SetPanelState(const Value: TPanelState);
begin
FPanelState := Value;
if FPanelState = pnsOpened
then begin
inherited Height := OpenedHeight;
if Assigned(FOnDropDown) then FOnDropDown(self);
end
else begin
inherited Height := TopPanelHeight;
if Assigned(FOnCloseUp) then FOnCloseUp(self);
end;
FStateButton.Down := FPanelState = pnsOpened;
FClientPanel.Enabled := FSTateButton.Down;
FClientPanel.Visible := FSTateButton.Down;
end;

function TDropPanel.GetHeight: integer;
begin
Result := FHeight;
end;

procedure TDropPanel.SetHeight(Value: integer);
begin
if Value < TopPanelHeight then Value := TopPanelHeight;
if PanelState = pnsOpened then OpenedHeight := Value
end;

function TDropPanel.GetBevelInner: TBevelCut;
begin
Result := FClientPanel.BevelInner;
end;

function TDropPanel.GetBevelOuter: TBevelCut;
begin
Result := FClientPanel.BevelOuter;
end;

procedure TDropPanel.SetBevelInner(const Value: TBevelCut);
begin
FClientPanel.BevelInner := Value;
end;

procedure TDropPanel.SetBevelOuter(const Value: TBevelCut);
begin
FClientPanel.BevelOuter := Value;
end;

procedure TDropPanel.WMSize(var Msg: TWMSize);
begin
Height := Msg.Height;
Msg.Height := Height;
inherited;
end;

destructor TDropPanel.Destroy;
begin
if Assigned(FClientPanel) then FClientPanel.Free;
if Assigned(FTopPanel) then FTopPanel.Free;
inherited;
end;

function TDropPanel.GetAlign: TAlign;
begin
Result := inherited Align;
end;

procedure TDropPanel.SetAlign(const Value: TAlign);
begin
inherited Align := Value;
Realign;
end;

procedure TDropPanel.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation = opInsert) and (AComponent is TControl) and
((AComponent as TControl).Parent = self)
( AComponent as TControl) implementation

{ TDropPanel }

procedure TDropPanel.ButtonClick(Sender: TObject);
begin
if FPanelState = pnsOpened
then PanelState := pnsClosed else PanelState := pnsOpened;
end;

constructor TDropPanel.Create(AOwner: TComponent);
var
bm: TBitMap;
begin
inherited Create(AOwner);
bm := TBitMap.Create;
try
FOpenedHeight := 150;
inherited Height := FOpenedHeight;
inherited BevelOuter := bvNone;
Constraints.MinHeight := TopPanelHeight;
ControlStyle := ControlStyle-[csAcceptsControls];

FTopPanel := TPanel.Create(self);
with FTopPanel do begin
Parent := self;
Align := alTop;
Height := TopPanelHeight;
BevelInner := bvLowered;
BevelOuter := bvRaised;
Font.Style := [fsBold];
OnDblClick := ButtonClick;
end;

FClientPanel := TPanel.Create(self);
with FClientPanel do begin
Parent := self;
Align := alClient;
BevelInner := bvNone;
BevelOuter := bvNone;
end;

FStateButton := TSpeedButton.Create(FTopPanel);
with FStateButton do begin
Parent := FTopPanel;
Left := 2;
Top := 2;
Width := 20;
Height := 20;
GroupIndex := 7865;
AllowAllUp := True;
OnClick := ButtonClick;
Glyph.LoadFromResourceName(HInstance,"BUTTON");
NumGlyphs := 4;
end;

if csDesigning in ComponentState
then PanelState := pnsOpened
else PanelState := pnsClosed;
finally
bm.Free;
end;
end;

function TDropPanel.GetCaption: TCaption;
begin
Result := FTopPanel.Caption;
end;

procedure TDropPanel.SetCaption(const Value: TCaption);
begin
FTopPanel.Caption := Value;
end;

function TDropPanel.GetAlignment: TAlignment;
begin
Result := FTopPanel.Alignment;
end;

procedure TDropPanel.SetAlignment(const Value: TAlignment);
begin
FTopPanel.Alignment := Value;
end;

procedure TDropPanel.SetOpenedHeight(Value: integer);
begin
if Value < TopPanelHeight then Value := TopPanelHeight;
if FOpenedHeight <> Value then begin
FOpenedHeight := Value;
if PanelState = pnsOpened then begin
FHeight := Value;
inherited Height := Value;
end;
end;
end;

procedure TDropPanel.SetPanelState(const Value: TPanelState);
begin
FPanelState := Value;
if FPanelState = pnsOpened
then begin
inherited Height := OpenedHeight;
if Assigned(FOnDropDown) then FOnDropDown(self);
end
else begin
inherited Height := TopPanelHeight;
if Assigned(FOnCloseUp) then FOnCloseUp(self);
end;
FStateButton.Down := FPanelState = pnsOpened;
FClientPanel.Enabled := FSTateButton.Down;
FClientPanel.Visible := FSTateButton.Down;
end;

function TDropPanel.GetHeight: integer;
begin
Result := FHeight;
end;

procedure TDropPanel.SetHeight(Value: integer);
begin
if Value < TopPanelHeight then Value := TopPanelHeight;
if PanelState = pnsOpened then OpenedHeight := Value
end;

function TDropPanel.GetBevelInner: TBevelCut;
begin
Result := FClientPanel.BevelInner;
end;

function TDropPanel.GetBevelOuter: TBevelCut;
begin
Result := FClientPanel.BevelOuter;
end;

procedure TDropPanel.SetBevelInner(const Value: TBevelCut);
begin
FClientPanel.BevelInner := Value;
end;

procedure TDropPanel.SetBevelOuter(const Value: TBevelCut);
begin
FClientPanel.BevelOuter := Value;
end;

procedure TDropPanel.WMSize(var Msg: TWMSize);
begin
Height := Msg.Height;
Msg.Height := Height;
inherited;
end;

destructor TDropPanel.Destroy;
begin
if Assigned(FClientPanel) then FClientPanel.Free;
if Assigned(FTopPanel) then FTopPanel.Free;
inherited;
end;

function TDropPanel.GetAlign: TAlign;
begin
Result := inherited Align;
end;

procedure TDropPanel.SetAlign(const Value: TAlign);
begin
inherited Align := Value;
Realign;
end;

procedure TDropPanel.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation = opInsert) and (AComponent is TControl) and
((AComponent as TControl).Parent = self)
then (AComponent as TControl).Parent := FClientPanel;
end;


 
NAlexey   (2003-08-08 12:40) [7]

Чё это вы тут делаете?


 
XanderMan   (2003-08-08 12:45) [8]

> NAlexey © (08.08.03 12:40)

> Чё это вы тут делаете?

Не поверишь! Ж-)



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2003.08.21;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.5 MB
Время: 0.01 c
14-68465
Gorlum
2003-08-05 16:41
2003.08.21
fibplus4702


14-68537
Yanis
2003-08-02 18:36
2003.08.21
Шахматные игры


1-68370
XenonXX
2003-08-08 08:22
2003.08.21
Поиск, оптимизация.


7-68568
Алексей Глеб
2003-06-08 19:04
2003.08.21
Интерфейс


6-68430
k$v
2003-06-15 21:41
2003.08.21
Нужен простейший пример использования INDY ...





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский