Einzelnen Beitrag anzeigen

Benutzerbild von Stevie
Stevie
Online

Registriert seit: 12. Aug 2003
Ort: Soest
4.011 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#3

AW: Generic Integer zu Float konvertieren

  Alt 22. Dez 2017, 13:25
Delphi-Quellcode:
function TMyRec<T>.ToDouble: Double;
begin
  case GetTypeData(TypeInfo(t)).OrdType of
    otSByte: Result := PShortInt(@v)^;
    otUByte: Result := PByte(@v)^;
    otSWord: Result := PSmallInt(@v)^;
    otUWord: Result := PByte(@v)^;
    otSLong: Result := PInteger(@v)^;
    otULong: Result := PCardinal(@v)^;
  end;
end;
Edit: Das soll natürlich PWord sein bei otUWord
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight

Geändert von Stevie (22. Dez 2017 um 13:46 Uhr)
  Mit Zitat antworten Zitat