unit uRegister;

// AsOf 2023-09-22
interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

procedure FormsRegister;
Function CreateForm(const FormName: string): TForm;

implementation

Uses
  uBodyPlan,
  {UsesStepsStart}
  uStep_1, uStep_2, uStep_3, uStep_4, uStep_5,
  {UsesStepsStop}

  {UsesSynapsesStart}

  uSynapse_11, uSynapse_10, uSynapse_9, uSynapse_8, uSynapse_7, uSynapse_6, uSynapse_5, uSynapse_4, uSynapse_3, uSynapse_2, uSynapse_1,
  {UsesSynapsesStop}

  {UsesDendritesStart}
  uDendrite_11, uDendrite_10, uDendrite_9, uDendrite_8, uDendrite_7, uDendrite_6, uDendrite_5, uDendrite_4, uDendrite_3,
  uDendrite_2, uDendrite_1,
  {UsesDendritesStop}

  {UsesSomesStart}
  uSoma_1, uSoma_2, uSoma_3, uSoma_4, uSoma_5, uSoma_6, uSoma_7, uSoma_8, uSoma_9, uSoma_10, uSoma_11,
  {UsesSomesStop}

  {UsesAxonsStart}
  uAxon_1, uAxon_2, uAxon_3, uAxon_4, uAxon_5, uAxon_6, uAxon_7, uAxon_8, uAxon_9, uAxon_10, uAxon_11,
  uAxon_12, uAxon_13, uAxon_14, uAxon_15, uAxon_16, uAxon_17, uAxon_18, uAxon_19, uAxon_20, uAxon_21,
  uAxon_22, uAxon_23, uAxon_24, uAxon_25, uAxon_26, uAxon_27, uAxon_28, uAxon_29, uAxon_30, uAxon_31,
  uAxon_32, uAxon_33, uAxon_34, uAxon_35, uAxon_36, uAxon_37, uAxon_38, uAxon_39, uAxon_40, uAxon_41,
  uAxon_42, uAxon_43, uAxon_44, uAxon_45, uAxon_46, uAxon_47, uAxon_48, uAxon_49, uAxon_50,
  {UsesAxonsStop}

  {UsesScopesStart}
  uScope_Blue, UScope_Black, uScope_Green, UScope_Red; // Terminal of the use clause;
{ UsesScopesStop }

const
  NumberOfSteps = 5;

  NumberOfSynapses = 11;
  NumberOfDendrites = 11;
  NumberOfSomas = 11;
  NumberOfAxons = 50;
  NumberOfScopes = 4;

  NumberOfForms = NumberOfSteps + NumberOfSynapses + NumberOfDendrites + NumberOfSomas + NumberOfAxons + NumberOfScopes;

  arrayOfClasses: array [0 .. NumberOfForms - 1] of TFormClass = (
    { FormStartSteps }
    TfrmStep_1, TfrmStep_2, TfrmStep_3, TfrmStep_4, TfrmStep_5,
    { FormStopSteps }
    //
    { FormStartSynapses }
    TfrmSynapse_11, TfrmSynapse_10, TfrmSynapse_9, TfrmSynapse_8, TfrmSynapse_7, TfrmSynapse_6, TfrmSynapse_5, TfrmSynapse_4, TfrmSynapse_3, TfrmSynapse_2,
    TfrmSynapse_1,
    { FormStop Synapses }
    //
    { FormStartDendrites }
    TfrmDendrite_11, TfrmDendrite_10, TfrmDendrite_9, TfrmDendrite_8, TfrmDendrite_7, TfrmDendrite_6, TfrmDendrite_5, TfrmDendrite_4, TfrmDendrite_3,
    TfrmDendrite_2, TfrmDendrite_1,
    { FormStopDendrites }
    //
    { FormStartSomas }
    TfrmSoma_11, TfrmSoma_10, TfrmSoma_9, TfrmSoma_8, TfrmSoma_7, TfrmSoma_6, TfrmSoma_5, TfrmSoma_4, TfrmSoma_3, TfrmSoma_2, TfrmSoma_1,
    { FormStopSomas }
    //
    { FormStartAxons }
    TfrmAxon_1, TfrmAxon_2, TfrmAxon_3, TfrmAxon_4, TfrmAxon_5, TfrmAxon_6, TfrmAxon_7, TfrmAxon_8, TfrmAxon_9, TfrmAxon_10, TfrmAxon_11, TfrmAxon_12,
    TfrmAxon_13, TfrmAxon_14, TfrmAxon_15, TfrmAxon_16, TfrmAxon_17, TfrmAxon_18, TfrmAxon_19, TfrmAxon_20, TfrmAxon_21, TfrmAxon_22, TfrmAxon_23, TfrmAxon_24,
    TfrmAxon_25, TfrmAxon_26, TfrmAxon_27, TfrmAxon_28, TfrmAxon_29, TfrmAxon_30, TfrmAxon_31, TfrmAxon_32, TfrmAxon_33, TfrmAxon_34, TfrmAxon_35, TfrmAxon_36,
    TfrmAxon_37, TfrmAxon_38, TfrmAxon_39, TfrmAxon_40, TfrmAxon_41, TfrmAxon_42, TfrmAxon_43, TfrmAxon_44, TfrmAxon_45, TfrmAxon_46, TfrmAxon_47, TfrmAxon_48,
    TfrmAxon_49, TfrmAxon_50,
    { FormStopAxons }
    //
    TfrmScope_Blue, TfrmScope_Black, TfrmScope_Green, TfrmScope_Red); // Terminal of the Array

function FormExists(AFormClass: TClass): TForm;
var
  i: integer;
begin
  Result := nil;
  for i := 0 to Application.ComponentCount - 1 do
    begin
      if Application.Components[i].ClassType = AFormClass then
        begin
          Result := TForm(Application.Components[i]);
          break;
        end;
    end;
end;

Function CreateForm(const FormName: string): TForm;
var
  FormClass: TFormClass;
  retForm: TForm;
  IconFormName: String;
begin

  FormClass := TFormClass(FindClass('Tfrm' + FormName));
  retForm := FormExists(FormClass);
  if retForm = nil then
    retForm := FormClass.Create(Application);

  IconFormName := retForm.name;
  Result := retForm;
end;

procedure FormsRegister;
var
  i: integer;
begin

  for i := 0 to NumberOfForms - 1 do
    RegisterClass(arrayOfClasses[i]);

end;

end.
