Case sensitivity |
Top Previous Next |
What is translated > Tokens > Case sensitivity Delphi is not case-sensitive. This means that identifiers such as Name, name, and NAME are treated as the same identifier in Delphi. C++, on the other hand, is case-sensitive. In C++, Name, name, and NAME are considered distinct identifiers. This means that if Delphi code uses the same identifier in different case variations, it could lead to issues when translating to C++ because variations will refer to non-existing variables or methods. Care must be taken to ensure that all references to an identifier use consistent capitalization when converting from Delphi to C++.
In Delphi2Cpp, prior to version 2.5.0, this issue was addressed by unifying the case of all identifiers, regardless of their possible different declarations. However, as of version 2.5.0, this method is considered outdated. Now, all identifiers are written to match their respective declarations. To preserve backward compatibility, the old option is still available. It can be enabled via the checkbox 'Unify All Identifiers'.
For example in the following unit there are defined a constant, a property and a parameter with the names "name", "Name" and "NAME".
unit casesensitivity;
interface
const name: string = 'DefaultName';
type TPerson = class private FName: string; public property Name: string read FName write FName; procedure DisplayInfo(NAME: string); end;
implementation
procedure TPerson.DisplayInfo(Name: string); begin WriteLn('Parameter Name: ' + Name); WriteLn('Property Name: ' + Self.Name); WriteLn('Constant Name: ' + casesensitivity.Name); end;
end.
The three symbol all are used in the procedure DisplayInfo, This is possible, because they are declared in different scopes. Delphi2Cpp converts the procedure for C++Builder to:
void __fastcall TPerson::DisplayInfo(String NAME) { WriteLn(String(L"Parameter Name: ") + NAME); WriteLn(String(L"Property Name: ") + this->Name); WriteLn(String(L"Constant Name: ") + casesensitivity::name); }
For other compilers it gets converted to:
void TPerson::DisplayInfo(String NAME) { WriteLn(String(L"Parameter Name: ") + NAME); WriteLn(String(L"Property Name: ") + this->ReadPropertyName()); WriteLn(String(L"Constant Name: ") + casesensitivity::name); }
By use of the deprecated "unify all cases" option all symbols are given identical names and the procedure becomes to:
void __fastcall TPerson::DisplayInfo(String name) { WriteLn(String(L"Parameter Name: ") + name); WriteLn(String(L"Property Name: ") + this->name); WriteLn(String(L"Constant Name: ") + casesensitivity::name); }
The option to match the declaration names avoids problems that arise when different parts of the code are translated with different identifier lists
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |