Print Page | Close Window

How to set custom TidGenerator from DataModeler

Printed From: TMS Software
Category: Business Tools
Forum Name: Data Modeler
Forum Discription:
URL: http://www.tmssoftware.com/site/forum/forum_posts.asp?TID=11375
Printed Date: 18 Sep 2019 at 5:49pm


Topic: How to set custom TidGenerator from DataModeler
Posted By: Yannick Le Coat
Subject: How to set custom TidGenerator from DataModeler
Date Posted: 11 Sep 2018 at 3:53pm
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




Replies:
Posted By: Wagner R. Landgraf
Date Posted: 11 Sep 2018 at 8:54pm
You can use Data Modeler customization script feature: http://www.tmssoftware.biz/business/dmodeler/doc/web/customization-script.html - 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;


Posted By: Yannick Le Coat
Date Posted: 12 Sep 2018 at 11:42am
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


Posted By: Yannick Le Coat
Date Posted: 12 Sep 2018 at 12:26pm
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


Posted By: Wagner R. Landgraf
Date Posted: 12 Sep 2018 at 12:49pm
Thanks for the correction, Yannick. Indeed, I believe it was the format post.



Print Page | Close Window