0

我无法访问其他表单上的函数/变量或组件。我创建了一个有两种形式的 dll。POSFORM 从主机应用程序调用。调用 dll 后,会显示 POSFORM。在 buttonclick 上创建 PAYFORM 并且也没有问题。PAYFORM buttonclick 应该访问 POSFORM 中的变量和标签。

那里的 AV 上升。

FPosForm->abc;
FPosForm->Label1->Caption = "test";

一切都编译得很好

POSFORM.CPP (first form)


#include <vcl.h>
#pragma hdrstop

#include "PosForm.h"
#include "payForm.h"
// ---------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

__fastcall TFPosForm::TFPosForm(TComponent* Owner) : TForm(Owner)
{

}

// ---------------------------
void __fastcall TFPosForm::Button1Click(TObject * Sender)
{


abc=999;
TFormPay *FormPay;
FormPay = new TFormPay(this);
FormPay->ShowModal();

}


POSFORM.H
// ---------------------------

#ifndef PosFormH
#define PosFormH
// ---------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>

// ---------------------------
class PACKAGE TFPosForm : public TForm
{
__published: // IDE-managed Components

TPanel *Panel1;
TButton *Button1;
TLabel *label1;

void __fastcall Button1Click(TObject *Sender);

private: // User declarations
public : // User declarations

int abc;

__fastcall TFPosForm(TComponent* Owner);
};

// ---------------------------
extern PACKAGE TFPosForm *FPosForm;
// ---------------------------
#endif







Second Form
Pay.cpp
// ---------------------------

#include <vcl.h>
#pragma hdrstop

#include "pay.h"
#include "PosForm.h"
// ---------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormPay *FormPay;

// ----------------------------
__fastcall TFormPay::TFormPay(TComponent* Owner) : TForm(Owner)
{
}

// ---------------------------

void __fastcall TFormPay::Button1Click(TObject *Sender)
{
FPosForm->abc = 1000;
FPosForm->Label1->Caption = "test";
}

Pay.h


#ifndef payH
#define payH
// ---------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>

// ---------------------------
class TFormPay : public TForm
{
__published: // IDE-managed Components
TButton *Buttton1;
void __fastcall Button1(TObject *Sender);

private: // User declarations
public : // User declarations

__fastcall TFormPay(TComponent* Owner);
};

// ---------------------------
extern PACKAGE TFormPay *FormPay;
// ---------------------------
#endif
4

1 回答 1

0

AV:模块 POSDLL.DLL 中地址 055A241E 的访问冲突 读取地址 0000059C 的数据

当我尝试更改标签文本时会发生这种情况

FPosForm->Label1->Text = "TEST"; 或者当我改变整数值 FPosForm->abc = 1000;

于 2018-02-02T11:31:24.183 回答