How to write Delphi Wizards
ToolServices
We've seen some generic but in fact pretty much useless Wizard so far.
In order to write truly more useful Wizards, we need to do something special inside the Execute method, like show a (more) interesting form in which a lot of things can happen, a bit like we introduced with the TSysInfoExpert.
Did you ever feel the need to load some project other than a .DPR file in the IDE?
No?
Never written any DLLs in Delphi?
Well, I often have the need to open a .PAS or any file with an extension other than .DPR inside the IDE as my project.
In fact, my need is so big, I want to write an Wizard to help me in browsing over my disk and directories in search for a certain file to open as a new project.
But is this possible?
To answer this question, we need to take a look at TOOLINTF.PAS from Delphi 1.0, the file that contains the definition of TIToolServices (the "I" stands for Interface again), which is as follows:
unit ToolIntf;
interface
uses
WinTypes, VirtIntf;
Type
TIToolServices = class(TInterface)
public
{ Action interfaces }
function CloseProject: Boolean; virtual; export; abstract;
function OpenProject(const ProjName: string): Boolean; virtual; export; abstract;
function OpenProjectInfo(const ProjName: string): Boolean; virtual; export; abstract;
function SaveProject: Boolean; virtual; export; abstract;
function CloseFile(const FileName: string): Boolean; virtual; export; abstract;
function SaveFile(const FileName: string): Boolean; virtual; export; abstract;
function OpenFile(const FileName: string): Boolean; virtual; export; abstract;
function ReloadFile(const FileName: string): Boolean; virtual; export; abstract;
function ModalDialogBox(Instance: THandle; TemplateName: PChar; WndParent: HWnd;
DialogFunc: TFarProc; InitParam: LongInt): Integer; virtual; export; abstract;
function CreateModule(const ModuleName: string; Source, Form: TIStream;
CreateFlags: TCreateModuleFlags): Boolean; virtual; export; abstract;
{ Project/UI information }
function GetParentHandle: HWND; virtual; export; abstract;
function GetProjectName: string; virtual; export; abstract;
function GetUnitCount: Integer; virtual; export; abstract;
function GetUnitName(Index: Integer): string; virtual; export; abstract;
function GetFormCount: Integer; virtual; export; abstract;
function GetFormName(Index: Integer): string; virtual; export; abstract;
function GetCurrentFile: string; virtual; export; abstract;
function IsFileOpen(const FileName: string): Boolean; virtual; export; abstract;
function GetNewModuleName(var UnitIdent, FileName: string): Boolean; virtual; export; abstract;
{ Component Library interface }
function GetModuleCount: Integer; virtual; export; abstract;
function GetModuleName(Index: Integer): string; virtual; export; abstract;
function GetComponentCount(ModIndex: Integer): Integer; virtual; export; abstract;
function GetComponentName(ModIndex, CompIndex: Integer): string; virtual; export; abstract;
{function InstallModule(const ModuleName: string): Boolean; virtual; export; abstract;
function CompileLibrary: Boolean; virtual; export; abstract;
}
{ Error handling }
procedure RaiseException(const Message: string); virtual; export; abstract;
end;
implementation
The Tool services object is created on the application (Delphi/C++Builder) side, and is passed to the VCS/Expert Manager DLL during initialization.
Note that the application (Delphi/C++Builder) is responsible for creating and freeing the interface object, and the client should never free the interface.
The following ToolServices functions are available to the client (for Delphi 1.0 as well as 2.0x and 3):
TIToolInterface for Delphi 2.0x and 3
Delphi 2.0x and 3 have an expanded Open Tools API (compared to Delphi 1.x), which is not only reflected in a few new methods for TIExpert, but especially for TIToolServices.
The following additional methods are new and for the 32-bits versions of Delphi only (methods that are shared with Delphi 1.0 have been left out for now):
TIToolServices = class(TInterface)
public
{ Action interfaces }
function CreateModuleEx(const ModuleName, FormName, AncestorClass,
FileSystem: string; Source, Form: TIStream;
CreateFlags: TCreateModuleFlags): TIModuleInterface; virtual;
stdcall; abstract;
{ Project/UI information }
function EnumProjectUnits(EnumProc: TProjectEnumProc; Param: Pointer): Boolean;
virtual; stdcall; abstract;
{ Virtual File system interfaces }
function RegisterFileSystem(AVirtualFileSystem: TIVirtualFileSystem): Boolean;
virtual; stdcall; abstract;
function UnRegisterFileSystem(const Ident: string): Boolean; virtual;
stdcall; abstract;
function GetFileSystem(const Ident: string): TIVirtualFileSystem; virtual;
stdcall; abstract;
{ Editor Interfaces }
function GetModuleInterface(const FileName: string): TIModuleInterface;
virtual; stdcall; abstract;
function GetFormModuleInterface(const FormName: string): TIModuleInterface;
virtual; stdcall; abstract;
{ Menu Interfaces }
function GetMainMenu: TIMainMenuIntf; virtual; stdcall; abstract;
{ Notification registration }
function AddNotifier(AddInNotifier: TIAddInNotifier): Boolean;
virtual; stdcall; abstract;
function RemoveNotifier(AddInNotifier: TIAddInNotifier): Boolean;
virtual; stdcall; abstract;
{ Pascal string handling functions }
function NewPascalString(Str: PChar): Pointer; virtual; stdcall; abstract;
procedure FreePascalString(var Str: Pointer); virtual; stdcall; abstract;
procedure ReferencePascalString(var Str: Pointer); virtual; stdcall; abstract;
procedure AssignPascalString(var Dest, Src: Pointer); virtual;
stdcall; abstract;
{ Configuration Access }
function GetBaseRegistryKey: string; virtual; stdcall; abstract;
end;
The following ToolServices functions are available to the client for 32-bits versions of Delphi only:
[HOME]
[TABLE OF CONTENTS]
[SEARCH]