{**********************************************}
{   TeeChart Wizard                            }
{   Copyright (c) 1996-2020 by Steema Software }
{**********************************************}
unit TeeChartExp;
{$I TeeDefs.inc}

{$IFNDEF D6}
{$UNDEF TEEENTERPRISE}  { Less than Delphi 6, No ADO ! }
{$ENDIF}

interface

uses
     {$IFNDEF LINUX}
     Windows,
     {$ENDIF}
     {$IFDEF D7}
     ToolsApi
     {$ELSE}
     ExptIntf, ToolIntf, VirtIntf, IStreams
     {$ENDIF}
     ;

type
  {$IFDEF D7}
  TTeeChartWizard=class(TNotifierObject, IOTAWizard,
                        {$IFNDEF D9}
                        IOTAMenuWizard,
                        {$ENDIF}
                        IOTAFormWizard, IOTARepositoryWizard,
                        IOTARepositoryWizard60
                        {$IFDEF D9}
                        ,IOTARepositoryWizard80
                        {$ENDIF})
  public
    IsBCB : Boolean;

    function GetIDString: string;
    function GetName: string;
    function GetState: TWizardState;
    function GetDesigner: string;
    procedure Execute;

    {.$IFNDEF D9}  // Breaks Demand-load
    function GetMenuText: string;
    {.$ENDIF}

    function GetAuthor: string;
    function GetComment: string;
    function GetPage: string;
    function GetGlyph: Cardinal;

    {$IFDEF D9}
    function GetGalleryCategory: IOTAGalleryCategory;
    function GetPersonality: string;
    {$ENDIF}
  end;
  {$ELSE}
  TTeeChartWizard = class(TIExpert)
    IsBCB : Boolean;
    
    function GetName: string; override;
    function GetAuthor: string; override;
    function GetComment: string; override;
    function GetGlyph: HICON; override;
    function GetStyle: TExpertStyle; override;
    function GetState: TExpertState; override;
    function GetIDString: string; override;
    function GetPage: string; override;
    procedure Execute; override;
    function GetMenuText: string; override;
  end;
  {$ENDIF}

Procedure Register;

implementation

{$R TeeChaEx.res}

uses Forms, Controls, Classes, SysUtils, Proxies,

     {$IFNDEF NOUSE_BDE}
     DB, DBTables, DBChart,
     {$IFDEF TEEENTERPRISE}
     AdoDB,
     {$ENDIF}
     {$ENDIF}

     TeeExpForm, TeeStore, TeeConst, Chart, TeeProcs, TeCanvas, TeEngine;

