如何使用 Delphi OTA (Open Tools API) 创建表单文件

问题描述

我正在尝试使用 OTA 创建项目向导。该项目需要一个 .dpr 文件一个表单单元(.pas 和 .dfm 文件)。我的代码有问题,没有创建 .dfm。请注意,不会调用模块创建者中的“NewFormFile”过程。遵循部分代码

  type
    TModuleCreator = Class(TInterfacedobject,IOTACreator,IOTAModuleCreator)
      {$IFDEF D2005} Strict {$ENDIF} Private
        FProject : IOTAProject;
      {$IFDEF D2005} Strict {$ENDIF} Protected
      Public
        Constructor Create(AProject: IOTAProject);
        // IOTACreator
        Function GetCreatorType: String;
        Function GetExisting: Boolean;
        Function GetFileSystem: String;
        Function Getowner: IOTAModule;
        Function GetUnnamed: Boolean;
        // IOTAModuleCreator
        Procedure FormCreated(Const FormEditor: IOTAFormEditor);
        Function GetAncestorName: String;
        Function GetFormName: String;
        Function GetImplFileName: String;
        Function GetIntfFileName: String;
        Function GetMainForm: Boolean;
        Function GetShowForm: Boolean;
        Function GetShowSource: Boolean;
        Function NewFormFile(Const FormIdent: String; Const AncestorIdent: String) : IOTAFile;
        Function NewImplSource(Const ModuleIdent: String; Const FormIdent: String;
          Const AncestorIdent: String): IOTAFile;
        Function NewIntfSource(Const ModuleIdent: String; Const FormIdent: String;
          Const AncestorIdent: String): IOTAFile;
      End;
    
      TModuleCreatorFile = Class(TInterfacedobject,IOTAFile)
      {$IFDEF D2005} Strict {$ENDIF} Private
      Public
        Constructor Create;
        function GetAge: TDateTime;
        function GetSource: string;
      End;
    
      TFormCreateFile = class(TInterfacedobject,IOTAFile)
      {$IFDEF D2005} strict {$ENDIF} private
      public
        constructor Create;
        function GetAge: TDateTime;
        function GetSource: string;
      end;
    
    Implementation
    
    uses
      SysUtils,Classes,Windows;
    
    { TModuleCreator }
    
    constructor TModuleCreator.Create(AProject: IOTAProject);
    begin
      FProject := AProject;
    end;
    
    function TModuleCreator.GetCreatorType: String;
    begin
      Result := sForm;
    end;
    
    function TModuleCreator.GetExisting: Boolean;
    begin
      Result := False;
    end;
    
    function TModuleCreator.GetFileSystem: String;
    begin
      Result := '';
    end;
    
    function TModuleCreator.Getowner: IOTAModule;
    begin
      Result := FProject;
    end;
    
    function TModuleCreator.GetUnnamed: Boolean;
    begin
      Result := True;
    end;
    
    procedure TModuleCreator.FormCreated(const FormEditor: IOTAFormEditor);
    begin
    end;
    
    function TModuleCreator.GetAncestorName: String;
    begin
      Result := 'TForm';
    end;
    
    function TModuleCreator.GetFormName: String;
    begin
      Result := 'Form1';
    end;
    
    function TModuleCreator.GetImplFileName: String;
    begin
      Result := '';
    end;
    
    function TModuleCreator.GetIntfFileName: String;
    begin
      Result := '';
    end;
    
    function TModuleCreator.GetMainForm: Boolean;
    begin
      Result := True;
    end;
    
    function TModuleCreator.GetShowForm: Boolean;
    begin
      REsult := True;
    end;
    
    function TModuleCreator.GetShowSource: Boolean;
    begin
      Result := True;
    end;
    
    function TModuleCreator.NewFormFile(const FormIdent,AncestorIdent: String): IOTAFile;
    begin
      // not pass here !!!!!
      Result := TFormCreateFile.Create;
    end;
    
    function TModuleCreator.NewImplSource(const ModuleIdent,FormIdent,AncestorIdent: String): IOTAFile;
    begin
      Result := TModuleCreatorFile.Create;
    end;
    
    function TModuleCreator.NewIntfSource(const ModuleIdent,AncestorIdent: String): IOTAFile;
    begin
      Result := Nil;
    end;
    
    { TModuleCreatorFile }
    
    constructor TModuleCreatorFile.Create;
    begin
    end;
    
    function TModuleCreatorFile.GetAge: TDateTime;
    begin
      Result := -1;
    end;
    
    function TModuleCreatorFile.GetSource: string;
    
    begin
      Result :=
        'Unit MyUnit;'#13#10 +
        ''#13#10 +
        'Interface'#13#10 +
        ''#13#10 +
        'Implementation'#13#10 +
        ''#13#10 +
        'End.'#13#10;
    end;
    
    { TFormCreateFile }
    
    constructor TFormCreateFile.Create;
    begin
    end;
    
    function TFormCreateFile.GetAge: TDateTime;
    begin
      Result:=-1;
    end;
    
    function TFormCreateFile.GetSource: string;
    begin
      Result :=
        'object Form1: TForm1') + #13#10 + 'end';
    end;

永远不会执行过程“TModuleCreator.NewFormFile”。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)