In so many modern applications, we frequently see the help of Wizard in making things easier for the users to do specific tasks, with step-by-step method. Can we utilize the similar Wizard in our Delphi applications?? The answer is: Yes and very easy, by reading this article, you are expected to create Wizard in a short period.
William Yu Wei had created an intuitive component KWizard. You can view his website in http://members.rogers.com/wyu66/index.htm. To get start with, you must download the latest version of that component (KWizard.zip, which is version 1.7 currently) from his website, or from Mikrodata's CD Accompanion.
If you have installed the previous version, then you must delete the package from Delphi IDE. Next, do the following steps properly:
- Unzip KWizard.zip to a directory
- From Delphi IDE, choose menu File - Open, then switch to the directory you used in step #1, open KWizardD?R.dpk, and do compile process
- From Delphi IDE, choose menu File - Open, open KWizardD?.dpk, and do compile & install process
- Optionally, you can do compile and install process for two routemaps sample components, by opening dclRouteMap.dpk
Figure 1. KWizard Palette
Symbol ? represents the Delphi version you are using, in example you are using Delphi 5, then you must open file KWizardD5R.dpk and KWizardD5.dpk
Before using KWizard, you must create a new form in your application. Then you simply put KWizard component (in our example, we give the name wzrdMain) in that form, and you will see an empty Wizard screen you are familiar with, see this picture:
Figure 2. Empty KWizard Screen
Usually, a Wizard will be started with a Welcome Page. You simply right-click at the KWizard panel and choose New Welcome Page, we give the name wzrdpgWelcome.
Figure 3. Welcome Page Screen
To customize the appearance, you can arrange the property from wzrdpgWelcome object:
- Caption (seen as "This is caption")
- Header.Title (seen as "Welcome")
- Header.SubTitle (seen as "Welcome to my first Wizard written with KWizard")
- Image.Picture (seen as the bitmap picture)
You can also display other types of control (i.e. TEdit, TComboBox, TCheckBox, Tbutton, etc) simply by putting the control components you desired to the Wizard page (seen from ComboBox1 example).
Next, we need to create several pages contain the steps of our Wizard, these pages are called Interior Pages. To create them is quite easy, right-click on KWizard panel and choose New Interior Page option, we give the name wzrdpgSelectMode.
Figure 4. Interior Page Screen
To adjust the text or add elements, you can use the same method with Welcome Page.
Arranging Page Ordering
For example, we have created three Interior Pages:
- wzrdpgTambah: add new data
- wzrdpgUbah: modify existing data
- wzrdpgHapus: delete existing data
Now we need to arrange the page order. KWizard enables you to arrange the page order easily, simply by arranging the Enabled property for each Interior Page you have.
Add OnNextButtonClick event on wzrdpgSelectMode, as follows:
procedure TfrmMain.wzrdpgSelectModeNextButtonClick(Sender: TObject; var Stop: Boolean); begin wzrdpgTambah.Enabled := rdbtnTambah.Checked; wzrdpgUbah.Enabled := rdbtnUbah.Checked; wzrdpgHapus.Enabled := rdbtnHapus.Checked; end;
Be careful when adding the event-handling code in KWizard because you need to differentiate whether the event is best suited to KWizard itself (affecting the entire Wizard) or to specific Welcome Page / Interior Page (applied only to those pages). In short, analyze which object you need to add the event-handling code to, do not confuse because your code is not working in a proper manner because of faulty event-handling code placement.
Arranging Finish and Cancel
Usually a Wizard has a last Interior Page regarding the user confirmation of the task being executed (Finish), cancel the task (Cancel), or back to previous screen (Back). We need to create a Interior Page (we give the name wzrdpgFinish), and here we arrange the VisibleButtons property for this page, which we set bkNext to False and bkFinish to True.
Figure 5. Last Interior Page Screen
Next we need to add code for OnFinishButtonClick and OnCancelButtonClick event for KWizard object, because it applies to all pages generally, no matter which Interior Page is displayed currently.
procedure TfrmMain.wzrdMainFinishButtonClick(Sender: TObject); begin if rdbtnTambah.Checked then MessageDlg( 'Tambah data...', mtInformation, [ mbOK ], 0 ) else if rdbtnUbah.Checked then MessageDlg( 'Ubah data...', mtInformation, [ mbOK ], 0 ) else if rdbtnHapus.Checked then MessageDlg( 'Hapus data...', mtInformation, [ mbOK ], 0 ); Close; end; procedure TfrmMain.wzrdMainCancelButtonClick(Sender: TObject); begin MessageDlg( 'Cancelled by user...', mtInformation, [ mbOK ], 0 ); Close; end;
PageList is very useful when you want to insert a Interior Page or see the list of pages you created. To display PageList, you do right-click on KWizard panel and choose Page List menu.
Figure 6. PageList Screen
To display the Wizard route visually, we can utilize RouteMaps, currently there are two RouteMaps samples created by Steve Forbes and Max Evans. The usage is quite simple, simply by dropping the RouteMaps components in our form.
Figure 7. RouteMaps Sample Screen by Steve Forbes
Figure 8. RouteMaps Sample Screen by Max Evans
As we have seen, creating Wizard in Delphi with KWizard component is a very easy job. Also KWizard is a freeware with source code, can be distributed as long as you give the original archieve. You can read the License Agreement info in its website.
About the Author
I am a IT practician working for an apparel manufacturing company, using Delphi, Clipper, and PHP as the primary programming languages. Please visit my personal website in http://www.hianoto.net
Notes: This articles was published in Mikrodata Magazine.