Creating constructors with paramenters

Hello, is it possible to use scripting to create the second constructor with parameters?Something like this:


procedure OnClassGenerated(Args: TClassGeneratedArgs);
var
  Proc: TCodeMemberMethod;    
begin
  case Args.CodeType.Name of
    'TAcc': begin  
      Proc := Args.CodeType.AddConstructor('CreateUser', mvPublic);
      Proc.AddParameter('Name', 'string').Modifier := pmConst;  
      Proc.AddSnippet('Result := inherited;');
      Proc.AddSnippet('Result.Name := Name');
    end; 
  end;
end;

to get this second constructor:


constructor TAcc.CreateUser(const Name: string);
begin
  Result := inherited;
  Result.Name := Name
end;

Yes, you can use something like this:




procedure OnClassGenerated(Args: TClassGeneratedArgs);     
var                                         
  Proc: TCodeMemberConstructor;        
begin                                   
  case Args.CodeType.Name of
    'TCategories':
      begin
        Proc := TCodeMemberConstructor.Create;
        Args.CodeType.Members.Add(Proc);             
        Proc.Name := 'Create';
        Proc.Directives := SetOf([mdOverload]);
        Proc.Visibility := mvPublic;
        Proc.AddParameter('Name', 'string').Modifier := pmConst;  
        Proc.AddSnippet('inherited Create;');
        Proc.AddSnippet('Self.Name := Name;');
      end;
  end;                                                   
end;

Thank you very much. How I can add "overload" for the standard constructor in this situation?

Now I'm use this method to add "overload" for the standard constructor, may be it is not optimal?


procedure OnClassGenerated(Args: TClassGeneratedArgs);
var       
  I: Integer;
  Member: TCodeTypeMember;
  Proc1, Proc2: TCodeMemberConstructor;        
begin                                   
  case Args.CodeType.Name of
    'TAcc': 
      begin 
        for I := 0 to Args.CodeType.Members.Count - 1 do begin
          Member := Args.CodeType.Members[ I ];
          if Member.Name = 'Create' then begin 
            Proc1 := Member;
            Proc1.Directives := Proc1.Directives + SetOf([mdOverload]);
            Break;
          end;
        end;  
        
        Proc2 := TCodeMemberConstructor.Create;
        Args.CodeType.Members.Add(Proc2);             
        Proc2.Name := 'Create';
        Proc2.Directives := SetOf([mdOverload]);
        Proc2.Visibility := mvPublic;
        Proc2.AddParameter('Name', 'string').Modifier := pmConst;  
        Proc2.AddSnippet('Create;');
        Proc2.AddSnippet('Self.Name := Name;');
      end;       
  end;            
end;

It's a good approach.