unit DevFormExpt;
interface
uses
Classes, SysUtils, Controls, Windows, ToolsApi;
Type
TNewFormExpt = class(TInterfacedObject, IOTAWizard, IOTARepositoryWizard,
IOTAProjectWizard, IOTACreator, IOTAModuleCreator)
private
FFileName:String;
protected
{IOTARepositoryWizard}
function GetAuthor: string; //作者信息
function GetComment: string;//描述
function GetPage: string; //向导所在页签
function GetGlyph: Cardinal;//图标
{IOTAWizard}
function GetIDString: string;//唯一标识
function GetName: string; //向导名称
function GetState: TWizardState;//向导状态
procedure Execute; //触发向导时执行
{IOTANotifier}
procedure AfterSave;
procedure BeforeSave;
procedure Destroyed;
procedure Modified;
{IOTACreator}
function GetCreatorType: string; //创建文件类型 窗体或单元
function GetExisting: Boolean; //
function GetFileSystem: string;
function GetOwner: IOTAModule; //获取新建对象的父对象(项目工程单元模块)
function GetUnnamed: Boolean; //由IDE自动命名
function GetAncestorName: string;//基类名称
{IOTAModuleCreator}
function GetImplFileName: string;//实现文件名称
function GetIntfFileName: string;//头文件名称
{ Return the form name }
function GetFormName: string; //获取新窗体的名称
function GetMainForm: Boolean; //新生成的窗体是否作为主窗体
function GetShowForm: Boolean; //IDE显示新生成的窗体
function GetShowSource: Boolean; //IDE显示新生成的单元
{ Create and return the Form resource for this new module if applicable }
function NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
{ Create and return the Implementation source for this module. (C++ .cpp
file or Delphi unit) }
function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
{ Create and return the Interface (C++ header) source for this module }
function NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
{ Called when the new form/datamodule/custom module is created }
procedure FormCreated(const FormEditor: IOTAFormEditor);
public
end;
procedure RegNewFormExpt;
implementation
uses HrsConst, HrsUtils;
Type
TDevFormOATFile = class(TInterfacedObject, IOTAFile)
private
FFormName: string;
function GetFormName: string;
public
function GetAge: TDateTime;
function GetSource: string;
constructor Create(AFormName: string);
end;
procedure RegNewFormExpt;
begin
RegisterPackageWizard(TNewFormExpt.Create as IOTAWizard);
end;
{ TNewFormExpt }
procedure TNewFormExpt.AfterSave;
begin
end;
procedure TNewFormExpt.BeforeSave;
begin
end;
procedure TNewFormExpt.Destroyed;
begin
end;
procedure TNewFormExpt.Execute;
var tmpUnitName, tmpClassName:String;
begin
(BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName('Unit', tmpUnitName, tmpClassName, FFileName);//根据给出的前缀获取唯一的类名称和单元名称
(BorlandIDEServices as IOTAModuleServices).CreateModule(Self);//根据传递的构造器生成单元文件
end;
procedure TNewFormExpt.FormCreated(const FormEditor: IOTAFormEditor);
begin
end;
function TNewFormExpt.GetAncestorName: string;
begin
Result := 'Form';
end;
function TNewFormExpt.GetAuthor: string;
begin
Result := CAuthor;
end;
function TNewFormExpt.GetComment: string;
begin
Result := 'Dev窗体生成向导';
end;
function TNewFormExpt.GetCreatorType: string;
begin
Result := sForm;//创建窗体
end;
function TNewFormExpt.GetExisting: Boolean;
begin //创建新模块则直接返回False
Result := False;
end;
function TNewFormExpt.GetFileSystem: string;
begin
Result := '';
end;
function TNewFormExpt.GetFormName: string;
begin
Result := StringReplace(ExtractFileName(FFileName), 'Unit', 'NewForm', []);
Result := StringReplace(Result, '.pas', '', []);
//MessageBox(0, PChar(Result), '', 0);
end;
function TNewFormExpt.GetGlyph: Cardinal;
begin
Result := 0;//LoadIcon(HInstance, 'F');
end;
function TNewFormExpt.GetIDString: string;
begin
Result:= '{5534E2A5-22D0-4395-AADF-F11945D1A0F7}';
end;
function TNewFormExpt.GetImplFileName: string;
begin
Result := FFileName; //通过调用(BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName获得
end;
function TNewFormExpt.GetIntfFileName: string;
begin
Result := ''; //获得接口文件名称(Delphi中头文件与实现文件合并为一个文件)
end;
function TNewFormExpt.GetMainForm: Boolean;
begin
Result:=False;
end;
function TNewFormExpt.GetName: string;
begin
Result:='Dev窗体';
end;
function TNewFormExpt.GetOwner: IOTAModule;
begin
Result:=ToolsAPI.GetActiveProject;
if (Result = nil) then
Result := THelpClass.GetFirstModuleSupporting(IOTAProject) as IOTAProject;
end;
function TNewFormExpt.GetPage: string;
begin
Result := CPageName;
end;
function TNewFormExpt.GetShowForm: Boolean;
begin
Result:=True;
end;
function TNewFormExpt.GetShowSource: Boolean;
begin
Result:=True;
end;
function TNewFormExpt.GetState: TWizardState;
begin
Result:=[wsEnabled];
end;
function TNewFormExpt.GetUnnamed: Boolean;
begin
Result := True;
end;
procedure TNewFormExpt.Modified;
begin
end;
function TNewFormExpt.NewFormFile(const FormIdent,
AncestorIdent: string): IOTAFile;
begin
Result := TDevFormOATFile.Create(GetFormName);
end;
function TNewFormExpt.NewImplSource(const ModuleIdent, FormIdent,
AncestorIdent: string): IOTAFile;
begin
//..
end;
function TNewFormExpt.NewIntfSource(const ModuleIdent, FormIdent,
AncestorIdent: string): IOTAFile;
begin
Result := nil;
end;
{ TDevFormOATFile }
constructor TDevFormOATFile.Create(AFormName: string);
begin
FFormName := AFormName;
end;
function TDevFormOATFile.GetAge: TDateTime;
begin
Result := Now;
end;
function TDevFormOATFile.GetFormName: string;
begin
Result := FFormName;
end;
function TDevFormOATFile.GetSource: string;
var
oList: TStringList;
begin
oList := TStringList.Create;
try
oList.Add('object ' + GetFormName + ': T' + GetFormName);
oList.Add(' Left = 0');
oList.Add(' Top = 0');
oList.Add(' Caption = ''NewForm1''');
oList.Add(' ClientHeight = 206');
oList.Add(' ClientWidth = 455');
oList.Add(' OldCreateOrder = False');
oList.Add(' PixelsPerInch = 96');
oList.Add('end');
Result := oList.Text;
//MessageBox(0, PChar(Result), '', 0);
finally
oList.Free;
end;
end;
end.
注册函数:
procedure Register;
begin
RegNewFormExpt;
end;