10

I'm using delphi 7 and I'm trying to make a wizard interface. I don't know if there is an easier way to make a wizard, so I was thinking of making separate forms for each step of the wizard, and when the user clicks "Next" the active form closes and the next one opens.

Here's a screen-shot of two successive forms: screen-shot

I've made a procedure that take 2 forms as parameters: the form that will be closed and the next form of the wizard

class Procedure Tspad.nextForm(showForm, closeForm: TForm);
begin
   closeForm.Close;
   showForm.Showmodal;
end;

When I click the "Next" Button the folowing code is executed:

Tspad.nextForm(echipContractForm, clientContractForm);

When i run the program, and i press the "Next" button, the next form apeares but the curent one dosen't close.

How can i make this work, or is there another more efficient way to create a wizard?

Mike Spadaru
  • 501
  • 6
  • 15
  • 4
    Use TPageControl : http://delphi.about.com/od/delphitips2007/qt/hidepagectrltab.htm – SimaWB Dec 05 '11 at 11:43
  • 3
    Project Jedi (JVCL) has a wizard component called [TJvWizard](http://wiki.delphi-jedi.org/wiki/JVCL_Help:TJvWizard). – LU RD Dec 05 '11 at 12:42

6 Answers6

20

One very common way to make a wizard is to use a page control. Each distinct page of the wizard is a different page/tabsheet in the page control. I believe that this is effectively how Windows implements wizards.

Naturally you want to hide all the tabs. Do this by setting TabVisible to False for each tabsheet. When you wish to move forwards and backwards through the wizard, e.g. when the user clicks the next or previous buttons, effect this by setting ActivePage or ActivePageIndex depending on your preference.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • This is how I've done it in the past. Have a separate form for your wizard, with the page control and some buttons. – Marcus Adams Dec 05 '11 at 14:44
  • i agree with this but also with LaKraven's idea to make a form per page, and dock the pages at runtime. Otherwise wizards tend to turn into a giant ball of spaghetti. – Warren P Dec 05 '11 at 14:49
  • @Warren LaKraven is actually suggesting frames rather than forms and I presume docking them at design time. But either way works and can be a very good technique to keep the spaghetti at bay, I agree. – David Heffernan Dec 05 '11 at 19:14
  • For better results you could set DoubleBuffered to true. – Ben May 15 '13 at 16:19
14

A good practise for the division of content being displayed on a single form is the use of Frames.

A Frame is a lot like a form, except it has no Window of its own, but rather sits inside a host Form.

When combined with (as David Heffernan has suggested) a TPageControl or even a TNotebook (which is pretty-much exactly the same as TPageControl, only it doesn't have Tabs to begin with), you end up with an easily-maintainable Wizard.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
LaKraven
  • 5,804
  • 2
  • 23
  • 49
11

JVCL has a good control to make a wizard in a very simple and effective way (TJvWizard). See http://jvcl.delphi-jedi.org/

4

You can give a try to these :

Community
  • 1
  • 1
menjaraz
  • 7,551
  • 4
  • 41
  • 81
2

You can test some components that can help you with this task (internally using tPageControl or TNotebook). See this link.

Regards.

0

You may also consider TMS TAdvSmoothStepControl (not free !). Another solution, but only 'external' to your program, is to use Inno Setup to make a Wizard, even for 'non installation setup' purposes.

In fact with Inno Setup you can make a lot of thinks ( modify .ini file and registry, start/stop programs...) that can be usefull for a wizard without 'installing' a program.

philnext
  • 3,242
  • 5
  • 39
  • 62
  • 1
    The last statement in your answer presumes the OP is trying to produce an Installation Wizard. The screenshots suggest otherwise. I suggest editing that part of your answer out and leaving the recommendation of TAdvSmoothStepControl (which is a nice component for sure) – LaKraven Dec 05 '11 at 22:15
  • @LaKraven While the main use for Inno Setup is to create an installation setup, you may also use it (with some hack) as a Wizard for simple operations, like close a program, change .ini files according to user choices, and run the program again. May be it is not clear for all and I'll edit my answer. – philnext Dec 06 '11 at 22:32