【问题标题】:Compile With Win32- Ok But With Win64- Compiler Error E2064使用 Win32 编译 - 好的,但使用 Win64 - 编译器错误 E2064
【发布时间】:2016-05-15 17:52:47
【问题描述】:

以下代码使用Win32编译,但使用Win64编译时会产生Delphi编译器错误E2064 left side cannot be assigned to。

type
  PRGB24 = ^TRGB24;

  TRGB24 = record
    B, G, R: Byte;
  end;

  PRGBArray = ^TRGBArray;
  TRGBArray = array [Word] of TRGB24;

procedure TFormCurves.ApplyCurve(Src: TIEBitmap);
var
  iRGBArray: PRGBArray;
  SFill, X, Y: Integer;
begin
  if not AImageLoaded then
    Exit;
  iRGBArray := PRGBArray(Src.Scanline[0]);
  SFill := Integer(Src.Scanline[1]) - Integer(iRGBArray);
  for Y := 0 to Src.Height - 1 do
  begin
    for X := 0 to Src.Width - 1 do
    begin
      iRGBArray[X].R := ALUT[0, ALUT[1, iRGBArray[X].R]];
      iRGBArray[X].G := ALUT[0, ALUT[2, iRGBArray[X].G]];
      iRGBArray[X].B := ALUT[0, ALUT[3, iRGBArray[X].B]];
    end;
    Inc(Integer(iRGBArray), SFill);//compiler error E2064 left side cannot be assigned to 
  end;
end;

procedure TFormCurves.GetHist;
var
  iRGBArray: PRGBArray;
  X, Y, SFill: Integer;
  iIEBitmap: TIEBitmap;
  iRGB: TRGB24;
  R, G, B, l: Byte;
begin
  if not AImageLoaded then
    Exit;
  for Y := 0 to 3 do
  begin
    AMaxHistory[Y] := 0;
    for X := 0 to 255 do
      AHistory[Y, X] := 0;
  end;
  iIEBitmap := imgView.IEBitmap;
  iRGBArray := PRGBArray(iIEBitmap.Scanline[0]);
  SFill := Integer(iIEBitmap.Scanline[1]) - Integer(iRGBArray);
  for Y := 0 to iIEBitmap.Height - 1 do
  begin
    for X := 0 to iIEBitmap.Width - 1 do
    begin
      iRGB := iRGBArray[X];
      R := iRGB.R;
      G := iRGB.G;
      B := iRGB.B;
      l := (R + G + B) div 3;
      AHistory[0, l] := AHistory[0, l] + 1;
      AHistory[1, R] := AHistory[1, R] + 1;
      AHistory[2, G] := AHistory[2, G] + 1;
      AHistory[3, B] := AHistory[3, B] + 1;
    end;
    Inc(Integer(iRGBArray), SFill); //compiler error E2064 left side cannot be assigned to 
  end;
  for Y := 0 to 3 do
    for X := 0 to 255 do
      if AHistory[Y, X] > AMaxHistory[Y] then
        AMaxHistory[Y] := AHistory[Y, X];
end;

如何消除 Win64 的编译器错误?

【问题讨论】:

    标签: delphi delphi-10-seattle


    【解决方案1】:

    在 Win64 上,指针是 64 位宽,Integer 是 32 位宽。这种强制转换要求赋值表达式的两边大小相同。因此错误。

    而不是转换为Integer 转换为PByte

     Inc(PByte(iRGBArray), SFill);    
    

    你所有的其他Integer 演员都是错误的。您必须掌握这些类型的不同大小。你可以投到NativeInt 来解决它们。

    【讨论】:

    • 修复了编译错误,但现在我在 Win64 和 PRGBArray(sDst)[X] := C; Win32 没有运行时错误。有任何想法吗?如有必要,我应该在另一个问题中发布程序吗?
    • 该代码不在问题范围内。你真的想要我对我看不到的代码的意见吗?
    • 好的..我会针对我的运行时问题发布问题
    猜你喜欢
    • 2011-10-04
    • 2013-07-09
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多