Painting simple ellips in C++ Builder. Exception raising.

Discussion in 'C++' started by hazamin, Mar 12, 2009.

  1. hazamin

    hazamin New Member

    Joined:
    Mar 10, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    hi. I am writing application on C++ Builder which draws ellipse on Canvas. i get run-time error: When canvas color is being changed compiler generates exception.
    So, i have created new unit (unit2) with Tellipse class declaration:

    Unit2.h:
    Code:
    #ifndef Unit2H
    #define Unit2H
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <ExtCtrls.hpp>
    
    class Tellipse
    {
      int x1,y1,x2,y2;
      TCanvas *canvic;
      TColor *col;
    
    public:
      Tellipse(TCanvas *canv, int px1, int py1, int px2, int py2,TColor pcol );
      ~Tellipse();
      void draw(bool visible);
      void move(int dx, int dy);
    
    } ;
    
    extern PACKAGE Tellipse *el;
    #endif
    
    Here is implementation (unit2.cpp):

    Code:
    #pragma hdrstop
    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    
    
    Tellipse::Tellipse(TCanvas *canv, int px1, int py1, int px2, int py2,TColor pcol) // initializing values in constructor
    {
      canvic=canv;
      x1=px1; x2=px2; y1=py1; y2=py2;
      canvic->Pen->Color=pcol;
    }
    
    Tellipse::~Tellipse()
    {}
    
    void Tellipse::draw(bool visible)                         // for drawing ellipse on canvas
    {
      if (visible) canvic->Pen->Color=*pcol ;           //here is all ok
                   else canvic->Pen->Color=clWhite;    // this line compiler allocates with blue color
      canvic->Brush->Color=clWhite; // if i delete line above compiler allocates this line and raises exception
      canvic->Ellipse(x1,y1,x2,y2);                         // if i delete two lines above compiler allocates this line and raises exception
     }
    
    
    void Tellipse::move(int dx, int dy)                      // doesn't matter. Changing coordinates move ellipse somewhere
    {
      draw(false);                       // stumbling block. 
      x1=x1+dx; x2=x2+dx;
      y1=y1+dy; y2=y2+dy;
      draw(true);                       // stumbling block. 
    }
    
    Telllipse::draw() is stumbling block.

    In main unit (unit1.cpp) On form paint i call void __fastcall TForm1::formpaint(TObject *Sender)
    Code:
    ....
    Tellipse *el;
    ....
    ....
    void __fastcall TForm1::formpaint(TObject *Sender)
    {
    Tellipse *el=new Tellipse(PaintBox1->Canvas,0,10,3,20, clBlack);
    PaintBox1->Canvas->Pen->Color=clWhite;
    PaintBox1->Canvas->Pen->Style=psDot;
    PaintBox1->Canvas->Brush->Color=clWhite;
    PaintBox1->Canvas->Rectangle(PaintBox1->ClientRect);
       el->draw(true);  // stumbling block. 
    }
    
    What causes may underlie this error? Thanks for attention
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    If the compiler itself generates an exception then I'd say that's a compiler bug. The compiler should throw an error if there's something wrong with the code, not crash.
    Are you sure you mean the compiler and not the editor?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice