!!!!求解---C++Bulider 组件运行出错!!!!
这是一个动画组件,利用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));
}
}