Page 1 of 1

"Error reading Tchart->OnAfterDraw" Exception

Posted: Thu Nov 20, 2008 1:18 pm
by 8574101
When I run the following codes ,"Error reading Tchart->OnAfterDraw" application Exception is showed.

Run the application ,
add points to chart by "btnAddPointClick(TObject *Sender) ",
push the "Save para" button to save the .tee file(btnSaveparaClick),
the "OK" what were canvased disappeared.

Then close the application ,open it again, the application Exception is showed.


Unit.h

Code: Select all

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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "ImaPoint.hpp"
#include <Chart.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <Series.hpp>
#include <TeEngine.hpp>
#include <TeeProcs.hpp>
#include "TeeTools.hpp"
#include "TeeEdit.hpp"

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
    TChart *Chart1;
    TButton *btnSavepara;
    TChartEditor *ChartEditor1;
    TButton *btnLoadPara;
    TButton *btnEditchart;
    TButton *btnAddPoint;
    TFastLineSeries *Series2;
    TFastLineSeries *Series1;
    void __fastcall btnSaveparaClick(TObject *Sender);
    void __fastcall btnEditchartClick(TObject *Sender);
    void __fastcall btnAddPointClick(TObject *Sender);
    void __fastcall btnLoadParaClick(TObject *Sender);
    void __fastcall Chart1AfterDraw(TObject *Sender);
private:	// User declarations
    bool bDrawText;
public:		// User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit.cpp

Code: Select all

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "TeeStore.hpp"
#include "EditChar.hpp"
#include "TeeEditPRO.hpp"
#pragma link "TeeEditPRO"


//---------------------------------------------------------------------------
#pragma package(smart_init)

#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
   Chart1->BottomAxis->SetMinMax(1,100); 
   Chart1->LeftAxis->SetMinMax(1,100); 

   Chart1->BottomAxis->Logarithmic=true;
   Chart1->LeftAxis->Logarithmic=true;

   bDrawText = false;

   if(FileExists("d:\\a.tee"))
   {
      LoadChartFromFile(Chart1,"d:\\a.tee");
   }

}

//Load Tchart Parameters
void __fastcall TForm1::btnSaveparaClick(TObject *Sender)
{

   SaveChartToFile(Chart1,"d:\\a.tee",false,false);
}

//Edit chart
void __fastcall TForm1::btnEditchartClick(TObject *Sender)
{
    EditChart(Form1,Chart1);
}

//Add sample points
void __fastcall TForm1::btnAddPointClick(TObject *Sender)
{
    bDrawText = true;
    Chart1->Draw();
    bDrawText = false;

}

//Load chart Parameters
void __fastcall TForm1::btnLoadParaClick(TObject *Sender)
{
//
}




void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
   int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
    int Y0 = Chart1->Axes->Left->CalcYPosValue(50);

  if(bDrawText ) 
{
  for(int i=0;i<5;i++)
   {

        Chart1->Canvas->TextOutA(X0,Y0,"OK");
        X0 +=10;
        Y0 +=10;
   }
}
}
//---------------------------------------------------------------------------



Posted: Thu Nov 20, 2008 1:54 pm
by narcis
Hello wwp3321,

Have you tried implementing OnAfterDraw event like this?

Code: Select all

void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
	if(bDrawText )
	{
		int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
		int Y0 = Chart1->Axes->Left->CalcYPosValue(50);

		for(int i=0;i<5;i++)
		{
			Chart1->Canvas->TextOutA(X0,Y0,"OK");
			X0 +=10;
			Y0 +=10;
		}
	}
}

Posted: Fri Nov 21, 2008 12:37 am
by 8574101
narcis wrote:Hello wwp3321,

Have you tried implementing OnAfterDraw event like this?

Code: Select all

void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
	if(bDrawText )
	{
		int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
		int Y0 = Chart1->Axes->Left->CalcYPosValue(50);

		for(int i=0;i<5;i++)
		{
			Chart1->Canvas->TextOutA(X0,Y0,"OK");
			X0 +=10;
			Y0 +=10;
		}
	}
}

Yes, I have tried ,but still get "Error reading Tchart->OnAfterDraw" application Exception.

[img]
http://img1.freep.cn/p.aspx?u=v20_img1_ ... 103843.jpg
[/img]

Posted: Fri Nov 21, 2008 12:39 am
by 8574101
I saved the "a.tee" file as .txt file, it includes "OnAfterDraw = Chart1AfterDraw". I think Exception showed when Chart read this value .

Would you please try to compile my source posted ?
Thank you!

Posted: Fri Nov 21, 2008 1:54 am
by 8574101
Another question

The "SaveChartToFile()" method erased those "OK"s. :shock:

Posted: Fri Nov 21, 2008 9:32 am
by narcis
Hi wwp3321,
Yes, I have tried ,but still get "Error reading Tchart->OnAfterDraw" application Exception.
I'm not able to reproduce this here using v8.04. Should I follow any specific steps to reproduce it?
The "SaveChartToFile()" method erased those "OK"s
Yes, custom drawing is not exported with charts and you will have to draw it again after saving the chart file:

Code: Select all

//Load Tchart Parameters
void __fastcall TForm1::btnSaveparaClick(TObject *Sender)
{
	SaveChartToFile(Chart1,"c:\\temp\\a.tee",false,false);
	bDrawText = true;
	Chart1->Draw();
	bDrawText = false;
}

Posted: Fri Nov 21, 2008 10:01 am
by 8574101
narcis wrote:Hi wwp3321,
Yes, I have tried ,but still get "Error reading Tchart->OnAfterDraw" application Exception.
I'm not able to reproduce this here using v8.04. Should I follow any specific steps to reproduce it?
Run the application ,
add points to chart by "btnAddPointClick(TObject *Sender) ",
push the "Save para" button to save the .tee file(btnSaveparaClick),

Then close the application ,open it again, the application Exception is showed.

Posted: Fri Nov 21, 2008 10:18 am
by narcis
Hi wwp3321,

Thanks for the information but I'm not able to reproduce this here using v8.04. You could try downloading fully functional evaluation version at the URL below and try in a different machine (or same machine with v6 installed) if it solves the problem at your end.

http://www.steema.com/downloads/form_tch_vcl.html

Please notice that TeeChart Pro v7 VCL was released on early 2004 and since mid-2007 v8 is the current TeeChart version.

Posted: Fri Nov 21, 2008 10:23 am
by 8574101
Would you please try with Teechart 6.01 and BCB6.0

Posted: Sat Nov 22, 2008 10:04 am
by 8574101
I have tried at other computers,but get the same application error...
BCB6.0,Teechart6.01
WinXP sp2

Posted: Mon Nov 24, 2008 8:16 am
by narcis
Hi wwp3321,

Thanks for the information. We could reproduce the issue here using BCB6 and TeeChart V6.01. We can also confirm this works fine using v8.

We are investigating the issue and will get back to you when we have further news.

Posted: Mon Nov 24, 2008 11:12 am
by narcis
Hi wwp3321,

Before exporting the chart you should set all events to null and after importing it assign them again, for example:

Code: Select all

//Load Tchart Parameters
void __fastcall TForm1::btnSaveparaClick(TObject *Sender)
{
        Chart1->OnAfterDraw=NULL;
	SaveChartToFile(Chart1,"c:\\temp\\a.tee",false,true);
	bDrawText = true;
	Chart1->Draw();
	bDrawText = false;
}

//Load chart Parameters
void __fastcall TForm1::btnLoadParaClick(TObject *Sender)
{
        if(FileExists("c:\\temp\\a.tee"))
	{
          LoadChartFromFile(dynamic_cast<TCustomChart*>(Chart1),"c:\\temp\\a.tee");
          Chart1->OnAfterDraw=Chart1AfterDraw;
	}
}
TeeChart v8 VCL does this automatically.