How to set custom TidGenerator from DataModeler

Hello,

I need to store some table ids as Varchar(32) and use the  as column attribute TIdGenerator.Uuid32 to generate such ID.

Si i need DataModeler to generated this king of column attribute
[Id('Fid_vehicule', TIdGenerator.Uuid32)]

But i did not find solution to do this. Is this something possible ?
I yes, how to ?

Thanks for your answer.

Regards

You can use Data Modeler customization script feature: http://www.tmssoftware.biz/business/dmodeler/doc/web/customization-script.html

Here is a small example that change ALL Id attributes to TIdGenerator.Uuid32. You can write additional logic to choose specific classes to have the id changed.


procedure OnClassGenerated(Args: TClassGeneratedArgs);
var
  Attr: TCodeAttributeDeclaration;
  I: Integer;
begin                       
  for I := 0 to Args.CodeType.CustomAttributes.Count - 1 do
  begin
    Attr := Args.CodeType.CustomAttributes;
    if Attr.Name = 'Id' then
    begin
      TCodeSnippetExpression(Attr.Arguments[1].Value).Value := 
        'TIdGenerator.Uuid32';
    end;
  end;      
end;

Hi

Thanka lot for your answer.
I suspected that customization scripts would permit to do this but did not find how to code it.
You make me save a lot of time.

Regards

There was a small error in sample code.

Here is the working code:

procedure OnClassGenerated(Args: TClassGeneratedArgs);
var
  Attr: TCodeAttributeDeclaration;
  i: Integer;
begin                      
  for I := 0 to Args.CodeType.CustomAttributes.Count - 1 do
  begin
    Attr := Args.CodeType.CustomAttributes[i];
    if Attr.Name = 'Id' then
    begin
      TCodeSnippetExpression(Attr.Arguments[1].Value).Value :=
        'TIdGenerator.Uuid32';
    end;
  end;     

end;

It seems that enabeling 'BBcodes to format post' removes the [i] from the original code

Thanks for the correction, Yannick. Indeed, I believe it was the format post.