!!!!求解---C++Bulider 组件运行出错!!!!

seawolf_57 2002-05-29 06:28:00
这是一个动画组件,利用Timer时间触发,轮流显示ImageList的图片,但运行是使用
EnableFlash(void)
StopFlash(void)
程序出错。请高手指正。
//FImage.h
//------------------------------------------------------------------------

#ifndef FImageH
#define FImageH
#define nil 0
//------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
//------------------------------------------------------------------------
class PACKAGE TFImage : public TGraphicControl
{
private:
int FFlashInterval;
bool FSelect;
int FBeginImage;
int FImageCount;
TTimer *FTimer;
Windows::TBitmap *FMaskBitmap;
Windows::TBitmap *FSourceBitmap;
TImageList *FImages;
void __fastcall SetImageList(TImageList *Value);
void __fastcall DoSelect(bool Value);
void __fastcall SetBeginImage(int Value);
void __fastcall SetFlashInterval(int Value);
protected:
void __fastcall FTimerTimer(TObject *Sender);
virtual void __fastcall paint(void);
public:
__fastcall TFImage(TComponent* Owner);
__fastcall ~TFImage(void);
void __fastcall EnableFlash(void);
void __fastcall StopFlash(void);
__published:
__property int FlashInterval = {read=FFlashInterval, write=SetFlashInterval, default=10};
__property TImageList *Images = {read=FImages, write=SetImageList};
__property bool Selected = {read=FSelect, write=DoSelect, default=False};
__property int BeginImage = {read=FBeginImage, write=SetBeginImage, default=0};

//Create
//Destory

__property Cursor;
__property Visible;
__property PopupMenu;
__property ShowHint;
__property ParentShowHint;
__property Hint;

__property OnMouseDown;
__property OnDblClick;
__property OnClick;
__property OnMouseMove;
__property OnMouseUp;

};
//------------------------------------------------------------------------
#endif

//FImage.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "FImage.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(TFImage *)
{
new TFImage(NULL);
}
//------------------------------------------------------------------------
__fastcall TFImage::TFImage(TComponent* Owner)
: TGraphicControl(Owner)
{
FSelect=false;
FBeginImage=0;
FFlashInterval=10;
Width=32;
Height=32;
TTimer *FTimer = new TTimer(this);
FTimer->Enabled=false;
FTimer->Interval=10;
FTimer->OnTimer=FTimerTimer;
FImageCount=0;
}
//------------------------------------------------------------------------
__fastcall TFImage::~TFImage(void)
{
FTimer->Enabled=false;
FTimer->Free();
}
//------------------------------------------------------------------------
namespace Fimage
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TFImage)};
RegisterComponents("Win32", classes, 0);
}
}
//------------------------------------------------------------------------
void __fastcall TFImage::SetImageList(TImageList *Value)
{
if (FImages!=Value)
{
FImages=Value;
if (Value!=nil)
Value->FreeNotification(this);
}
}
//------------------------------------------------------------------------
void __fastcall TFImage::DoSelect(bool Value)
{
FSelect=Value;
}
//------------------------------------------------------------------------
void __fastcall TFImage::SetBeginImage(int Value)
{
if (FImages!=nil)
{
if ((Value>0) && (Value<FImages->Count))
{
FImageCount=Value;
FBeginImage=Value;
}
else
{
FImageCount=Value;
FBeginImage=Value;
}
}
}
//------------------------------------------------------------------------
void __fastcall TFImage::SetFlashInterval(int Value)
{
FFlashInterval=Value;
}
//------------------------------------------------------------------------
void __fastcall TFImage::FTimerTimer(TObject *Sender)
{
if (FImages->Count>0)
{
FImageCount++;
if (FImageCount>=FImages->Count)
FImageCount=FBeginImage;
}
}
//------------------------------------------------------------------------
void __fastcall TFImage::EnableFlash(void)
{
FTimer->Enabled=true;
FTimer->Interval=FFlashInterval;
}
//------------------------------------------------------------------------
void __fastcall TFImage::StopFlash(void)
{
FTimer->Enabled=False;
FImageCount=FBeginImage;
}
//------------------------------------------------------------------------
void __fastcall TFImage::paint(void)
{
if (FImages!=nil)
{
Width=FImages->Width;
Height=FImages->Height;
if (FSelect)
{
FImages->DrawingStyle=dsFocus;
FImages->Draw(Canvas,0,0,FImageCount,true);
}
else
{
FImages->DrawingStyle=dsTransparent;
FImages->Draw(Canvas,0,0,FImageCount,true);
}
}
if (ComponentState.Contains(csDesigning) )
{
Canvas->Brush->Color=clBlack;
Canvas->FrameRect(Rect(0,0,Width,Height));
}
}
...全文
43 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
我不懂电脑 2002-05-29
  • 打赏
  • 举报
回复
同意RedProgramer(RedSteel)
你的FTimer是TFImage的私有成员,但在构造函数里,又新建了一个timer
seawolf_57 2002-05-29
  • 打赏
  • 举报
回复
TO:RedProgramer(RedSteel)
程序中为什么会出现这样的问题
你能将的详细一些吗?
FTimer改成TFImage的成员应怎样修改,我以前用Delphi对C++Bulider不太熟悉。
谢谢!!!
RedProgramer 2002-05-29
  • 打赏
  • 举报
回复
__fastcall TFImage::TFImage(TComponent* Owner)
: TGraphicControl(Owner)
{
FSelect=false;
FBeginImage=0;
FFlashInterval=10;
Width=32;
Height=32;
TTimer *FTimer = new TTimer(this);
FTimer->Enabled=false;
FTimer->Interval=10;
FTimer->OnTimer=FTimerTimer;
FImageCount=0;
}
中把TTimer *FTimer= new TTimer(this);
改为
FTimer= new TTimer(this);
就可以了

RedProgramer 2002-05-29
  • 打赏
  • 举报
回复
你的FTimer是局部变量,不出错才怪,改成TFImage的成员就可以了

13,825

社区成员

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

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