Delphi XE2 64bit:记录指针,无效的类型转换

时间:2011-10-22 22:30:10

标签: delphi 64-bit delphi-xe2

我如何将其重新编码为64位for Delphi XE2进行编译?

在第一个代码中,我得到的错误大小超过2gb。

在第二个,Invalid Typecast on:if int64(TMethod(FOnChangeOO [i1]))= int64(TMethod(changeEvent))然后

1)     TExtBool =(不,是,其他);

  TAByte          = array [0..maxInt      -1] of byte;
  TAShortInt      = array [0..maxInt      -1] of shortInt;
  TAChar          = array [0..maxInt div sizeOf(Char)-1] of Char;
  TAAnsiChar      = array [0..maxInt      -1] of AnsiChar;
  TAWideChar      = array [0..maxInt shr 1-1] of WideChar;
  TABoolean       = array [0..maxInt      -1] of boolean;
  TAExtBool       = array [0..maxInt      -1] of TExtBool;
  TAWord          = array [0..maxInt shr 1-1] of word;
  TASmallInt      = array [0..maxInt shr 1-1] of smallInt;
  TACardinal      = array [0..maxInt shr 2-1] of cardinal;
  TAInteger       = array [0..maxInt shr 2-1] of integer;
  TAPointer       = array [0..maxInt shr 2-1] of pointer;
  TAString        = array [0..maxInt shr 2-1] of string;
  TAAnsiString    = array [0..maxInt shr 2-1] of AnsiString;
  TAWideString    = array [0..maxInt shr 2-1] of WideString;
  TAUnicodeString = array [0..maxInt shr 2-1] of UnicodeString;
  TAIUnknown      = array [0..maxInt shr 2-1] of IUnknown;
  TAInt64         = array [0..maxInt shr 3-1] of int64;

2)

TMethod = record code, data: pointer; end;
  TIListChangeEventOO = procedure (const list: ICustomBasicList; const item: IBasic;
                                   beforeChange: boolean;
                                   changeType: TChangeType; oldIndex, index: integer) of object;
  ICustomBasicList = interface (IList) ['{EE6D35A0-5F85-11D3-A52D-00005A180D69}']
  TChangeType = (lctUnchanged, lctChanged, lctNew, lctDeleted);
 IBasic = interface ['{53F8CE42-2C8A-11D3-A52D-00005A180D69}']


procedure TICustomBasicList.RegisterChangeEvent(changeEvent: TIListChangeEventOO);
var i1 : integer;
begin
  FSection.Enter;
  try
    if CheckValid then begin
      for i1 := 0 to high(FOnChangeOO) do
        if int64(TMethod(FOnChangeOO[i1])) = int64(TMethod(changeEvent)) then
          exit;
      i1 := Length(FOnChangeOO);
      SetLength(FOnChangeOO, i1 + 1);
      FOnChangeOO[i1] := changeEvent;
    end;
  finally FSection.Leave end;
end;

function TICustomBasicList.UnregisterChangeEvent(changeEvent: TIListChangeEvent) : boolean;
var i1, i2 : integer;
begin
  result := false;
  FSection.Enter;
  try
    i2 := high(FOnChange);
    for i1 := i2 downto 0 do
      if @FOnChange[i1] = @changeEvent then begin
        FOnChange[i1] := FOnChange[i2];
        dec(i2);
        result := true;
        FSuccess := true;
      end;
    if result then SetLength(FOnChange, i2 + 1)
    else           SetLastError(ERROR_FILE_NOT_FOUND);
  finally FSection.Leave end;
end;

1 个答案:

答案 0 :(得分:12)

1)代替“shr 1/2/3”,你应该总是使用SizeOf(T)因为“shr 2 = div 4”不等于64位的“div SizeOf(Pointer)”。对于UnicodeString,WideString,IUnknown,......也是一样的。

2)TMethod是一个有两个指针的记录。在32位中,两个指针需要8个字节(32位* 2)。在64位中,两个指针需要16个字节(64位* 2)。并且Int64不能容纳128位。所以你现在必须直接比较这两个字段,而不是将其转换。

if (TMethod(FOnChangeOO[i1]).Data = TMethod(changeEvent).Data) and
   (TMethod(FOnChangeOO[i1]).Code = TMethod(changeEvent).Code) then