2010-06-22 95 views
1

我有自定義窗體,它是TForm的後代。我使用ToolApi來註冊自定義模塊並將其添加到存儲庫。到現在爲止還挺好。但是當我點擊文件 - >新建時,我可以看到我的類別圖標爲我的自定義窗體,但它被禁用。圖標呈灰色,我無法從菜單中選擇它來創建自定義窗體並將其添加到項目中。使用ToolsApi在delphi 2010中註冊自定義窗體

你有什麼建議和提示什麼是錯的,我應該嘗試什麼?

Click here to transfer my source code...

在此先感謝。

編輯:

另外也列出的代碼,我覺得這是很重要的:

unit CustomFormFrame_Design;  

interface 

{$Include jvcl.inc} 

uses Windows, Classes, ToolsAPI; 

type 
    TPoCustomFormWizard = class(TNotifierObject, IOTAWizard, IOTARepositoryWizard,  
    IOTAFormWizard, IOTACreator, IOTAModuleCreator,  
    IOTARepositoryWizard60 
    {$IFDEF COMPILER8_UP}, IOTARepositoryWizard80 {$ENDIF COMPILER8_UP} 
    {$IFDEF COMPILER10_UP}, IOTAProjectWizard100 {$ENDIF COMPILER10_UP}) 
    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: Cardinal; 
    // 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); 

    { IOTARepositoryWizard60 } 
    function GetDesigner: string; 

    {$IFDEF COMPILER8_UP} 
    { IOTARepositoryWizard80 } 
    function GetGalleryCategory: IOTAGalleryCategory; virtual; 
    function GetPersonality: string; virtual; 
    {$ENDIF COMPILER8_UP} 

    {$IFDEF COMPILER10_UP} 
    { IOTAProjectWizard100 } 
    function IsVisible(Project: IOTAProject): Boolean; 
    {$ENDIF COMPILER10_UP} 

    {$IFDEF COMPILER8_UP} 
    property Personality: string read GetPersonality; 
    {$ENDIF} 


    end; 

    procedure Register;  

implementation 

    uses Forms, PoCustomForm, SysUtils, DesignIntf, DesignEditors; 

    {$R *.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; 

procedure Register; 
begin 
    RegisterCustomModule(TPoCustomForm, TCustomModule); 
    RegisterPackageWizard(TPoCustomFormWizard.Create); 
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 TPoCustomFormWizard.GetIDString: string; 
begin 
    Result := 'XFORM.PoCustomForm'; 
end; 

function TPoCustomFormWizard.GetName: string; 
begin 
    Result := 'XFORM PoCustom Form Wizard'; 
end; 

function TPoCustomFormWizard.GetState: TWizardState; 
begin 
    Result := [wsEnabled]; 
end; 

procedure TPoCustomFormWizard.Execute; 
begin 
    (BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName(
    'PoCustomForm', FUnitIdent, FClassName, FFileName); 
    (BorlandIDEServices as IOTAModuleServices).CreateModule(Self); 
end; 

{ TPoCustomFormWizard.IOTARepositoryWizard/TPoCustomFormWizard.IOTAFormWizard } 
function TPoCustomFormWizard.GetGlyph: Cardinal; 
begin 
    Result := 0; // use standard icon 
end; 


function TPoCustomFormWizard.GetPage: string; 
begin 
    Result := 'XFORM'; 
end; 

function TPoCustomFormWizard.GetAuthor: string; 
begin 
    Result := 'XFORM'; 
end; 

function TPoCustomFormWizard.GetComment: string; 
begin 
    Result := 'Creates a new PoCustom form.' 
end; 

{ TPoCustomFormWizard.IOTACreator } 
function TPoCustomFormWizard.GetCreatorType: string; 
begin 
    Result := ''; 
end; 

function TPoCustomFormWizard.GetDesigner: string; 
begin 
    Result := dVCL; 
end; 

{$IFDEF COMPILER8_UP} 
function TPoCustomFormWizard.GetGalleryCategory: IOTAGalleryCategory; 
begin 
    Result := (BorlandIDEServices as IOTAGalleryCategoryManager).FindCategory('Borland.Delphi.New.Expert'); 
end; 

function TPoCustomFormWizard.GetPersonality: string; 
begin 
    Result := sDelphiPersonality; 
end; 
{$ENDIF COMPILER8_UP} 

{$IFDEF COMPILER10_UP} 
function TPoCustomFormWizard.IsVisible(Project: IOTAProject): Boolean; 
begin 
    Result := True; 
end; 
{$ENDIF COMPILER10_UP} 

function TPoCustomFormWizard.GetExisting: Boolean; 
begin 
    Result := False; 
end; 

function TPoCustomFormWizard.GetFileSystem: string; 
begin 
    Result := ''; 
end; 

function TPoCustomFormWizard.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 TPoCustomFormWizard.GetUnnamed: Boolean; 
begin 
    Result := True; 
end; 

{ TPoCustomFormWizard.IOTAModuleCreator } 
function TPoCustomFormWizard.GetAncestorName: string; 
begin 
    Result := 'TPoCustomForm'; 
end; 

function TPoCustomFormWizard.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 TPoCustomFormWizard.GetIntfFileName: string; 
begin 
    Result := ''; 
end; 

function TPoCustomFormWizard.GetFormName: string; 
begin 
    Result := FClassName; 
end; 

function TPoCustomFormWizard.GetMainForm: Boolean; 
begin 
    Result := False; 
end; 

function TPoCustomFormWizard.GetShowForm: Boolean; 
begin 
    Result := True; 
end; 

function TPoCustomFormWizard.GetShowSource: Boolean; 
begin 
    Result := True; 
end; 

function TPoCustomFormWizard.NewFormFile(const FormIdent, 
AncestorIdent: string): IOTAFile; 
begin 
    Result := TFormFile.Create('', FormIdent, AncestorIdent); 
end; 

function TPoCustomFormWizard.NewImplSource(const ModuleIdent, FormIdent, 
AncestorIdent: string): IOTAFile; 
begin 
    Result := TUnitFile.Create(ModuleIdent, FormIdent, AncestorIdent); 
end; 

function TPoCustomFormWizard.NewIntfSource(const ModuleIdent, FormIdent, 
AncestorIdent: string): IOTAFile; 
begin 
    Result := nil; 
end; 

procedure TPoCustomFormWizard.FormCreated(const FormEditor: IOTAFormEditor); 
begin 
// do nothing 
end; 

end. 
+0

你可能想把這段代碼放在這裏(編輯你的問題)。在寫這篇文章之前,27位訪問過這個問題的人中的一位可能會遇到這樣的錯誤,但您不希望我們下載您的代碼,打開存檔並查看完整的代碼列表,是嗎?你應該做腿部的工作! – 2010-06-23 05:14:14

回答

2

一個完整的知識庫嚮導(自定義格式)是體現在布魯諾Fierens'白皮書,你可以從這裏得到:http://forms.embarcadero.com/forms/AMUSCA1104BrunoFierensOTAPIWhitepaper通過Embarcadero。

我給你的鏈接,而不僅僅是答案的原因是,我注意到你的代碼不止一個問題,你將通過閱讀白皮書獲益!它不會花費你很長時間,演示應用程序隨之而來,它不僅解決了這個問題,而且還解決了使用OTAPI時可能遇到的大多數問題。