function DoFormCreation(Wizard: TTeeDlgWizard; const FormIdent: string): TForm;

  Procedure AddControls(AForm:TCustomForm);
  var tmpChart : TCustomChart;
      {$IFNDEF NOUSE_BDE}
      tmpTable : TDataSet;
      {$ENDIF}
      t       : Integer;
  begin
    {$IFNDEF NOUSE_BDE}
    tmpTable:=nil;
    {$ENDIF}

    tmpChart:=nil;

    with Wizard do
    {$IFNDEF NOUSE_BDE}
    if RGDatabase.ItemIndex=0 then
    begin
      if StyleBDE then
      begin
        tmpTable:=TTable.Create(AForm);
        With TTable(tmpTable) do
        begin
          DatabaseName:=CBAlias.Text;
          TableName:=CBTables.Text;
        end;
      end
      else
      begin
        {$IFDEF TEEENTERPRISE}
        tmpTable:=TADOQuery.Create(AForm);
        With TADOQuery(tmpTable) do
        begin
          ConnectionString:=ADOConn.ConnectionString;
          SQL.Assign(ADOQuery.SQL);
        end;
        {$ENDIF}
      end;

      with tmpTable do
      begin
        Left:=12;
        Top:=8;
        if StyleBDE then Name:=TeeMsg_WizardTable1
                    else Name:='ADOQuery1';
        Open;
      end;

      tmpChart:=TDBChart.Create(AForm);
    end
    else
    {$ENDIF}
       tmpChart:=TChart.Create(AForm);

    if Wizard.RGDatabase.ItemIndex=2 then
    with Wizard do
    begin
      tmpChart.Parent:=AForm;
      CopyPreviewChart(tmpChart);
    end
    else
    begin
      With tmpChart do
      begin
        Parent:=AForm;
        Assign(Wizard.PreviewChart as TCustomChart);
      end;

      Wizard.CreateSeries(AForm,tmpChart{$IFNDEF NOUSE_BDE},tmpTable{$ENDIF},False)
    end;

    // set component names
    with tmpChart do
    begin
       Name:=TeeGetUniqueName(AForm,Copy(ClassName,2,Length(ClassName)));

      {$IFNDEF NOUSE_BDE}
      if Wizard.RGDatabase.ItemIndex=0 then
         Left:=48
      else
      {$ENDIF}
         Left:=8;

      Top:=8;

      for t:=0 to SeriesCount-1 do
      with Series[t] do
      if Name='' then
         Name:=TeeGetUniqueName(AForm,Copy(ClassName,2,Length(ClassName)));

      for t:=0 to Tools.Count-1 do
      with Tools[t] do
      if Name='' then
         Name:=TeeGetUniqueName(AForm,Copy(ClassName,2,Length(ClassName)));

      AllowPanning:=pmBoth;
      Zoom.Allow:=True;
      BevelOuter:=bvRaised;
    end;
  end;

begin
  result:=TForm.Create(nil);
  Proxies.CreateSubClass(Result, 'T' + FormIdent, TForm);  { <-- dont translate }

  with Result do
  begin
    Name    :=FormIdent;
    Caption :=FormIdent;
    Width:=470;
    Height:=300;

    ParentFont:=True;
  end;

  AddControls(result);
end;

function GetFirstChart(AForm:TCustomForm):TCustomChart;
var t : Integer;
begin
  result:=nil;

  with AForm do
  for t:=0 to ComponentCount-1 do
  if Components[t] is TCustomChart then
  begin
    result:=TCustomChart(Components[t]);
    break;
  end;
end;

function FormExtension:String;
begin
  {$IFDEF D7}
  result:=(BorlandIDEServices as IOTAServices).GetActiveDesignerType;

  if result='' then
     result:='dfm';

  {$ELSE}
  result:='dfm';
  {$ENDIF}
end;

const
  CRLF = TeeTextLineSeparator;

function TeeNamespace:String;
{$IFDEF D16}
var ext : String;
{$ENDIF}
begin
  {$IFDEF D16}
  ext:=UpperCase(FormExtension);

  if ext='DFM' then
     result:='VCLTee.'
  else
  if ext='FMX' then
     result:='FMXTee.'
  else
     result:='';

  {$ELSE}
  result:='';
  {$ENDIF};
end;

Function GetPascalSource(Wizard:TTeeDlgWizard; AForm:TCustomForm;
                         const ModuleIdent,FormIdent:String):String;

  function FrameworkUses:String;
  begin
    if FormExtension='fmx' then
       result:='  Classes, SysUtils, FMX.Types, FMX.Controls, FMX.Forms, FMX.StdCtrls,'+CRLF+
               '  '+TeeNamespace+'Engine, '+TeeNamespace+'Procs, '+
                    TeeNamespace+'Chart, '+TeeNamespace+'Series'
    else
       result:='  Windows, Messages, SysUtils, Classes,'+CRLF+
               '  Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,'
               +CRLF+
               '  '+TeeNamespace+'TeEngine, '+TeeNamespace+'TeeProcs, '+
                    TeeNamespace+'Chart, '+TeeNamespace+'Series'
               ;
  end;

var tmp : String;
    t   : Integer;
