Sunday, December 14, 2008

The Delphi Wizard Framework - Navigation

In a previous entry, I discussed some of the design decisions that allowed me to reach the current solution. One more decision which greatly impacted the design of the framework... I wanted to make sure that it could be data driven.

One of the projects that I was working on at the time was an editor for an XML datafile. For simplicity sake, the file had a structure something like the following:

<data>
<book>
<author>
<name>Steven King</name>
</author>
</book>
<movie>
<director>
<name>Stanley Kubrick</name>
</director>
</movie>
</data>

The goal of the program was to create an editor that could handle each child element. I created two forms, one named tBookWizardForm and another named tMovieWizardForm. Invoking these pages from the first page of the wizard looked something like the following:

procedure EditChild(ChildNode:IXmlNode);
var
NodeAware : IXmlNodeAware;
begin
fWizMgr.NavigateToPage('T'+ChildNode.NodeName+'WizardForm');
if Supports(fWizMgr.CurForm,IXmlNodeAware,NodeAware) then
NodeAware.SetXmlNode(ChildNode);
end;

Note in this example: The call to NavigateToPage automatically inserts the current page into the "to be deleted" list so there is no need to perform any manual cleanup.

The interface IXmlNodeAware actually exists in another unit which is shared by both wizard forms, it looks like the following:

type
IXmlNodeAware = interface
['{F78DF157-CBAF-48A3-BC4C-CE338514C898}']
Procedure SetXmlNode(Node:IXmlNode);
end

This would automatically perform the dispatch to the proper wizard form, if it ran into a node which it did not understand, it would generate an exception which would be handled and displayed by the wizard manager (displays a dialog that states that the requested form was not registered).

In my next post, I will cover SetAllowDeletion, and why one would need to use it.

1 comment:

Kofi said...

Hi,

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

-
Delphi development