这是什么错误?

飞月梦想 2003-10-20 11:44:34
我在自己写的一个组件中设置了一个事件,把组件放入工程中编译运行没问题,但是在运行时激活该事件调用处理函数的时候出现错误对话框,内容是
Project Project1.exe raised exception class EAccessViolation with message'Access violation at address 401075B9 in module 'vcl60.bpl'.read of address 0000003F'........
我发现在事件处理函数中引用了其他控件就会出现这样的错误,比如
Label1->Caption=......;
请问这时什么原因造成的?先谢谢了!!
...全文
109 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdnxw 2003-10-24
  • 打赏
  • 举报
回复
可能:
1 访问了一个没有初始化的指针
2 访问了一个已经释放了对象的指针
3 ....看看上面大家的
show00 2003-10-24
  • 打赏
  • 举报
回复
是不是MyComponentl的问题哦???试试把你的MyComponentl放到其他工程能用不?
飞月梦想 2003-10-23
  • 打赏
  • 举报
回复
MyComponent1是自定义的组件,Count是其属性,组件是直接读取FCount变量取得属性值的,没什么问题吧。
pcclever 2003-10-23
  • 打赏
  • 举报
回复
MyComponent1->Count 是怎么把值返回的呢?
飞月梦想 2003-10-23
  • 打赏
  • 举报
回复
我的程序基本上都是从书上照搬的,怎么会这样?
whitelion 2003-10-22
  • 打赏
  • 举报
回复
我的意思是:
访问了没有分配内存的类,你试着一行一行的检查程序吧
飞月梦想 2003-10-21
  • 打赏
  • 举报
回复
不是类型问题,用与不用IntToStr函数结果都一样,所以在这里我没有用该函数进行类型转换。

出错的两行代码等号右边无论是什么都会出相同的错,可见问题是等号左边。可应该是没有问题啊。

还是继续请教!!!谢谢!!!
pcclever 2003-10-21
  • 打赏
  • 举报
回复
cp->Text=MyComponent1->Count; //类型不对
Label1->Caption=MyComponent1->Count; //同上

我知道在bcb5里用label1->Caption=IntToStr(...);

BCB6没用过,不知道有没有这个原因
飞月梦想 2003-10-21
  • 打赏
  • 举报
回复
MyComponent1是程序中添加的自定义组件的名称
jiangchun_xn 2003-10-21
  • 打赏
  • 举报
回复
MyComponent1在哪生成的
我不懂电脑 2003-10-21
  • 打赏
  • 举报
回复
是不是没有创建vcl控件或者访问越界
jiangchun_xn 2003-10-21
  • 打赏
  • 举报
回复
whitelion(chinaproject.51.net):

精彩,英语不错。:)
飞月梦想 2003-10-21
  • 打赏
  • 举报
回复
组件头文件代码:

#ifndef MyComponentH
#define MyComponentH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
//---------------------------------------------------------------------------
typedef void (__closure * TCountChangedEvent)(TObject * Sender,int value);
class PACKAGE TMyProperty : public TPersistent
{
private:
int FText;
int __fastcall GetMyProperty();
void __fastcall SetMyProperty(int value);
protected:
public:
__published:
__property int MyText={read=GetMyProperty,write=SetMyProperty};

};
class PACKAGE TMyComponent : public TWinControl
{
private:
int FCount;
int FArrayProperty[10];
int __fastcall GetArrayProperty(int index);
void __fastcall SetArrayProperty(int index, int value);
TMyProperty* MyProperty;
void __fastcall SetCount(int value);
TCountChangedEvent FCountChanged;
protected:
public:
__fastcall TMyComponent(TComponent* Owner);
__fastcall ~TMyComponent();
__published:
__property int Count={read=FCount,write=SetCount};
__property int ArrayProperty[int index]={read=GetArrayProperty,write=SetArrayProperty};
__property TMyProperty * MyInput={read=MyProperty,write=MyProperty};
__property TCountChangedEvent OnCountChanged={read=FCountChanged,write=FCountChanged,nodefault};
};
//---------------------------------------------------------------------------
#endif