begin

  { unit header and uses clause }
  tmp:=Format(
    'unit %s;' + CRLF + CRLF +
    'interface' + CRLF + CRLF +
    'uses'+CRLF + FrameworkUses,[ModuleIdent]);

  { additional units that may be needed }
  {$IFNDEF NOUSE_BDE}
  if Wizard.RGDatabase.ItemIndex=0 then
     if Wizard.StyleBDE then
        tmp:=tmp+ ', '+TeeNamespace+'DBChart, DB, DBTables'
     else
        tmp:=tmp+ ', '+TeeNamespace+'DBChart, DB, ADODB';
  {$ENDIF}

  tmp:=tmp+ ';' + CRLF + CRLF;

  { begin the class declaration }
  tmp:=tmp+'type'+CRLF +'  T'+FormIdent+' = class(TForm)'+CRLF;

  { add variable declarations }

  {$IFNDEF NOUSE_BDE}
  if Wizard.RGDatabase.ItemIndex=0 then
     if Wizard.StyleBDE then
        tmp:=tmp+'    Table1 : TTable;' + CRLF
     else
        tmp:=tmp+'    ADOQuery1 : TADOQuery;' + CRLF;
  {$ENDIF}

  with GetFirstChart(AForm) do
  begin
    tmp:=tmp+'    '+Name+': '+ClassName+';' + CRLF;

    for t:=0 to SeriesCount-1 do
    with Series[t] do
         tmp:=tmp+Format('    %s: %s;'+CRLF,[Name,ClassName]);

    for t:=0 to Tools.Count-1 do
    with Tools[t] do
         tmp:=tmp+Format('    %s: %s;'+CRLF,[Name,ClassName]);
  end;

  tmp:=tmp+Format(
    '  private'+CRLF+
    '    '+TeeMsg_PrivateDeclarations+CRLF+
    '  public'+CRLF+
    '    '+TeeMsg_PublicDeclarations+CRLF+
    '  end;' + CRLF + CRLF +
    'var' + CRLF +
    '  %s: T%s;' + CRLF + CRLF +
    'implementation' + CRLF + CRLF +
    '{$R *.'+ FormExtension +'}' + CRLF + CRLF, [FormIdent, FormIdent]);

  result:=tmp+'end.' + CRLF;
end;

const
  DashLine =
  '//----------------------------------------------------------------------------';

function Header(const AName:String):String;
begin
  {$IFDEF D11}
  result:='#include <'+AName+'>';
  {$ELSE}
  result:='#include <vcl\'+AName+'>';
  {$ENDIF}
end;

function GetCppSource(const UnitIdent, FormIdent:String):String;

  function FrameworkHeader:String;
  begin
    if FormExtension='fmx' then
       result:='fmx.h'
    else
       result:='vcl.h';
  end;

begin
  result:=Format(DashLine + CRLF + CRLF +
          Header(FrameworkHeader) + CRLF +
          '#pragma hdrstop' + CRLF +
          CRLF +
          '#include "%0:s.h"' + CRLF +
          DashLine + CRLF +
          '#pragma package(smart_init)' + CRLF +
          '#pragma resource "*.'+FormExtension+'"' + CRLF +
          'T%1:s *%1:s;' + CRLF +
          DashLine + CRLF +
          '__fastcall T%1:s::T%1:s(TComponent* Owner)' + CRLF +
          '        : TForm(Owner)' + CRLF +
          '{' + CRLF +
          '}' + CRLF +
          DashLine, [UnitIdent,FormIdent]);
end;

function GetHppSource(Wizard:TTeeDlgWizard; AForm:TCustomForm;
                      const UnitIdent, FormIdent:String):String;

  function FrameworkIncludes:String;
  begin
    if FormExtension='fmx' then
       result:=Header('FMX.Types.hpp')+ CRLF +
               Header('FMX.Controls.hpp') + CRLF +
               Header('FMX.StdCtrls.hpp') + CRLF +
               Header('FMX.Forms.hpp')+ CRLF +
               Header(TeeNamespace+'Engine.hpp') + CRLF +
               Header(TeeNamespace+'Procs.hpp') + CRLF +
               Header(TeeNamespace+'Series.hpp') + CRLF +
               Header(TeeNamespace+'Chart.hpp') + CRLF
    else
       result:=Header('Controls.hpp') + CRLF +
               Header('StdCtrls.hpp') + CRLF +
               Header('Forms.hpp')+ CRLF +
               Header(TeeNamespace+'TeEngine.hpp') + CRLF +
               Header(TeeNamespace+'TeeProcs.hpp') + CRLF +
               Header(TeeNamespace+'Series.hpp') + CRLF +
               Header(TeeNamespace+'Chart.hpp') + CRLF;
  end;

