📄 abwizard.pas
字号:
unit ABWizard;
interface
uses Windows, Classes, ToolsAPI;
type
TAppBarWizard = class(TNotifierObject, IOTAWizard, IOTARepositoryWizard,
IOTAFormWizard, IOTACreator, IOTAModuleCreator)
private
FUnitIdent: string;
FClassName: string;
FFileName: string;
protected
// IOTAWizard methods
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure Execute;
// IOTARepositoryWizard / IOTAFormWizard methods
function GetAuthor: string;
function GetComment: string;
function GetPage: string;
function GetGlyph: HICON;
// IOTACreator methods
function GetCreatorType: string;
function GetExisting: Boolean;
function GetFileSystem: string;
function GetOwner: IOTAModule;
function GetUnnamed: Boolean;
// IOTAModuleCreator methods
function GetAncestorName: string;
function GetImplFileName: string;
function GetIntfFileName: string;
function GetFormName: string;
function GetMainForm: Boolean;
function GetShowForm: Boolean;
function GetShowSource: Boolean;
function NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
function NewImplSource(const ModuleIdent, FormIdent,
AncestorIdent: string): IOTAFile;
function NewIntfSource(const ModuleIdent, FormIdent,
AncestorIdent: string): IOTAFile;
procedure FormCreated(const FormEditor: IOTAFormEditor);
end;
implementation
uses Forms, AppBars, SysUtils, DsgnIntf;
{$R CodeGen.res}
type
TBaseFile = class(TInterfacedObject)
private
FModuleName: string;
FFormName: string;
FAncestorName: string;
public
constructor Create(const ModuleName, FormName, AncestorName: string);
end;
TUnitFile = class(TBaseFile, IOTAFile)
protected
function GetSource: string;
function GetAge: TDateTime;
end;
TFormFile = class(TBaseFile, IOTAFile)
protected
function GetSource: string;
function GetAge: TDateTime;
end;
{ TBaseFile }
constructor TBaseFile.Create(const ModuleName, FormName,
AncestorName: string);
begin
inherited Create;
FModuleName := ModuleName;
FFormName := FormName;
FAncestorName := AncestorName;
end;
{ TUnitFile }
function TUnitFile.GetSource: string;
var
Text: string;
ResInstance: THandle;
HRes: HRSRC;
begin
ResInstance := FindResourceHInstance(HInstance);
HRes := FindResource(ResInstance, 'CODEGEN', RT_RCDATA);
Text := PChar(LockResource(LoadResource(ResInstance, HRes)));
SetLength(Text, SizeOfResource(ResInstance, HRes));
Result := Format(Text, [FModuleName, FFormName, FAncestorName]);
end;
function TUnitFile.GetAge: TDateTime;
begin
Result := -1;
end;
{ TFormFile }
function TFormFile.GetSource: string;
const
FormText =
'object %0:s: T%0:s'#13#10'end';
begin
Result := Format(FormText, [FFormName]);
end;
function TFormFile.GetAge: TDateTime;
begin
Result := -1;
end;
{ TAppBarWizard }
{ TAppBarWizard.IOTAWizard }
function TAppBarWizard.GetIDString: string;
begin
Result := 'DDG.AppBarWizard';
end;
function TAppBarWizard.GetName: string;
begin
Result := 'DDG AppBar Wizard';
end;
function TAppBarWizard.GetState: TWizardState;
begin
Result := [wsEnabled];
end;
procedure TAppBarWizard.Execute;
begin
(BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName(
'AppBar', FUnitIdent, FClassName, FFileName);
(BorlandIDEServices as IOTAModuleServices).CreateModule(Self);
end;
{ TAppBarWizard.IOTARepositoryWizard / TAppBarWizard.IOTAFormWizard }
function TAppBarWizard.GetGlyph: HICON;
begin
Result := 0; // use standard icon
end;
function TAppBarWizard.GetPage: string;
begin
Result := 'DDG';
end;
function TAppBarWizard.GetAuthor: string;
begin
Result := 'Delphi 5 Developer''s Guide';
end;
function TAppBarWizard.GetComment: string;
begin
Result := 'Creates a new AppBar form.'
end;
{ TAppBarWizard.IOTACreator }
function TAppBarWizard.GetCreatorType: string;
begin
Result := '';
end;
function TAppBarWizard.GetExisting: Boolean;
begin
Result := False;
end;
function TAppBarWizard.GetFileSystem: string;
begin
Result := '';
end;
function TAppBarWizard.GetOwner: IOTAModule;
var
I: Integer;
ModServ: IOTAModuleServices;
Module: IOTAModule;
ProjGrp: IOTAProjectGroup;
begin
Result := nil;
ModServ := BorlandIDEServices as IOTAModuleServices;
for I := 0 to ModServ.ModuleCount - 1 do
begin
Module := ModSErv.Modules[I];
// find current project group
if CompareText(ExtractFileExt(Module.FileName), '.bpg') = 0 then
if Module.QueryInterface(IOTAProjectGroup, ProjGrp) = S_OK then
begin
// return active project of group
Result := ProjGrp.GetActiveProject;
Exit;
end;
end;
end;
function TAppBarWizard.GetUnnamed: Boolean;
begin
Result := True;
end;
{ TAppBarWizard.IOTAModuleCreator }
function TAppBarWizard.GetAncestorName: string;
begin
Result := 'TAppBar';
end;
function TAppBarWizard.GetImplFileName: string;
var
CurrDir: array[0..MAX_PATH] of char;
begin
// Note: full path name required!
GetCurrentDirectory(SizeOf(CurrDir), CurrDir);
Result := Format('%s\%s.pas', [CurrDir, FUnitIdent, '.pas']);
end;
function TAppBarWizard.GetIntfFileName: string;
begin
Result := '';
end;
function TAppBarWizard.GetFormName: string;
begin
Result := FClassName;
end;
function TAppBarWizard.GetMainForm: Boolean;
begin
Result := False;
end;
function TAppBarWizard.GetShowForm: Boolean;
begin
Result := True;
end;
function TAppBarWizard.GetShowSource: Boolean;
begin
Result := True;
end;
function TAppBarWizard.NewFormFile(const FormIdent,
AncestorIdent: string): IOTAFile;
begin
Result := TFormFile.Create('', FormIdent, AncestorIdent);
end;
function TAppBarWizard.NewImplSource(const ModuleIdent, FormIdent,
AncestorIdent: string): IOTAFile;
begin
Result := TUnitFile.Create(ModuleIdent, FormIdent, AncestorIdent);
end;
function TAppBarWizard.NewIntfSource(const ModuleIdent, FormIdent,
AncestorIdent: string): IOTAFile;
begin
Result := nil;
end;
procedure TAppBarWizard.FormCreated(const FormEditor: IOTAFormEditor);
begin
// do nothing
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -