나는 델파이에 전혀 경험이없고 델파이 2,3 버전에서 컴파일 할 수있는 아주 오래된 프로젝트가 있지만 델파이 4에서는 작동하지 않습니다. 문제는 최신 버전에서 다르게 작동하는 포인터에 관한 것입니다.
이러한 코드는 " Variable required " 오류를 발생시킵니다 .
pEnabled := @pClrWire_s^.enabled;
pEnabled := @Enabled;
pNEnabled := @pName_s^.Enabled;
여기서 pEnabled는 다음과 같습니다.
const
pEnabled : ^boolean = nil;
pClrWire_s 및 pName_s도 포인터입니다.
pClrWire_s : TpImage; {pointer to an image of colored wire}
pName_s : TpNamed; {pointer to the identifier}
TpImage 및 TpNamed에 대한 설명은 프로젝트의 다른 파일에서 찾을 수 있습니다.
type
TpImage = ^TImage;
TpNamed = ^TNamed;
TNamed = class(TLabel)
전체 코드를 심각하게 다시 작성하지 않고도이 문제를 해결할 수 있습니까? 그리고 Delphi 4에서 그러한 문제의 원인은 무엇입니까?
다음은 최신 Delphi로 테스트 한 완전한 솔루션입니다 (초기 Delphi 버전 번호와 비교하면 실제로는 Delphi 버전 26이지만 다른 이야기입니다).
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages,
System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
type
TpImage = ^TImage;
{$J+} // enable writable constant
const
pEnabled : ^boolean = nil;
var
pClrWire_s : TpImage;
type
TForm1 = class(TForm)
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
Dalija Prasnikar와 Gerry Coll이 각각의 주석에서 말했듯이, 핵심은 할당 가능한 유형 상수를 활성화하는 것입니다. 소스 코드에서 {$ J +}를 사용하거나 Project options / Building / Delphi compiler / Compiling / Syntax options / Asignable typed constant에있는 프로젝트 옵션을 사용하여 수행 할 수 있습니다.
그것이 당신을 위해 작동하는지 알려주십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다