var t: Integer;
begin
  result:=Format(
          DashLine + CRLF +
          '#ifndef %0:sH' + CRLF +
          '#define %0:sH' + CRLF +
          DashLine + CRLF +
          Header('Classes.hpp')  + CRLF +
          FrameworkIncludes+CRLF, [UnitIdent]);

  {$IFNDEF NOUSE_BDE}
  if Wizard.RGDatabase.ItemIndex=0 then
    if Wizard.StyleBDE then
       result:=result+
          Header(TeeNamespace+'DBChart.hpp') + CRLF +
          Header('DB.hpp') + CRLF +
          Header('DBTables.hpp') + CRLF
    else
       result:=result+
          Header(TeeNamespace+'DBChart.hpp') + CRLF +
          Header('DB.hpp') + CRLF +
          Header('ADODB.hpp') + CRLF;

  {$ENDIF}

  result:=result+DashLine + CRLF;

  result:=result+Format(
    'class T%s : public TForm' + CRLF +
    '{' + CRLF +
    '__published:' + CRLF, [FormIdent]);

  {$IFNDEF NOUSE_BDE}
  if Wizard.RGDatabase.ItemIndex=0 then
     if Wizard.StyleBDE then
        result:=result+'TTable *Table1;' + CRLF
     else
        result:=result+'TADOQuery *ADOQuery1;' + CRLF;
  {$ENDIF}

  with GetFirstChart(AForm) do
  begin
    result:=result+Format('%s *%s;' + CRLF, [ClassName,Name]);

    for t:=0 to SeriesCount-1 do
    with Series[t] do
         result:=result+Format('%s *%s;'+CRLF,[ClassName,Name]);

    for t:=0 to Tools.Count-1 do
    with Tools[t] do
         result:=result+Format('%s *%s;'+CRLF,[ClassName,Name]);
  end;

  result:=result+Format('private:'+CRLF +
           'public:' +CRLF +
           '  __fastcall  '+ {$IFNDEF D16}'T%0:s::'+{$ENDIF} 'T%0:s(TComponent* Owner);' + CRLF +
           '};' + CRLF ,[FormIdent]);

  result:=result+Format(
    DashLine + CRLF +
    'extern  T%0:s *%0:s;' + CRLF +
    DashLine + CRLF +
    '#endif', [FormIdent]);
end;

{$IFDEF D7}
type
  TTeeChartModuleCreator = class(TInterfacedObject, IOTACreator, IOTAModuleCreator)
  private
    TheForm : TCustomForm;
    Wizard  : TTeeDlgWizard;
    IsBCB   : Boolean;
  public
    Constructor Create(AWizard:TTeeDlgWizard; IsCBuilder:Boolean);
    Destructor Destroy; override;

    // IOTACreator
    function GetCreatorType: string;
    function GetExisting: Boolean;
    function GetFileSystem: string;
    function GetOwner: IOTAModule;
    function GetUnnamed: Boolean;
    // IOTAModuleCreator
    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;

{$ELSE}
procedure TeeChartWizard(ToolServices: TIToolServices; IsBCB:Boolean);

Const SourceBufferSize = 1024;
var SourceBuffer : PChar;

  procedure FmtWrite(Stream: TStream; Const Fmt: String;
    const Args: array of const);
  begin
    if Assigned(Stream) and Assigned(SourceBuffer) then
    begin
      StrLFmt(SourceBuffer, SourceBufferSize, @Fmt[1], Args);
      Stream.Write(SourceBuffer[0], StrLen(SourceBuffer));
    end;
  end;

var D: TTeeDlgWizard;

  function CreateHeader(const UnitIdent, FormIdent:String;
                        AForm:TForm): TMemoryStream;
  begin
    SourceBuffer := StrAlloc(SourceBufferSize);
    try
      Result := TMemoryStream.Create;
      try
        FmtWrite(Result,GetHppSource(D,AForm,UnitIdent,FormIdent),[nil]);
        Result.Position := 0;
      except
        Result.Free;
        raise;
      end;
    finally
      StrDispose(SourceBuffer);
    end;
  end;

  function CreateCppSource(const UnitIdent,FormIdent:String): TMemoryStream;
  begin
    SourceBuffer := StrAlloc(SourceBufferSize);
    try
      Result := TMemoryStream.Create;
      try
        FmtWrite(Result,GetCppSource(UnitIdent, FormIdent),[nil]);
        Result.Position := 0;
      except
        Result.Free;
        raise;
      end;
    finally
      StrDispose(SourceBuffer);
    end;
  end;

  function CreateDelphiSource(const UnitIdent, FormIdent: string;
                              AForm:TCustomForm): TMemoryStream;
  begin
    SourceBuffer := StrAlloc(SourceBufferSize);
    try
      Result := TMemoryStream.Create;
      try
        FmtWrite(Result,GetPascalSource(D,AForm,UnitIdent,FormIdent),[nil]);
        Result.Position := 0;
      except
        Result.Free;
        raise;
      end;
    finally
      StrDispose(SourceBuffer);
    end;
  end;

var IHeaderStream : TIMemoryStream;
    ISourceStream : TIMemoryStream;
    IFormStream   : TIMemoryStream;
    UnitIdent     : String;
    FormIdent     : String;
    FileName      : String;
    ChartForm     : TForm;
    tmpStream     : TMemoryStream;
begin
  if (ToolServices<>nil) and
     ToolServices.GetNewModuleName(UnitIdent, FileName) then
  begin
    D := TTeeDlgWizard.Create(Application);
    try
      if D.ShowModal = mrOK then
      begin
        UnitIdent := LowerCase(UnitIdent);
        UnitIdent[1] := Upcase(UnitIdent[1]);
        FormIdent := 'Form' + Copy(UnitIdent, 5, 255);

        ChartForm:=DoFormCreation(D,FormIdent);
        try
          tmpStream:=TMemoryStream.Create;
          tmpStream.WriteComponentRes(FormIdent, ChartForm);
          tmpStream.Position:=0;

          IFormStream := TIMemoryStream.Create(tmpStream);

          if IsBCB then
          begin
            IHeaderStream := TIMemoryStream.Create(CreateHeader(UnitIdent,FormIdent,ChartForm), soOwned);
            ISourceStream := TIMemoryStream.Create(CreateCppSource(UnitIdent,FormIdent), soOwned);
            ToolServices.CreateCppModule(FileName, '', '', '', IHeaderStream,
              ISourceStream, IFormStream, [cmAddToProject, cmShowSource,
              cmShowForm, cmUnNamed, cmMarkModified]);
          end
          else
          begin
            ISourceStream := TIMemoryStream.Create(CreateDelphiSource(UnitIdent,FormIdent,ChartForm));
            ToolServices.CreateModule(FileName, ISourceStream, IFormStream,
                  [ cmAddToProject, cmShowSource, cmShowForm, cmUnNamed,
                    cmMarkModified]);
          end;
        finally
          ChartForm.Free;
        end;
      end;
    finally
      D.Free;
    end;
  end;
end;
{$ENDIF}

{ TTeeChartWizard }
function TTeeChartWizard.GetName: string;
begin
  Result:=TeeMsg_TeeChartWizard;
end;

function TTeeChartWizard.GetComment: string;
begin
  Result:=TeeMsg_TeeChartWizard;
end;

{$IFDEF D7} // Delphi 5
function TTeeChartWizard.GetGlyph: Cardinal;
{$ELSE}
function TTeeChartWizard.GetGlyph: HICON;
{$ENDIF}
begin
  {$IFDEF D7}
    Result:=LoadIcon(HInstance, 'TEEEXPICON');
  {$ELSE}
  result:=0;
  try
    Result:=LoadIcon(HInstance, 'TEEEXPICON');
  except
    ToolServices.RaiseException(ReleaseException);
  end;
  {$ENDIF}
end;

{$IFNDEF D7}
function TTeeChartWizard.GetStyle: TExpertStyle;
begin
  Result:=esForm;
end;
{$ENDIF}

{$IFDEF D7}
function TTeeChartWizard.GetDesigner: string;
begin
  result:=dVCL;
end;

{$IFDEF D9}
function TTeeChartWizard.GetGalleryCategory: IOTAGalleryCategory;
var Manager: IOTAGalleryCategoryManager;
begin
  Manager:=(BorlandIDEServices as IOTAGalleryCategoryManager);

  if IsBCB then
     result:=Manager.FindCategory({$IFDEF D26}sCategoryCBuilderWindows{$ELSE}sCategoryCBuilderNewFiles{$ENDIF})
  else
     result:=Manager.FindCategory({$IFDEF D26}sCategoryDelphiWindows{$ELSE}sCategoryDelphiNewFiles{$ENDIF});
end;

function TTeeChartWizard.GetPersonality: string;
begin
  if IsBCB then
     result:=sCBuilderPersonality
  else
     result:=sDelphiPersonality;
end;
{$ENDIF}

function TTeeChartWizard.GetState: TWizardState;
begin
  Result:=[wsEnabled];
end;
{$ELSE}
function TTeeChartWizard.GetState: TExpertState;
begin
  Result:=[esEnabled];
end;
{$ENDIF}

function TTeeChartWizard.GetIDString: string;
begin
  Result:=TeeMsg_TeeChartIDWizard;

  if IsBCB then
     result:=result+'Cpp';
end;

function TTeeChartWizard.GetAuthor: string;
begin
  Result:=TeeMsg_TeeChartSL;
end;

function TTeeChartWizard.GetPage: string;
begin
{$IFDEF D26}
  if IsBCB then
     Result:=sCategoryCBuilderWindows
  else
     Result:=sCategoryDelphiWindows;
{$ELSE}
  Result:=TeeMsg_WizardTab;
{$ENDIF}
end;

procedure TTeeChartWizard.Execute;
{$IFDEF D7}
var D: TTeeDlgWizard;
{$ENDIF}
begin
  {$IFDEF D7}
  D := TTeeDlgWizard.Create(Application);
  try
    if D.ShowModal = mrOK then
       (BorlandIDEServices as IOTAModuleServices).CreateModule(TTeeChartModuleCreator.Create(D,IsBCB));
  finally
    D.Free;
  end;
  {$ELSE}
  try
    TeeChartWizard(ToolServices,IsBCB);
  except
    ToolServices.RaiseException(ReleaseException);
  end;
  {$ENDIF}
end;

{.$IFNDEF D9}  // Breaks Demand-load
function TTeeChartWizard.GetMenuText: string;
begin
  result:=TeeMsg_TeeChartWizard+'...';
end;
{.$ENDIF}

Procedure Register;
var Wizard : TTeeChartWizard;
begin
  Wizard:=TTeeChartWizard.Create;

  {$IFNDEF D9}
  {$IFDEF BCB}
  Wizard.IsBCB:=True;
  {$ENDIF}
  {$ENDIF}

  {$IFDEF D7}
  // Delphi
  RegisterPackageWizard(Wizard);

  {$IFDEF D9}
  // C++ Builder
  Wizard:=TTeeChartWizard.Create;
  Wizard.IsBCB:=True;
  RegisterPackageWizard(Wizard);
  {$ENDIF}

  {$ELSE}
  RegisterLibraryExpert(Wizard);
  {$ENDIF}
end;

{$IFDEF D7}

{ TTeeChartModuleCreator }

Constructor TTeeChartModuleCreator.Create(AWizard:TTeeDlgWizard; IsCBuilder:Boolean);
begin
  inherited Create;
  Wizard:=AWizard;
  IsBCB:=IsCBuilder;
end;

Destructor TTeeChartModuleCreator.Destroy;
begin
  FreeAndNil(TheForm);
  inherited;
end;

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

function TTeeChartModuleCreator.GetAncestorName: string;
begin
  Result := 'Form';
end;

function TTeeChartModuleCreator.GetCreatorType: string;
begin
  Result := sForm;
end;

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

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

function TTeeChartModuleCreator.GetFormName: string;
begin
  Result := '';
end;

function TTeeChartModuleCreator.GetImplFileName: string;
begin
  Result := '';
end;

function TTeeChartModuleCreator.GetIntfFileName: string;
begin
  Result := '';
end;

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

// From Delphi 7 help file
function TTeeChartModuleCreator.GetOwner: IOTAModule;

  function FindAProject:IOTAModule;
  var
    I: Integer;
    Svc: IOTAModuleServices;
    Module: IOTAModule;
    Project: IOTAProject;
    Group: IOTAProjectGroup;
  begin
    Supports(BorlandIDEServices, IOTAModuleServices, Svc);

    for I := 0 to Svc.ModuleCount - 1 do
    begin
      Module := Svc.Modules[I];

      if Supports(Module, IOTAProject, Project) then
      begin
        { Remember the first project module}
        if Result = nil then
          Result := Project;
      end
      else if Supports(Module, IOTAProjectGroup, Group) then
      begin
        { Found the project group, so return its active project}
        Result := Group.ActiveProject;
        Exit;
      end;

    end;
  end;
  
begin
  { Return the current project. }
  {$IFDEF D7}
  result:=GetActiveProject;

  if not Assigned(result) then
  {$ENDIF}
    result := FindAProject;
end;

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

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

function TTeeChartModuleCreator.GetUnnamed: Boolean;
begin
  Result := True;
end;

function TTeeChartModuleCreator.NewFormFile(const FormIdent,
  AncestorIdent: string): IOTAFile;

  function ComponentToString(Component: TComponent): string;
  var
    BinStream:TMemoryStream;
    StrStream: TStringStream;
    s: string;
  begin
    BinStream := TMemoryStream.Create;
    try
      StrStream := TStringStream.Create(s);
      try
        BinStream.WriteComponent(Component);
        BinStream.Seek(0, soFromBeginning);
        ObjectBinaryToText(BinStream, StrStream);
        StrStream.Seek(0, soFromBeginning);
        Result:= StrStream.DataString;
      finally
        StrStream.Free;
      end;
    finally
      BinStream.Free
    end;
  end;

begin
  if not Assigned(TheForm) then
     TheForm:=DoFormCreation(Wizard,FormIdent);

  result:=StringToIOTAFile(ComponentToString(TheForm));
end;

function TTeeChartModuleCreator.NewImplSource(const ModuleIdent, FormIdent,
  AncestorIdent: string): IOTAFile;
begin
  if not Assigned(TheForm) then
     TheForm:=DoFormCreation(Wizard,FormIdent);

  if IsBCB then
     result:=StringToIOTAFile(GetCppSource(ModuleIdent,FormIdent))
  else
     result:=StringToIOTAFile(GetPascalSource(Wizard,TheForm,ModuleIdent,FormIdent));
end;

function TTeeChartModuleCreator.NewIntfSource(const ModuleIdent, FormIdent,
  AncestorIdent: string): IOTAFile;
begin
  if IsBCB then
  begin
    if not Assigned(TheForm) then
       TheForm:=DoFormCreation(Wizard,FormIdent);

    result:=StringToIOTAFile(GetHppSource(Wizard,TheForm,ModuleIdent,FormIdent));
  end
  else
    result:=nil;
end;
{$ENDIF}

end.
