WizardInterface (Delphi)
Contents
Description
The following sample creates a menu wizard. It adds a new button in the Help menu that displays the name for each component of the active form. To use this sample, create a Delphi package, add a form with TMemo and TButton components and a new unit to your new package by right-clicking the bpl and selecting "Add New". Then add the code below. Make sure that the form name is NameListForm, so the Wizard unit finds it.
Because MenuWizardUnit uses ToolsAPI, select View > Project > Add to Project. This will display the "Add to Project" dialog. Select "designide.dcp" from the EMBT>RAD Studio\8.0\lib\win32\release installation directory. You may have to set the file type to *.*
The host app for your bpl is the IDE; so you need to specify EMBT\RAD Studio\8.0\bin\bds.exe in View > Run > Parameters as the host app.
To run, load the code project and then right-click the bpl file and select install.
From MenuWizardUnit.pas:
Code
//Wizard Interface
unit MenuWizardUnit;
interface
uses
ToolsAPI, Windows, SysUtils, Classes, Forms, Messages, Menus;
type
MenuWizard = class(TNotifierObject, IOTAWizard, IOTAMenuWizard)
public
{ IOTAWizard }
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure Execute;
{ IOTAMenuWizard }
function GetMenuText: string;
end;
procedure Register;
implementation
uses NameListForm;
const
MenuIdString = 'Component Name';
Menu = 'Component name format';
procedure Register;
begin
RegisterPackageWizard(MenuWizard.Create);
end;
function MenuWizard.GetIDString;
begin
Result := MenuIdString;
end;
function MenuWizard.GetName;
begin
Result:= MenuIdString;
end;
function MenuWizard.GetState;
begin
Result := [wsEnabled];
end;
function MenuWizard.GetMenuText;
begin
Result:=Menu;
end;
procedure InitWizard;
begin
// nothing needed
end;
procedure MenuWizard.Execute;
begin
if Name_List_Form= nil then
begin
Name_List_Form := TForm1.Create(Application);
end;
Name_List_Form.Show;
Name_List_Form.BringToFront;
end;
procedure DoneWizard;
begin
if Name_List_Form <> nil then
begin
FreeAndNil(Name_List_Form);
end;
end;
initialization
InitWizard;
finalization
DoneWizard;
end.
From NameListForm.pas
Code
//NameListForm Unit
unit NameListForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
end;
var
Name_List_Form: TForm1;
Active_Form: TForm;
implementation
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
Memo1.Text:='Form Caption: '+Active_Form.Caption +#13#10+'The components number is: '+IntToStr(Active_Form.ComponentCount)+#13#10;
for i:=0 to Active_Form.ComponentCount-1 do
Memo1.Text:=Memo1.Text+ Active_Form.Components[i].Name+#13#10;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
i:=0;
Active_Form:=Screen.ActiveForm;
Memo1.Text:='Form Caption: '+Active_Form.Caption +#13#10+'The components number is:: '+IntToStr(Active_Form.ComponentCount)+#13#10;
for i:=0 to Active_Form.ComponentCount-1 do
Memo1.Text:=Memo1.Text+ Active_Form.Components[i].Name+#13#10;
end;
end.
Uses
- System.IInterface
- System.IInterface.QueryInterface
- System.IInterface._AddRef
- System.IInterface._Release
- System.IUnknown