【发布时间】: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