Ver código fonte

Support implicit conversion between Integer64 and Int64.

This allows the two types to be used interchangeably in assignment
statements and function parameters.

I don't intend to implement more operators (e.g., addition or comparison)
because the ultimate goal is to replace Integer64 usage with Int64 (or
UInt64 in certain cases). This just allows the migration to be done more
incrementally.
Jordan Russell 2 meses atrás
pai
commit
0793e717af

+ 1 - 1
Projects/Src/Setup.InstFunc.pas

@@ -982,7 +982,7 @@ begin
   try
     if Assigned(@GetDiskFreeSpaceExFunc) then begin
       Result := GetDiskFreeSpaceExFunc(PChar(AddBackslash(PathExpand(DriveRoot))),
-        @TLargeInteger(FreeBytes), @TLargeInteger(TotalBytes), nil);
+        @TLargeInteger(Int64Rec(FreeBytes)), @TLargeInteger(Int64Rec(TotalBytes)), nil);
     end
     else begin
       Result := GetDiskFreeSpace(PChar(AddBackslash(PathExtractDrive(PathExpand(DriveRoot)))),

+ 1 - 1
Projects/Src/Setup.Install.pas

@@ -2749,7 +2749,7 @@ var
                           if not StrToInteger64(ExpandConst(ValueData), QV) then
                             InternalError('Failed to parse "qword" value');
                           ErrorCode := RegSetValueEx(K, PChar(N), 0, REG_QWORD,
-                            @TLargeInteger(QV), SizeOf(TLargeInteger(QV)));
+                            @QV, SizeOf(QV));
                           if (ErrorCode <> ERROR_SUCCESS) and
                              not(roNoError in Options) then
                             RegError(reRegSetValueEx, RK, S, ErrorCode);

+ 15 - 2
Projects/Src/Shared.Int64Em.pas

@@ -17,6 +17,8 @@ interface
 type
   Integer64 = record
     Lo, Hi: LongWord;
+    class operator Implicit(const A: Integer64): Int64;
+    class operator Implicit(const A: Int64): Integer64;
   end;
 
 function Compare64(const N1, N2: Integer64): Integer;
@@ -289,8 +291,19 @@ end;
 
 function To64(const Lo: Longword): Integer64;
 begin
-  Result.Lo  := Lo;
-  Result.Hi := 0;
+  Result := Lo;
+end;
+
+{ Integer64 }
+
+class operator Integer64.Implicit(const A: Int64): Integer64;
+begin
+  Int64Rec(Result) := Int64Rec(A);
+end;
+
+class operator Integer64.Implicit(const A: Integer64): Int64;
+begin
+  Int64Rec(Result) := Int64Rec(A);
 end;
 
 end.