How to create a form file using Delphi OTA (Open Tools API)

Viewed 163

I'm trying to create a project wizard using OTA. The project needs a .dpr file, and a form unit (.pas and .dfm files). Something wrong at my code, .dfm does not created. Note that "NewFormFile" procedure in module creator is not called. Follow part of code:

  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, FormIdent,
      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;

The procedure "TModuleCreator.NewFormFile" is never executed.

0 Answers
Related