From 9a9c6a3ff44a934166d4584a7126a69724628f87 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Sun, 3 Mar 2019 14:50:09 +0000 Subject: [PATCH] * fix for Mantis #35150: correctly convert Int64/QWord values to OleVariant (Delphi compatible) + added test git-svn-id: trunk@41571 - --- .gitattributes | 1 + packages/rtl-objpas/src/inc/variants.pp | 17 +++- tests/tbs/tb0655.pp | 115 ++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 tests/tbs/tb0655.pp diff --git a/.gitattributes b/.gitattributes index e7805b18d3..530ddf77d1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11797,6 +11797,7 @@ tests/tbs/tb0651.pp svneol=native#text/pascal tests/tbs/tb0652.pp svneol=native#text/pascal tests/tbs/tb0653.pp svneol=native#text/plain tests/tbs/tb0654.pp svneol=native#text/plain +tests/tbs/tb0655.pp svneol=native#text/pascal tests/tbs/tb205.pp svneol=native#text/plain tests/tbs/tb610.pp svneol=native#text/pascal tests/tbs/tb613.pp svneol=native#text/plain diff --git a/packages/rtl-objpas/src/inc/variants.pp b/packages/rtl-objpas/src/inc/variants.pp index 9f5f723c0d..a03ccc476a 100644 --- a/packages/rtl-objpas/src/inc/variants.pp +++ b/packages/rtl-objpas/src/inc/variants.pp @@ -2491,9 +2491,22 @@ end; procedure sysolevarfromint(var Dest : olevariant; const Source : Int64; const range : ShortInt); begin DoVarClearIfComplex(TVarData(Dest)); + { 64-bit values have their own types, all smaller ones are stored as signed 32-bit value } with TVarData(Dest) do begin - vInteger := Source; - vType := varInteger; + case range of + -8: begin + vInt64 := Int64(Source); + vType := varInt64; + end; + 8: begin + vQWord := QWord(Source); + vType := varQWord; + end; + else begin + vInteger := LongInt(Source); + vType := varInteger; + end; + end; end; end; diff --git a/tests/tbs/tb0655.pp b/tests/tbs/tb0655.pp new file mode 100644 index 0000000000..acfaa66c4d --- /dev/null +++ b/tests/tbs/tb0655.pp @@ -0,0 +1,115 @@ +program tb0655; + +uses + Variants; + +var + s8: Int8 = $12; + u8: UInt8 = $98; + s16: Int16 = $1234; + u16: UInt16 = $9876; + s32: Int32 = $12345768; + u32: UInt32 = $98765432; + s64: Int64 = $1234567812345678; + u64: UInt64 = UInt64($9876543298765432); + v: Variant; + ov: OleVariant; +begin + v := s8; + if VarType(v) <> varShortInt then + Halt(1); + if Int8(v) <> s8 then + Halt(2); + + v := u8; + if VarType(v) <> varByte then + Halt(3); + if UInt8(v) <> u8 then + Halt(4); + + v := s16; + if VarType(v) <> varSmallInt then + Halt(5); + if Int16(v) <> s16 then + Halt(6); + + v := u16; + if VarType(v) <> varWord then + Halt(7); + if UInt16(v) <> u16 then + Halt(8); + + v := s32; + if VarType(v) <> varInteger then + Halt(9); + if Int32(v) <> s32 then + Halt(10); + + v := u32; + if VarType(v) <> varLongWord then + Halt(11); + if UInt32(v) <> u32 then + Halt(12); + + v := s64; + if VarType(v) <> varInt64 then + Halt(13); + if Int64(v) <> s64 then + Halt(14); + + v := u64; + if VarType(v) <> varUInt64 then + Halt(15); + if UInt64(v) <> u64 then + Halt(16); + + { OleVariant has slightly different behaviour to Variant } + ov := s8; + if VarType(ov) <> varInteger then + Halt(17); + if Int8(ov) <> s8 then + Halt(18); + + ov := u8; + if VarType(ov) <> varInteger then + Halt(19); + if UInt8(ov) <> u8 then + Halt(20); + + ov := s16; + if VarType(ov) <> varInteger then + Halt(21); + if Int16(ov) <> s16 then + Halt(22); + + ov := u16; + if VarType(ov) <> varInteger then + Halt(23); + if UInt16(ov) <> u16 then + Halt(24); + + ov := s32; + if VarType(ov) <> varInteger then + Halt(25); + if Int32(ov) <> s32 then + Halt(26); + + ov := u32; + if VarType(ov) <> varInteger then + Halt(27); + { ! } + if UInt32(Int32(ov)) <> u32 then + Halt(28); + + ov := s64; + if VarType(ov) <> varInt64 then + Halt(29); + if Int64(ov) <> s64 then + Halt(30); + + ov := u64; + if VarType(ov) <> varUInt64 then + Halt(31); + if UInt64(ov) <> u64 then + Halt(32); +end.