Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: 2 Arrays vergleichen\sortieren

  Alt 22. Nov 2017, 15:11
Die sogenannten class operatoren musst du für den jeweiligen Record-Typ selber implementieren.
Da wo als Kommentar //...usw. usf. steht, musst du selber die weiteren Kriterien definieren.

Delphi-Quellcode:
program Project3;

{$APPTYPE CONSOLE}

{$R *.res}


uses
  System.SysUtils,
  Winapi.Windows;

type
  TgObj = record
    ID: Integer;
    Handle: HWND;
    ObjType: Integer;
    UseSize: Integer;
    ARGB: COLORREF;
    Use3d: Short;
    Style: DWORD;
    X1: Integer;
    X2: Integer;
    Y1: Integer;
    Y2: Integer;
    Clone: Integer;
    Region: HRGN;
    metadata: array [0 .. 2047] of Byte;
    Metacount: Integer;
    Scale: Single;
    Framecount: Byte;
    Frametouse: Byte;

    class operator Equal(const A, B: TgObj): Boolean;
    class operator NotEqual(const A, B: TgObj): Boolean;
    class operator GreaterThan(const A, B: TgObj): Boolean;
    class operator LessThan(const A, B: TgObj): Boolean;
    class operator GreaterThanOrEqual(const A, B: TgObj): Boolean;
    class operator LessThanOrEqual(const A, B: TgObj): Boolean;
  end;

var
  A, B: TgObj;

  { TgObj }

class operator TgObj.Equal(const A, B: TgObj): Boolean;
begin
  Result := (A.ID = B.ID) and (A.Handle = B.Handle); // ...usw. usf.
end;

class operator TgObj.GreaterThan(const A, B: TgObj): Boolean;
begin
  Result := (A.ID > B.ID) and (A.Handle > B.Handle); // ...usw. usf.
end;

class operator TgObj.GreaterThanOrEqual(const A, B: TgObj): Boolean;
begin
  Result := (A.ID >= B.ID) and (A.Handle >= B.Handle); // ...usw. usf.
end;

class operator TgObj.LessThan(const A, B: TgObj): Boolean;
begin
  Result := (A.ID < B.ID) and (A.Handle < B.Handle); // ...usw. usf.
end;

class operator TgObj.LessThanOrEqual(const A, B: TgObj): Boolean;
begin
  Result := (A.ID <= B.ID) and (A.Handle <= B.Handle); // ...usw. usf.
end;

class operator TgObj.NotEqual(const A, B: TgObj): Boolean;
begin
  Result := (A.ID <> B.ID) and (A.Handle <> B.Handle); // ...usw. usf.
end;

begin
  try
    FillChar(A, SizeOf(A), 0);
    FillChar(B, SizeOf(B), 0);

    A.ID := $BEEF;
    B.ID := $DEAD;

    A.Handle := $C001;
    B.Handle := $BA55;

    Writeln('A < B: ', A < B);
    Writeln('A > B: ', A > B);
    Writeln('A = B: ', A = B);
    Writeln('A <> B: ', A <> B);

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;

end.

Geändert von TiGü (22. Nov 2017 um 15:14 Uhr)
  Mit Zitat antworten Zitat