为组件的位图属性分配值时发生访问冲突 [英] Access violation when assigning a value to my component Bitmap property

查看:139
本文介绍了为组件的位图属性分配值时发生访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个必须使用位图的组件,在选择属性上的图像时遇到了问题。

I'm trying to create a component that must use a Bitmap, I'm having a problem when I go to select the image on the property.

这里是代码摘录:
属性声明

Here is an excerpt of the code: Property Declaration

Property StarOff: TBitmap read FStarOff write SetStarOff;

函数SetStarOff

Function SetStarOff

procedure TNotas.SetStarOff(const Value: TBitmap);
begin
FStarOff.Assign(Value);
end;

但是,当我为属性分配值时,出现错误:

But, when I assign a value to the property, I get the error:


模块'TNte.bpl'中地址1BC324B8的访问冲突。读取地址000000000

Access violation at address 1BC324B8 in module 'TNte.bpl'. Read of address 000000000

为什么会这样?

推荐答案

您的setter方法看起来正确,但是由于您的FStarOff成员目前为零,因此您遇到访问冲突。

Your setter method looks correct, but you're getting an Access Violation because your FStarOff member is nil at the moment.

通常是

constructor TMyComponent.Create(AOwner: TComponent);
begin
  inherited;
  FStarOff := TBitmap.Create;
end;

destructor TMyComponent.Destroy;
begin
  FStarOff.Free;
  inherited;
end;

这篇关于为组件的位图属性分配值时发生访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