The following tables show how code rules are used to remove unsupported triggers and methods. Code rules are written using syntax similar to regular expressions. A code rule uses one or more special words to match code on the form.

The following special words are used as tags to find and replace expressions, to create variables, and to move code and properties:

The following special words are used as placeholders for variables:

The following examples illustrate how code rules work and can be written. The first examples show simple find and replace rules. The next examples build on the find and replace rule.

<find> and <replace>

Use the <find> and <replace> special words to find specific code and replace it. If you omit the <replace> instruction in the code transformation rule, then the found code is deleted but not replaced with any code.

Code transformation rule Code before transformation Code after transformation
  CopyCode imageCopy Code
<find>
x := y;
  CopyCode imageCopy Code
MESSAGE('Hello');
x := y;
MESSAGE('World');
  CopyCode imageCopy Code
MESSAGE('Hello');
MESSAGE('World');
  CopyCode imageCopy Code
<find>
x := y;
<replace>
y := z;
  CopyCode imageCopy Code
MESSAGE('Hello');
x := y;
MESSAGE('World');
  CopyCode imageCopy Code
MESSAGE('Hello');
y := z;
MESSAGE('World');
  CopyCode imageCopy Code
<find>
x := TRUE;
<replace>
;
<find>
y := x;
<replace>
x := TRUE;
<find>
y := x;
<replace>
x := FALSE;
  CopyCode imageCopy Code
MESSAGE('Hello');
y := x;
MESSAGE('World');
NoteNote

Rules are evaluated from top to bottom. Rules are run again if a match is found.

  CopyCode imageCopy Code
MESSAGE('Hello');
;
MESSAGE('World');

<atTrigger>

Use the <atTrigger> special word to specify that you want to find and replace code only if it is in the specified trigger.

Code transformation rule Code before transformation Code after transformation
  CopyCode imageCopy Code
<find>
x := y;
<atTrigger>
OnOpenForm
  CopyCode imageCopy Code
OnInit=BEGIN
  MESSAGE('Hello');
  x := y;
  MESSAGE('World');
END;

OnOpenForm=BEGIN
  MESSAGE('Hello');
  x := y;
  MESSAGE('World');
END;
  CopyCode imageCopy Code
OnInitPage=BEGIN
  MESSAGE('Hello');
  x := y;
  MESSAGE('World');
END;

OnOpenPage=BEGIN
  MESSAGE('Hello');
  MESSAGE('World');
END;

<comment>

Use the <comment> special word to add comments to the CodeRules.txt file. The comment is ignored in the code transformation.

Code transformation rule Code before transformation Code after transformation
  CopyCode imageCopy Code
<find>
x := z;
<comment>
Hello world
  CopyCode imageCopy Code
x := z;
MESSAGE('Hello World');
  CopyCode imageCopy Code
MESSAGE('Hello World');

!var! and !var<int>!

Use the !var! special word to specify a variable in the code. A !var! in a code rule matches any variable. You can specify different variables by appending an integer to !var!, such as !var1! or !var2!.

Code transformation rule Code before transformation Code after transformation
  CopyCode imageCopy Code
<find>
y := !var!
<replace>
y := TRUE;
  CopyCode imageCopy Code
MESSAGE('Hello');
y := x;
x := z;
MESSAGE('World');
  CopyCode imageCopy Code
MESSAGE('Hello');
y := TRUE;
x := z;
MESSAGE('World');
  CopyCode imageCopy Code
<find>
!var1! := !var2!
<replace>
!var2! := !var1!
  CopyCode imageCopy Code
