【问题标题】:c++builder Cannot acces variable on other form (dll)c++builder无法访问其他形式的变量(dll)
【发布时间】:2018-02-02 11:05:51
【问题描述】:

我无法访问另一个表单上的函数/变量或组件。 我创建了一个有两种形式的 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

【问题讨论】:

  • 您能否显示一些输出来准确解释错误是什么?如果代码正常工作,您期望会发生什么?
  • 我建议您将其添加到您的问题本身中,而不是将其留在评论中。
  • 是的。 :)。我添加为答案

标签: dll access-violation c++builder-xe6


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2016-10-25
    • 2012-08-20
    • 2013-09-13
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    相关资源
    最近更新 更多