Top  Previous  Next

What is translated > Tokens > Ampersand

By means of an ampersand Delphi keywords can be used as identifiers, e.g. \Embarcadero\Studio\19.0\source\rtl\win\winrt\WinAPI.ShlObj.pas  line 11032:



  tagDROPDESCRIPTION = record 

    &type: TDropImageType;   


or \Embarcadero\Studio\19.0\source\rtl\win\winrt\WinAPI.CommCtrl.pas line 1429:


&type: UINT;



The Delphi2Cpp II pre-processor and parser can reckognize such tokens as identifiers, but the translation will result in type names that are forbidden in C++:


UINT &type;



There are four possibilities to handle such cases:


let the pre-processor substitute such expressions
let the translator substitute such expressions
modify the source code
make manual corrections afterwards



There is a case where the same identifiers are used with and without the ampersand.


    TState = (Start, &Property, ObjectStart, &Object, ArrayStart, &Array, ConstructorStart, &Constructor, Closed, Error);


and e.g.


    if FCurrentState = TState.Property then


then the identifier notations should be defined in the file for the identifiers in a unique way, e.g.:













Another example is in  \Embarcadero\Studio\19.0\source\rtl\win\winrt\WinAPI.DataRT.pas  line 598:



property &Implementation: Xml_Dom_IXmlDomImplementation read get_Implementation;



\rtl\win\winrt\WinAPI.Devices.pas line 6078:



property &Function: Word read get_Function;



\rtl\win\winrt\WinAPI.CommonTypes.pas line 138/439/544/6163...




Inside of the class TParallel in System.Threading there are a lot of overloaded "&For" functions.




This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content