MESSAGE('Hello');
y := x;
x := z;
MESSAGE('World;);
  CopyCode imageCopy Code
MESSAGE('Hello');
x := y;
z := x;
MESSAGE('World');

<declareVariable>, <declareVariableType>, and !declaredVariable!

Use the <declareVariable> special word to specify that the transformed code must declare a new variable. The expression after the <declareVariable> special word is the name of the new variable. Use the <declareVariableType> special word to specify the data type of the new variable that is declared. Use the !declaredVariable! special word to specify that you want to use the new variable that you declared.

Code transformation rule Code before transformation Code after transformation
  CopyCode imageCopy Code
<find>
!currForm!.!var1!.HEIGHT(!var2!)
<replace>
!currForm!.!var1!.HEIGHT := !var2!

<find>
CurrForm.!var1!.HEIGHT;
<declareVariable>
!var1!Height
<declareVariableType>
Integer
<replace>
!declaredVariable!;
  CopyCode imageCopy Code
OnRun=BEGIN
…
  MESSAGE('Hello');
  CurrForm.x.HEIGHT(NewHeight);
  MESSAGE('World');
END;
  CopyCode imageCopy Code
VAR
  xHeight : Integer;
OnRun=BEGIN
…
  MESSAGE('Hello');
  xHeight := NewHeight;
  MESSAGE('World');
END;

!currForm!

Use the !currForm! special word to specify either the CurrForm or CurrReport system-defined variable.

Code transformation rule Code before transformation Code after transformation
  CopyCode imageCopy Code
<find>
!currForm!.EDITABLE := TRUE
<replace>
;
  CopyCode imageCopy Code
MESSAGE('Hello')
CurrForm.EDITABLE := TRUE;
MESSAGE('World');
  CopyCode imageCopy Code
MESSAAGE('Hello');
;
MESSAGE('World');
  CopyCode imageCopy Code
<find>
!currForm!.EDITABLE := TRUE
<replace>
;
  CopyCode imageCopy Code
MESSAGE('Hello')
CurrReport.EDITABLE := TRUE;
MESSAGE('World');
  CopyCode imageCopy Code
MESSAAGE('Hello');
;
MESSAGE('World');

<moveToProperty>, <moveValueToProperty>, and <movePropertyToControlName>

Use the <moveToProperty> and the <moveValueToProperty> special words to move a value to the specified property. Use the <movePropertyToControlName> special word to move this property to the specified control.

Code transformation rule Code before transformation Code after transformation
  CopyCode imageCopy Code
<find>
Text := '';
<declareVariable>
!control!HideValue
<declareVariableType>
Boolean INDATASET
<replace>
!declaredVariable! := TRUE;
<atTrigger>
OnFormat
<moveToProperty>
HideValue
<moveValueToProperty>
!declaredVariable!
<movePropertyToControlName>
!control!
  CopyCode imageCopy Code
SourceExpr := x;
OnFormat=BEGIN
  MESSAGE('Hello');
  Text := '';
  MESSAGE('World');
END;
NoteNote

Assume that the preceding code is on a control. In this example, SourceExpr = x. The rule functions in the same way if the code is in a control with the Name property = x, or ID = x.

  CopyCode imageCopy Code
VAR
  xHideValue : Boolean INDATASET;
SourceExpr = x;
HideValue = xHideValue;
OnFormat=BEGIN
  MESSAGE('Hello');
  xHideValue := TRUE;
  MESSAGE('World');
END;

<moveCodeToTrigger> and <moveToTrigger>

Use the <moveCodeToTrigger> special word to specify the code that you want to move to a trigger. Use the <moveToTrigger> special word to specify the trigger to which you want to move the code.

Code transformation rule Code before transformation Code after transformation
  CopyCode imageCopy Code
<find>
y := x;
<atTrigger>
OnDeactivateForm
<replace>
;
<moveToTrigger>
OnCloseForm
<moveCodeToTrigger>
y := x;
  CopyCode imageCopy Code
OnDeactivateForm=BEGIN
  MESSAGE('Hello');
  y := x;
  MESSAGE('World');
END;
OnInit=BEGIN
  MESSAGE('Hello');
  y := x;
  MESSAGE('World');
END;
  CopyCode imageCopy Code
OnClosePage=BEGIN
  y := x;
END;
OnInit=BEGIN
  MESSAGE('Hello');
  y := x;
  MESSAGE('World');
END;