MVP the Delphi's MDI Forms and MDI

MVP the Delphi's MDI Forms and MDI

Post by Sherly » Wed, 30 Nov 2005 18:07:55


Hi! I have read some MVP examples, which when presenter is created, it
will be assigned to a variable (to make sure the presenter is not being
free):

fPresenter := TStringListPresenter.Create(fModel, fView);

For my case, i have a MDI form which is the main form presenter and i
have created presenter for each of the MDIChild form. In order to hold
the presenters, i have created a presenter list (IInterfaceList) in the
main form presenter to hold the instances:

fPresenterList.Add(TMDIChildFormPresenter.Create(fModel, fView));

But when a MDI Child form is closed, i have to remove the presenter from
the MainForm presenter list. I used PostMessage to inform MainForm
presenter free the presenter of the current active form. It will delete
the presenter based on the current active form view:

for i := 0 to fPresenterList - 1 do begin
if fPresenterList[i].View = Screen.ActiveForm as IMVPView then begin
fPresenterList.Delete(i);
Break;
end;
end;

But i know using PostMessage is not a good OO practice.

Does anyone has better idea to solve the problem? Thanks in advance.
 
 
 

MVP the Delphi's MDI Forms and MDI

Post by Joanna Car » Wed, 30 Nov 2005 18:34:25


XXXX@XXXXX.COM ...

| Does anyone has better idea to solve the problem? Thanks in advance.

Two possible solutions :

1. Once an MDI child Presenter is added to the list leave it there and
simply assign a new View when you create another instance of that form
class.

2. Trap the child form's close event in the child presenter and surface an
event in the child presenter to be caught in the MDI main form Presenter,
this then allows you to update the list.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

 
 
 

MVP the Delphi's MDI Forms and MDI

Post by Sherly » Thu, 01 Dec 2005 15:08:54

> 2. Trap the child form's close event in the child presenter and surface an

There may be a problem in second way you proposed.

If MainForm presenter perform the close event on behalf of MDIChild
Presenter, closing the MDIchild form will remove the MDIchild presenter from
the MainForm presenter list. Removal of MDIChild presenter will remove the
MDIChild model, view and interactors. This will cause AV as the program
still in the context of MDIChild.

I find no way to escape from this. Please advice.
 
 
 

MVP the Delphi's MDI Forms and MDI

Post by Joanna Car » Thu, 01 Dec 2005 18:56:36


XXXX@XXXXX.COM ...

| If MainForm presenter perform the close event on behalf of MDIChild
| Presenter, closing the MDIchild form will remove the MDIchild presenter
from
| the MainForm presenter list. Removal of MDIChild presenter will remove
the
| MDIChild model, view and interactors. This will cause AV as the program
| still in the context of MDIChild.

Each Presenter should have its own Model, removing one Child Presenter
should only affect the child that it is presenting. Either that or hold an
external reference to the Model for each child and don't free the Model when
the Presenter is freed.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer