Einzelnen Beitrag anzeigen

Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.757 Beiträge
 
Delphi 10.4 Sydney
 
#4

Re: 4 Bytes als Float betrachten

  Alt 22. Mär 2007, 10:55
Noch auf einer japanischen WebSeite gefunde,

Delphi-Quellcode:
function SingleToHex(d: single) : String;
var i: Cardinal absolute d;
begin
  Result := IntToHex(i,8);
end;

function HexToSingle(h: String): Single;
var
i: Cardinal;
s: Single absolute i;
begin
  i := StrToIntDef(h, 0);
  Result := s;
end;
zu absolute:
Zitat:
You can create a new variable that resides at the same address as another variable. To do so, put the directive absolute after the type name in the declaration of the new variable, followed by the name of an existing (previously declared) variable. For example,

var

Str: string[32];
StrLen: Byte absolute Str;

specifies that the variable StrLen should start at the same address as Str. Since the first byte of a short string contains the string’s length, the value of StrLen is the length of Str.
You cannot initialize a variable in an absolute declaration or combine absolute with any other directives.
Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat