![]() |
Delphi-Version: 10.4 Sydney
Inkompatible Handle-Typen erstellen
Hallo zusammen,
weiß jemand, ob man Handle-Typen erstellen kann, die *nicht* zuweisungskompatibel sind? Stichwort Typsicherheit. Es soll also nicht möglich sein, ein Wert vom Typ 1 einer Variablen vom Typ 2 zuzuweisen. Einfach so geht es schonmal nicht: type TSortHandle = THandle; TContextHandle = THandle; Und so leider auch nicht: type TSortHandle = type THandle; TContextHandle = type THandle; Mit Pointer, IntPtr und NativeInt das gleiche. |
AW: Inkompatible Handle-Typen erstellen
Delphi-Quellcode:
program Project1;
type TWindowHandle = record var handle: THandle; class operator Implicit(const handle: THandle): TWindowHandle; end; TProcessHandle = record var handle: THandle; class operator Implicit(const handle: THandle): TProcessHandle; end; class operator TWindowHandle.Implicit(const handle: THandle): TWindowHandle; begin Result.handle := handle; end; class operator TProcessHandle.Implicit(const handle: THandle): TProcessHandle; begin Result.handle := handle; end; var rawHandle: THandle; windowHandle: TWindowHandle; processHandle: TProcessHandle; begin rawHandle := 1234; windowHandle := rawHandle; processHandle := rawHandle; // windowHandle := processHandle; // E2010 Incompatible types end. |
AW: Inkompatible Handle-Typen erstellen
ja, so ging es.
Elegant ist anders, aber immerhin. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:09 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-2025 by Thomas Breitkreuz