Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
Delphi 7 Enterprise
|
AW: Von C++ nach Delphi (Union + Struct)
19. Mai 2011, 09:12
Zweiter Vorschlag:
Delphi-Quellcode:
type
TBMRecContent = record
Recipient: Byte;
Reserved: Byte;
_Type: Byte;
Dir: Byte;
end;
TBMRec = record
data : Byte;
end;
_BM_REQUEST_TYPE = packed record
case Byte of
0 : (_BM: TBMRec);
1 : (B: Byte);
end;
:
implementation
:
function getBMRecContent(BM_REQUEST_TYPE:_BM_REQUEST_TYPE): TBMRecContent;
begin
Result.Recipient:= (BM_REQUEST_TYPE._BM.data shr 6) and 3;
Result.Reserved:= (BM_REQUEST_TYPE._BM.data shr 3) and 7;
Result._Type:= (BM_REQUEST_TYPE._BM.data shr 1) and 3;
Result.Dir:= (BM_REQUEST_TYPE._BM.data and 1);
end;
procedure TForm.ButtonClick(Sender: TObject);
var BM_REQUEST_TYPE: _BM_REQUEST_TYPE;
begin
BM_REQUEST_TYPE._BM.data:=3;
ShowMessage(Format(
'Recipient = %d, Reserved = %d, Type = %d, Dir = %d',
[getBMRecContent(BM_REQUEST_TYPE).Recipient,
getBMRecContent(BM_REQUEST_TYPE).Reserved,
getBMRecContent(BM_REQUEST_TYPE)._Type,
getBMRecContent(BM_REQUEST_TYPE).Dir]
));
end;
Geändert von omata (19. Mai 2011 um 09:43 Uhr)
|
|
Zitat
|