AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Delphi-Equivalent zur C-union

Ein Thema von oXmoX · begonnen am 21. Jun 2005 · letzter Beitrag vom 22. Jun 2005
Antwort Antwort
NicoDE
(Gast)

n/a Beiträge
 
#1

Re: Delphi-Equivalent zur C-union

  Alt 21. Jun 2005, 18:59
Das lässt sich nur mit vielen Tricks übersetzen.
(wer auch immer unbenannte unions benutzt, gehört...)

Delphi-Quellcode:
(** Unnamed unions are evil stuff.

typedef struct CvMat
{
  int  type;
  int  step;
  int* refcount;
  union
  {
    uchar*  ptr;
    short*  s;
    int*    i;
    float*  fl;
    double* db;
  } data;
  union
  {
    int rows;
    int height;
  };
  union
  {
    int cols;
    int width;
  };
} CvMat;

**)


type
  CvMat = record
    type_ : Integer;
    step : Integer;
    (* for internal use only *)
    refcount : PInteger;
    data : record
      case Integer of
        0: (ptr : PByte);
        1: (s : PSmallInt);
        2: (i : PInteger);
        3: (fl : PSingle);
        4: (db : PDouble)
    end;
    case Integer of
      0: (rows : Integer);
      1: (height: Integer;
    case Integer of
      0: (cols : Integer);
      1: (width : Integer))
  end;

// unit testing

procedure TForm1.FormCreate(Sender: TObject);
  function FielsOffset(const Struct; const Field): string;
  begin
    Result := IntToHex(Cardinal(Addr(Field)) - Cardinal(Addr(Struct)), 8);
  end;
  var
    Foo: CvMat;
    Txt: string;
begin
  Txt :=
    'type_ ' + FielsOffset(Foo, Foo.type_ ) + #13#10 + // 00000000
    'step ' + FielsOffset(Foo, Foo.step ) + #13#10 + // 00000004
    'refcount ' + FielsOffset(Foo, Foo.refcount) + #13#10 + // 00000008
    'data ' + FielsOffset(Foo, Foo.data ) + #13#10 + // 0000000C
    ' ptr ' + FielsOffset(Foo, Foo.data.ptr) + #13#10 + // 0000000C
    ' s ' + FielsOffset(Foo, Foo.data.s ) + #13#10 + // 0000000C
    ' i ' + FielsOffset(Foo, Foo.data.i ) + #13#10 + // 0000000C
    ' fl ' + FielsOffset(Foo, Foo.data.fl ) + #13#10 + // 0000000C
    ' db ' + FielsOffset(Foo, Foo.data.db ) + #13#10 + // 0000000C
    'rows ' + FielsOffset(Foo, Foo.rows ) + #13#10 + // 00000010
    'height ' + FielsOffset(Foo, Foo.height ) + #13#10 + // 00000010
    'cols ' + FielsOffset(Foo, Foo.cols ) + #13#10 + // 00000014
    'width ' + FielsOffset(Foo, Foo.width ) + #13#10 + // 00000014
    '(SizeOf) ' + IntToHex(SizeOf(CvMat), 8); // 00000018
  ShowMessage(Txt);
end;
ps: keine Ursache, hab's gerade nochmal vereinfacht (der Rest war Routine )
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:44 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