Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Inkompatible Handle-Typen erstellen

  Alt 3. Jan 2022, 20:08
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.
  Mit Zitat antworten Zitat