Seit Delphi 7 wurden die Fähigkeite von Record's erweitert zu mehr klassenähnlichen Strukturen mit Properties, Methoden und verschachtelten Typen. Zum Beispiel:
type TMyRecord = record type TInnerColorType = Integer; var Red: Integer; class var Blue: Integer; procedure printRed(); constructor Create(val: Integer); property RedProperty: TInnerColorType read Red write Red; class property BlueProp: TInnerColorType read Blue write Blue; end;
implementation
constructor TMyRecord.Create(val: Integer); begin Red := val; end;
procedure TMyRecord.printRed; begin Writeln('Red: ', Red); end;
Für den C++Builder konvertiert DelphiXE2Cpp11 dies zu:
struct TMyRecord { typedef int TInnerColorType; int Red; static int Blue; void __fastcall printRed(); __fastcall TMyRecord(int val); __property TInnerColorType RedProperty = { read = Red, write = Red }; /*static */__property TInnerColorType BlueProp = { read = Blue, write = Blue };
TMyRecord() {}
};
---------------
int TMyRecord::Blue = 0;
__fastcall TMyRecord::TMyRecord(int val)
: Red(val)
{
}
void __fastcall TMyRecord::printRed() { { Write(L"Red: "); WriteLn(Red); }; }
Für andere Compiler als dem C++Builder wird der Code folgendermaßen übersetzt:
struct TMyRecord { typedef int TInnerColorType; int Red; static int Blue; void printRed(); TMyRecord(int val); /*property RedProperty : TInnerColorType read Red write Red;*/ TInnerColorType ReadPropertyRedProperty() { return Red;} void WritePropertyRedProperty(int Value){Red = Value;} /*property BlueProp : TInnerColorType read Blue write Blue;*/ static TInnerColorType ReadPropertyBlueProp() { return Blue;} static void WritePropertyBlueProp(int Value){Blue = Value;} void InitMembers(){Red = 0;}
TMyRecord() {InitMembers();}
};
---------------------
int TMyRecord::Blue = 0;
TMyRecord::TMyRecord(int val)
: Red(val)
{
}
void TMyRecord::printRed()
{
{ Write(L"Red: "); WriteLn(Red); };
}