![]() |
Verständnisfrage Deklaration
Hallo DP.
Wie ist so eine Deklaration zu verstehen?
Delphi-Quellcode:
:?:
// aus Types.pas
TRect = packed record case Integer of 0: (Left, Top, Right, Bottom: Longint); 1: (TopLeft, BottomRight: TPoint); end; Danke, gmc |
AW: Verständisfrage Deklaration
Sozusagen sind das folgende 2 Typen zusammengefasst:
Delphi-Quellcode:
Bei case of in einem Record wird jedoch der gleiche Speicherbereich verwendet.
TRect1 = packed record
Left, Top, Right, Bottom: Longint; end; TRect2 = packed record TopLeft, BottomRight: TPoint; end; Dh man hat sozusagen einen direkten Zugriff auf einen Cast der definierten Typen. Hier noch ein Beispielcode zum testen:
Delphi-Quellcode:
type
TRect = packed record case Integer of 0: (Left, Top, Right, Bottom: Longint); 1: (BottomRight, TopLeft: TPoint); end; var rct: TRect; begin rct.Left := 0; rct.Top := 1; rct.Right := 2; rct.Bottom := 3; ShowMessage( IntToStr(rct.TopLeft.X) + '/' + IntToStr(rct.TopLeft.Y) + sLineBreak + IntToStr(rct.BottomRight.X) + '/' + IntToStr(rct.BottomRight.Y) ); |
AW: Verständnisfrage Deklaration
Das nennt sich varianter Record (um mal einen Suchbegriff zu nennen).
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:52 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz