By: Corbin Dunn
Abstract: How to create a wizard the remembers its position and state in the desktop speedsettings.
Creating a Web Search Wizard for Delphi
By Corbin Dunn
Delphi Developer Support
Allen Bauer has written three articles for the OpenTools API with the most recent giving us some ideas on how to create a dockable IDE form. One thing that he didn't go into was how to get an expert or wizard to remember its position and state. This article goes through how I created a Web Search Expert for Delphi 5 that remembers its current position and state in the Desktop Speedsetting.
First of all, download the complete project so we are on the same playing field. I strongly recommend reading Allen Bauer's article to see how I started the project, but this isn't necessary. The key in his article is how to derive from an internal IDE form by adding DsnIDE50.dcp to the requires list of the package. After you have downloaded the source, open up the package SearchWiz.dpk.
Now, take a look at the unit SearchWizMnu. This is your normal registration unit that adds a menu item named "Web search..." to the Delphi IDE's Help menu. One of the new things to notice is in the Register procedure I call RegisterFieldAddress passing two parameters: a string that is the SearchWizForm's ini file section (which is 'SearchWizard' in this case), and the actual address of the SearchWizForm variable:
if Assigned(RegisterFieldAddress) then
Last Query=Corbin's treehouse
Last Search Engine=Borland Community
Use Same Window=1
RegisterDesktopFormClass(TSearchWizForm, CIniSection, CIniSection);
if Assigned(UnRegisterFieldAddress) then
if SearchWizForm <> nil then
SearchWizForm := nil;
Next, we want to open up the main form unit, SearchWizFrm.pas, but it uses some internal IDE forms that I got from Allen's example, and if we open up SearchWizFrm.pas it will complain about not finding the base classes. The trick here is to open up DeskForm.pas, then DockForm.pas, and finally SearchWizFrm.pas. To get my Search Wizard to remember its position and data, I overrode LoadWindowState and SaveWindowState (both of which are in TDesktopForm). In SaveWindowState we are passed a TMemIniFile from which I write my settings to. By first calling inherited SaveWindowState, TDesktopForm saves the current position and visible properties.
procedure TSearchWizForm.SaveWindowState(Desktop: TMemIniFile;
inherited SaveWindowState(Desktop, IsProject);
if SaveStateNecessary and (Desktop <> nil) then
Desktop.WriteString(CIniSection, CIniLastSearchQuery, cmbxQuery.Text);
with cmbxEngines do
Desktop.WriteString(CIniSection, CIniLastSearchEngine, Items[ItemIndex]);
if IsProject then
for I := 0 to cmbxQuery.Items.Count - 1 do
Desktop.WriteString(CIniSavedQueries, IntToStr(I), cmbxQuery.Items[I]);
Desktop.WriteBool(CIniSection, CIniUseSameWindow, FUseSameWindow);
Desktop.WriteBool(CIniSection, CIniWebBrowserShowing, FWebBrowserShowing);
procedure TSearchWizForm.LoadWindowState(Desktop: TMemIniFile);
if Desktop <> nil then
cmbxQuery.Text := Desktop.ReadString(CIniSection, CIniLastSearchQuery, '');
CIniLastSearchEngine, '')) >= 0 then
The next thing that you will want to do is install this Wizard into the IDE. It should be as simple as clicking "Install Package" in the Package Editor window. You will notice that the usual Project->Compile (F9) option will not work because a lot of the internal code is running in the IDE. This is normal, and also makes debugging really difficult. The easiest way to do it is to place ShowMessage calls inside of function calls to see where your program is at. Or, you could log things to a file.
Once again, feel free to download the source code for this project. Open up SearchWiz.dpk and click "Install Package". Then, select "Help->Web Search..." and save your desktop if you want it to remember the wizard being open!
If you find any problems with the source code, please let me know! I also wouldn't mind getting any updates you make to enhance the Wizard...
Download Delphi XE5 and create Android apps!
Get Free Trial
Webinars on demand!
More social media choices:
Delphi on Google+
@RADTools on Twitter
Server Response from: ETNASC02