组件实现文件代码:

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

#include <vcl.h>

#pragma hdrstop

#include "MyComponent.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TMyComponent *)
{
new TMyComponent(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMyComponent::TMyComponent(TComponent* Owner)
: TWinControl(Owner)
{
MyProperty=new TMyProperty;
}
//---------------------------------------------------------------------------
namespace Mycomponent
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMyComponent)};
RegisterComponents("Samples", classes, 0);
}
}
//---------------------------------------------------------------------------


int __fastcall TMyComponent::GetArrayProperty(int index)
{
if(index<=9&&index>=0)
return FArrayProperty[index];
else return -1;
}

void __fastcall TMyComponent::SetArrayProperty(int index, int value)
{
if(index<=9&&index>=0)
FArrayProperty[index]=value;
}

int __fastcall TMyProperty::GetMyProperty()
{
return FText;
}

void __fastcall TMyProperty::SetMyProperty(int value)
{
FText=value;
}

__fastcall TMyComponent::~TMyComponent()
{
delete MyProperty;
}

void __fastcall TMyComponent::SetCount(int value)
{
FCount=value;
if(FCountChanged!=NULL)
FCountChanged(this,value);
}

程序单元代码,change函数是以上事件的处理函数:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "MyComponent"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::changed(TObject *Sender,int value)
{
int a=1;
a=a+1;
cp->Text=MyComponent1->Count; //异常出现的代码位置
Label1->Caption=MyComponent1->Count; //异常出现的代码位置
}
//---------------------------------------------------------------------------

void __fastcall TForm1::WriteCount(TObject *Sender)
{
MyComponent1->Count=StrToInt(SetCount->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::InitLable(TObject *Sender)
{
Label1->Caption=IntToStr(MyComponent1->Count);
}

请高手指教!!!
niuzhenjun 2003-10-21
  • 打赏
  • 举报
回复
你这么问谁都没有办法回答,贴代码吧。
whitelion 2003-10-21
  • 打赏
  • 举报
回复
可能是内存读取错误
jiangchun_xn 2003-10-21
  • 打赏
  • 举报
回复
贴出代码看看。
飞月梦想 2003-10-21
  • 打赏
  • 举报
回复
哪位大侠知道?指导一下好吗?
什么是数据仓库呢?数据仓库是一个为数据分析而设计的企业级数据管理系统。数据仓库可集中、整合多个信息源的大量数据,借助数据仓库的分析能力,企业可从数据中获得宝贵的信息进而改进决策。同时,随着时间的推移,数据仓库中积累的大量历史数据对于数据科学家和业务分析师也是十分宝贵的。 数据仓库建模的意义是什么呢?如果把数据看作图书馆里的书,我们希望看到它们在书架上分门别类地放置;如果把数据看作城市的建筑,我们希望城市规划布局合理;如果把数据看作电脑文件和文件夹,我们希望按照自己的习惯有很好的文件夹组织方式,而不是糟糕混乱的桌面,经常为找一个文件而不知所措。数据模型就是数据组织和存储方法,它强调从业务、数据存取和使用角度合理存储数据。只有将数据有序的组织和存储起来之后,数据才能得到高性能、低成本、高效率、高质量的使用。 数据仓库建模的最终目的是什么呢?高性能:良好的数据模型能够帮助我们快速查询所需要的数据。低成本:良好的数据模型能减少重复计算,实现计算结果的复用,降低计算成本。高效率:良好的数据模型能极大的改善用户使用数据的体验,提高使用数据的效率。高质量:良好的数据模型能改善数据统计口径的混乱,减少计算错误的可能性。 本课程将基于理论和实践讲解数据仓库,包含基础知识:数据仓库建模方法论、数据仓库分层模型、数据仓库构建流程、事实表、维度表、指标体系、拉链表、维度模型等 ,基于真实电商业务作为实战,讲解电商数仓的整个构建过程,让大家在实战中理解和掌握数仓的理论知识。

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