如何更正此运行时错误以及为什么我在 Delphi 中得到它?

How to correct this runtime error and why do i get it in Delphi?

我正在尝试调用 Delphi 中的远程 API 函数:

procedure TForm4.Button1Click(Sender: TObject);
var
  getBalance1 : getBalance;
  type1 : consenttype;
begin
  getBalance1.consent.type_ := type1;
  getBalance1.consent.target := Edit5.Text;
  getBalance1.consent.id := Edit6.Text;
    
  Application.ProcessMessages;
  valasz := (HTTPRio1 as AccountInfo_PT).getBalance(getBalance1);
end;

但是在运行时,我得到这个错误:

Access violation at address 00791D72 in module generate_xml_exe. Write of address 0000000C.

这是什么,我该如何更正它?我在运行时单击按钮时出现此错误。

getBalancegetBalance_Type 的 class:

  getBalance_Type = class(TRemotable)
  private
    Fconsent: consent5;
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property consent: consent5  Index (IS_UNQL) read Fconsent write Fconsent;
  end;
    
  // ************************************************************************ //
  // XML       : getBalance, global, <element>
  // Namespace : http://bbrt.hu/openApiServices/AccountInfo/1/
  // Info      : Wrapper
  // ************************************************************************ //
  getBalance = class(getBalance_Type)
  private
  published
  end;

  consent5 = class(TRemotable)
  private
    Ftype_: consentType;
    Ftarget: targetType;
    Fid: consentIdType;
  published
    property type_:  consentType    Index (IS_UNQL) read Ftype_ write Ftype_;
    property target: targetType     Index (IS_UNQL) read Ftarget write Ftarget;
    property id:     consentIdType  Index (IS_UNQL) read Fid write Fid;
  end;

这些行导致运行时错误:

getBalance1.consent.type_ := type1;
getBalance1.consent.target := Edit5.Text;
getBalance1.consent.id := Edit6.Text;

但我不知道如何更正。

您的访问冲突的直接原因是未创建类型为 getBalancegetBalance1

Delphi 中的所有 类 都需要创建,通常通过名为 Create 的 CONSTRUCTOR。由于您没有隐式创建 getBalance1 变量,它包含一个随机值,您无法(安全地)访问其内容。

因此,在开始使用 getBalance1 变量之前,您需要创建它,如:

getBalance1 := getBalance.Create;