Einzelnen Beitrag anzeigen

Benutzerbild von Deep-Sea
Deep-Sea

Registriert seit: 17. Jan 2007
907 Beiträge
 
Delphi XE2 Professional
 
#16

AW: Von C++ nach Delphi (Union + Struct)

  Alt 19. Mai 2011, 08:54
Hab es wieder korrigiert
Jap, so sollte es stimmen.

Wo ich schon dabei bin, hier mal kurz meine Version:
Delphi-Quellcode:
type
  TRequestType = record
    Recipient: Byte;
    Reserved: Byte;
    Typ: Byte;
    Dir: Boolean;
  end;

implementation

function DecodeRequestType(ARequestType: Byte): TRequestType;
begin
  With Result do
  begin
    Recipient := (ARequestType shr 6) and 3;
    Reserved := (ARequestType shr 3) and 7;
    Typ := (ARequestType shr 1) and 3;
    Dir := (ARequestType and 1) > 0;
  end;
end;

// Ggf. zusätzlich: function EncodeRequestType(ARequestType: TRequestType): Byte;

procedure TForm1.Button1Click(Sender: TObject);
var
  LRequestType: TRequestType;
begin
  LRequestType := DecodeRequestType( { Wert holen } );
  ShowMessageFmt('Recipient = %d, Reserved = %d, Type = %d, Dir = %d',
    [LRequestType.Recipient, LRequestType.Reserved, LRequestType.Typ, Ord(LRequestType .Dir)]);
end;
Chris
Die Erfahrung ist ein strenger Schulmeister: Sie prüft uns, bevor sie uns lehrt.
  Mit Zitat antworten Zitat