Options

Understanding Code Rules - Form Transformation

dayscottdayscott Member Posts: 42
edited 2009-10-13 in NAV Three Tier
code rules are very important for proper form transformation - they are not trivial though: http://msdn.microsoft.com/en-us/library/dd338843.aspx

1. question:
6u306e8e7tmo6gqbip6l.png
why is there "hello world" in the last line of the first box? it does not do anything.

2. question
ycd0zbc7q2qbjrmfgze.png

I don't get the content of the first box at ALL.
<find>
CurrForm.!var1!.HEIGHT := TRUE;
<declareVariable>
!var1!Height
<declareVariableType>
Integer
<replace>
!declaredVariable! := TRUE;

what does !var1! do?

what does <declareVariableType>
Integer
do ?
The replaced variable is not even Integer here... thats really weird :?

Comments

  • Options
    jillfrankjillfrank Member, Microsoft Employee Posts: 9
    1. Hello World in the first column is a comment in the CodeRules.txt file. You add comments to the CodeRules.txt file by using the <comment> special word and then writing your comment. Comments in the CodeRules.txt file are ignored when transforming code.
    The example given is a little confusing because it also has a comment in columns 2 and 3 of the table, but these are unrelated to the <comment> in column 1.

    2. !var! (or !var1! or !var2!, etc.) lets you specify a variable in a code rule. The <declareVariable> special word specifies that the transformed code must declare a variable. <declareVariableType> specifies the data type for this new variable. You use !declaredVariable! in the code rule where you want the transformed code to use the new variable that was declared.

    The example given is confusing because as you mention, is assigns a Boolean value to an Integer. A better example would be this one, from the actual CodeRules.txt file:
    <find>
    !currForm!.!var1!.HEIGHT(!var2!)
    <replace>
    !currForm!.!var1!.HEIGHT := !var2!
    
    <find>
    CurrForm.!var1!.HEIGHT;
    <declareVariable>
    !var1!Height
    <declareVariableType>
    Integer
    <replace>
    !declaredVariable!;
    

    Then if you have code like this:
    OnRun=BEGIN
    …
      MESSAGE('Hello');
      CurrForm.x.HEIGHT(NewHeight);
      MESSAGE('World');
    END;
    

    It would be transformed to this:
    VAR
      xHeight : Integer;
    OnRun=BEGIN
    …
      MESSAGE('Hello');
      xHeight := NewHeight;
      MESSAGE('World');
    END;
    

    Hope that helps.
    I have updated the Code Rules topic to try to make it clearer. The updated version will be available on MSDN (http://msdn.microsoft.com/en-us/library/dd338843.aspx) in a few months when we next update the Developer and IT Pro Help.
    Jill Frank
    Senior Technical Writer
    Microsoft Dynamics NAV
  • Options
    dayscottdayscott Member Posts: 42
    first of all: Thanks for your answer, I appreciate it a lot that a MBS man is answering here.

    @1.
    jillfrank wrote:
    1. Hello World in the first column is a comment in the CodeRules.txt file. You add comments to the CodeRules.txt file by using the <comment> special word and then writing your comment. Comments in the CodeRules.txt file are ignored when transforming code.
    The example given is a little confusing because it also has a comment in columns 2 and 3 of the table, but these are unrelated to the <comment> in column 1.

    You say the "//comment" in column two is not needed, but isn't this a integral part of the "code rule" itself. How can this be unrelated?
    The "Hello World" in the last line of the first column freaks me out, what does it do?

    Please don't wait for uploading the MBS in a few months... the partners and ISVs need this now.
  • Options
    jillfrankjillfrank Member, Microsoft Employee Posts: 9
    first of all: Thanks for your answer
    No problem. :-)

    <comment> in the first column specifies that the next line(s) of the CodeRules.txt file are comments. These lines don't map to anything in the code on the form. They are ignored by the transformation tool.
    You could have something like this in the CodeRules.txt file:
    <find>
    x := z;
    <comment>
    This is a comment.
    I can write notes here about what this rule does.
    Until the transformation tool finds the next special word, all of these lines are parsed as comments. 
    <replace>
    ;
    
    The <comment> line and the next three lines are ignored. When the transformation tool gets to the <replace> line, it recognizes the <replace> special word and knows that the comments have ended.

    The above is exactly the same rule as
    <find>
    x := z;
    <replace>
    ;
    

    In the example from your original post:
    <find>
    x := z;
    <comment>
    Hello world
    
    The Hello world line does nothing.
    Also, since there is no <replace> in that example, the found line is deleted.

    Make sense?
    Jill Frank
    Senior Technical Writer
    Microsoft Dynamics NAV
Sign In or Register to comment.