Delphi编译错误E2064左侧无法分配给 [英] Delphi compiler error E2064 left side cannot be assigned to

查看:1431
本文介绍了Delphi编译错误E2064左侧无法分配给的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个Delphi应用程序,我对对象pascal一无所知。

I inherited a Delphi application and I know nothing about object pascal.

这是一个BPL,我需要编译到新版本的C ++ Builder XE

当我运行make时,我得到错误:

It's a BPL that I need to compile into the new version of C++ Builder XE.
When I run a make I get the error:

E2064左侧无法分配给。

E2064 left side cannot be assigned to.

我学到了足够的obj pascal来知道我有一个常数,试图被赋予一个值。

I've learned enough obj pascal to know I have a constant that is trying to be assigned a value.

但是,显然你可以骑这个behanvior;通过进入Delphi编译器下的Build选项并打开可分配类型的常量,将常量转换为vars。

But, apparently, you can over ride this behanvior; essentially turning constants into vars by going into Build options under the Delphi compiler and turning on "Assignable Typed constants".

我做到了,我继续得到相同的错误。

I did that and I continue to get the same error.

我尝试用{$ J +}和{$ J-}​​围绕我的代码,但仍然无法编译。

I tried surrounding my code with {$J+} and {$J-} and still it will not compile.

procedure TChunkIDAT.CopyInterlacedRGB8(const Pass: Byte;
  Src, Dest, Trans{$IFDEF Store16bits}, Extra{$ENDIF}: pChar );
var
  Col: Integer;
 begin
 {Get first column and enter in loop}
 Col := ColumnStart[Pass];
 Dest := pChar(Longint(Dest) + Col * 3);
 repeat
 {Copy this row}

  Byte(Dest^) := fOwner.GammaTable[pByte(Longint(Src) + 2)^]; inc(Dest);

在最后一行获取错误。如果我将const更改为var,那么我会得到声明与之前的声明不同的错误,但是我不知道之前的声明是哪里....

Get the error on last line. If I change the const to a var, I then get the error that the declaration differs from the previous declaration but I have no idea where the previous declaration is....

推荐答案

你将一个两字节的东西( Char )键入一个字节的东西(字节)。 读取可以很容易地定义该值,但是使得该值可写是棘手的,可能是因为正式和实际的var参数的类型需要相同。

You're type-casting a two-byte thing (Char) into a one-byte thing (Byte). Reading that value is easy to define, but making that value writable is tricky, probably for the same reason the types of formal and actual "var" parameters need to be identical.

也许您想要将其转换为两个字节的东西,例如 Word 。或者也许你想要 GammaTable 是一个 Char 的数组,所以你根本不需要输入。或者也许,如果这个代码最初是在2009年之前为Delphi版本编写的,那么您希望 PChar 声明为$ code> PAnsiChar Dest 键入 PByte ,然后取消引用结果。这可能是一个坏主意,因为你只会覆盖缓冲区的每个其他字节。

Maybe you wanted to type-cast it to a two-byte thing, such as Word. Or maybe you want GammaTable to be an array of Char so you don't have to type-cast at all. Or maybe, if this code was originally written for a Delphi version earlier than 2009, you want those PChar declarations to be PAnsiChar — character types have gotten wider. Another option is to type-cast Dest to PByte, and then dereference the result. That's probably a bad idea, though, because you'll only be overwriting every other byte of the buffer.

根据函数的名称,它听起来像 PChar 从来不是正确的数据类型要使用。该类型是用于字符数据,但我认为这个代码是处理字节。正确的做法可能是将 PChar 更改为 PByte ,然后您不需要键入目标

Based on the name of the function, it sounds like PChar was never the right data type to use. That type is for character data, but I think this code is dealing with bytes. The correct thing to do is probably to change PChar to PByte, and then you don't need to type-cast Dest at all.

$ J 无关紧要它控制编译器是否允许您将值分配给类型的常量。您没有任何这些代码。

The $J directive is irrelevant; it controls whether the compiler will allow you to assign values to typed constants. You don't have any of those in this code.

这篇关于Delphi编译错误E2064左侧无法分配给的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