//Shapes.cpp
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Shapes.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(TSampleShape *)
{
    new TSampleShape(NULL);
}
//---------------------------------------------------------------------------
__fastcall TSampleShape::TSampleShape(TComponent* Owner)
    : TGraphicControl(Owner)
{
    Height=65;
    Width=65;
    FBrush=new TBrush();
    FBrush->OnChange=StyleChanged;
    FPen=new TPen();
    FPen->OnChange=StyleChanged;
}
//---------------------------------------------------------------------------
__fastcall TSampleShape::~TSampleShape()
{
    delete FBrush;
    delete FPen;
}
//------------------------------------------------------------------------
void __fastcall TSampleShape::Paint()
{
    int X,Y,W,H,S;
    Canvas->Pen=FPen;
    Canvas->Brush=FBrush;
    W=Width;
    H=Height;
    X=Y=0;
    if(W<H)
        S=W;
    else
        S=H;
    switch(FShape)
    {
        case sstRectangle:
        case sstSquare:
            Canvas->Rectangle(X,Y,X+W,Y+H);
            break;
        case sstRoundRect:
        case sstRoundSquare:
            Canvas->RoundRect(X,Y,X+W,Y+H,S/4,S/4);
            break;
        case sstCircle:
        case sstEllipse:
            Canvas->Ellipse(X,Y,X+W,Y+H);
            break;
        default:
            break;
    }
}
//------------------------------------------------------------------
namespace Shapes
{
    void __fastcall PACKAGE Register()
    {
         TComponentClass classes[1] = {__classid(TSampleShape)};
         RegisterComponents("Samples", classes, 0);
    }
}
//---------------------------------------------------------------------------
void __fastcall TSampleShape::SetShape(TSampleShapeType Value)
{
    if(FShape!=Value)
        FShape=Value;
    Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TSampleShape::SetPen(TPen* Value)
{
    FPen->Assign(Value);
}
//-----------------------------------------------------------------------
void __fastcall TSampleShape::SetBrush(TBrush* Value)
{
    FBrush->Assign(Value);
}
//-----------------------------------------------------------------------
void __fastcall TSampleShape::StyleChanged(TObject* Owner)
{
    Invalidate();
}
//-----------------------------------------------------------------------
//Shapes.h
//---------------------------------------------------------------------------#ifndef ShapesH
#define ShapesH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
enum TSampleShapeType {sstRectangle,sstSquare,sstRoundRect,sstRoundSquare,
    sstEllipse,sstCircle};class PACKAGE TSampleShape : public TGraphicControl
{
private:
    TSampleShapeType FShape;
    void __fastcall SetShape(TSampleShapeType Value);
    TPen *FPen;
    TBrush *FBrush;
    void __fastcall SetPen(TPen* Value);
    void __fastcall SetBrush(TBrush* Value);
protected:
    virtual void __fastcall Paint();
public:
    virtual __fastcall TSampleShape(TComponent* Owner);
    __fastcall ~TSampleShape();
    void __fastcall StyleChanged(TObject* Owner);
__published:
    __property DragCursor;
    __property DragMode;
    __property OnDragOver;
    __property OnDragDrop;
    __property OnEndDrag;
    __property OnMouseDown;
    __property OnMouseMove;
    __property OnMouseUp;
    __property TSampleShapeType Shape={read=FShape,write=SetShape,nodefault};
    __property Height;
    __property Width;
    __property TBrush* Brush={read=FBrush,write=SetBrush,nodefault};
    __property TPen* Pen={read=FPen,write=SetPen,nodefault};
};
//---------------------------------------------------------------------------
#endif

解决方案 »

  1.   

    现在我所有的自定义的组件安装上去以后,都会出现这个问题。那天我重装了一遍bcb后可以,但运行了几遍后,就又出现了这个问题。在别人的某台机上可以运行,可能是project options设定有问题,但我找不出来。你们贴到你们的机嚣试试看。在线等待。
      

  2.   

    我的代码没有问题,我试过继承一个新的组件,什么都不做只是继承,加入dcusr50.cpp中后,运行也出这样的错误。??????????????????????