Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

How to set custom TidGenerator from DataModeler

 Post Reply Post Reply
Author
Yannick Le Coat View Drop Down
New Member
New Member
Avatar

Joined: 13 Aug 2018
Posts: 4
Post Options Post Options   Quote Yannick Le Coat Quote  Post ReplyReply Direct Link To This Post Topic: How to set custom TidGenerator from DataModeler
    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

Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2485
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post 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

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;
Back to Top
Yannick Le Coat View Drop Down
New Member
New Member
Avatar

Joined: 13 Aug 2018
Posts: 4
Post Options Post Options   Quote Yannick Le Coat Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Yannick Le Coat View Drop Down
New Member
New Member
Avatar

Joined: 13 Aug 2018
Posts: 4
Post Options Post Options   Quote Yannick Le Coat Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2485
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 2018 at 12:49pm
Thanks for the correction, Yannick. Indeed, I believe it was the format post.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down