Вниз
Скачать: CL | DM;

Notification   Найти похожие ветки 

 
D-NICKNAME ©   (2002-12-09 09:21) [0]

Привет всем!..
У меня проблема связывания компонентов, а точнее походу проблема с Notification. Сразу оговорюсь, что уведомлениями я пользуюсь первый раз. Есть 2 компонента TMDIControl и TDMDIContainer. TMDIControl привязывается к TDMDIContainer. После привязки в design-time удаляю TDMDIContainer. По идее TDMDIContainer должен уведомить TMDIControl о своём удалении. Вроде бы всё делаю как надо, но высвечивается Access violation. Скорее всего у меня ошибка. Вот код:

TMDIControl = class;

TDCustomMDIContainer = class(TCustomControl)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
procedure Paint; override;
published
{ Published declarations }
end;

TDMDIContainer = class(TDCustomMDIContainer)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
end;

TCustomMDIControl = class(TComponent)
private
FMDIContaier: TDMDIContainer;
procedure SetMDIContainer(const Value: TDMDIContainer);
procedure Notification(AComponent: TComponent; Operation: TOperation);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property MDIContainer: TDMDIContainer read FMDIContaier write SetMDIContainer;
end;

TMDIControl = class(TCustomMDIControl)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
end;

{ TDCustomMDIContainer }

constructor TDCustomMDIContainer.Create(AOwner: TComponent);
begin
inherited;
DoubleBuffered := True;
TabStop := False;
Height := 45;
Width := 185;
end;

procedure TDCustomMDIContainer.Paint;
var R: TRect;
begin
inherited;
with Canvas do begin
R := GetClientRect;
if (csDesigning in ComponentState) then DrawFocusRect(R);
end;
end;

{ TCustomMDIControl }

constructor TCustomMDIControl.Create(AOwner: TComponent);
begin
inherited;
FMDIContaier := nil;
end;

destructor TCustomMDIControl.Destroy;
begin

inherited;
end;

procedure TCustomMDIControl.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FMDIContaier) then FMDIContaier := nil;
end;

procedure TCustomMDIControl.SetMDIContainer(const Value: TDMDIContainer);
begin
if (Value <> FMDIContaier) then begin
// Здесь я пробывал разные модификации
if (Assigned(FMDIContaier)) then RemoveFreeNotification(FMDIContaier);
if (FMDIContaier <> nil) then FMDIContaier.FreeNotification(Self);
FMDIContaier := Value;
end;
end;


Заранее благодарю.


 
icWasya ©   (2002-12-09 09:36) [1]


procedure Notification(AComponent: TComponent; Operation: TOperation); override;


 
Юрий Зотов ©   (2002-12-09 09:41) [2]

procedure TCustomMDIControl.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (AComponent = FMDIContaier) then SetMDIContaier(nil)
end;

procedure TCustomMDIControl.SetMDIContainer(const Value: TDMDIContainer);
begin
if Value <> FMDIContaier then
begin
// Разрываем старую связь
if FMDIContaier <> nil then RemoveFreeNotification(FMDIContaier);
// Меняем ссылку
FMDIContaier := Value;
// Устанавливаем новую связь
if FMDIContaier <> nil then FreeNotification(FMDIContaier)
end
end;

В TCustomMDIControl конструктор и деструктор не делают ничего полезного и могут быть удалены. Поле FMDIContaier будет равным nil и без этого.


 
D-NICKNAME ©   (2002-12-10 15:08) [3]

2 icWasya
Краткость конечно же сестра таланта, но не в этой формулировке вопроса.

2 Юрий Зотов
Спасибо, теперь всё ясно.



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

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.017 c
1-61642
dkDimon
2002-12-06 23:04
2002.12.19
Звуковой регулятор


4-61874
kostik78ua
2002-11-06 14:15
2002.12.19
Нужен совет


6-61727
Ag2002
2002-10-23 16:33
2002.12.19
Сетевой файл


3-61392
Павка
2002-12-03 04:43
2002.12.19
Как заполнить шаблон Вордовский (справка) данными из базы


3-61474
Tlotr
2002-11-28 15:23
2002.12.19
Разное форматирование в одной колонке




   Наверх