GetAsLine() -> Invalid Type Cast

TeeChart for ActiveX, COM and ASP
Post Reply
jonnyg
Newbie
Newbie
Posts: 5
Joined: Fri Feb 22, 2008 12:00 am

GetAsLine() -> Invalid Type Cast

Post by jonnyg » Wed Apr 23, 2008 5:04 pm

I'm calling:

Code: Select all

m_chart.Series(i).Add(series_val, x_axis_label, color);
m_chart.Series(i).GetAsLine();
and getting "Invalid class typecast" during runtime when the GetAsLine() method is called. I'm using the TeeChart Pro Activex Control v8

From Release.txt:

January 2008
TeeChart Pro Activex Control v8
v8.0.0.3 Release

Any clue as to why this is happening?

Thanks,

John G[/code]

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Apr 24, 2008 9:28 am

Hi jonnyg,

This works fine for me here using same TeeChart version as you. Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post your files a t news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

jonnyg
Newbie
Newbie
Posts: 5
Joined: Fri Feb 22, 2008 12:00 am

Post by jonnyg » Mon Apr 28, 2008 6:27 am

Hi,

I've uploaded InvalidTypeCast.zip for your perusal.

Thanks for your help.

John G

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Fri May 02, 2008 9:09 am

Hi John,

We think that probably the teechart wrapper classes that your project is trying to use are not up to date. So I recommend you to regenerate them. Here are the steps you should follow:

- create a new dialog based project in mfc
- From the VC++ v6 IDE select "Project":"Add to project":"Components and Controls":"Registered ActiveX Controls" ... select "TeeChart Pro ActiveX Control v8" from the list.
- Accept with "OK" and the VC++ ClassWizard will generate all the classes related to the version of TeeChart registered. You may then re-use those class files in your project.

If this doesn't solve your problem, we'll investigate more
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jonnyg
Newbie
Newbie
Posts: 5
Joined: Fri Feb 22, 2008 12:00 am

Post by jonnyg » Fri May 02, 2008 2:51 pm

I do not have the VC++ v6 IDE. I only have a license for VS 2005 Pro Edition.

When I create an MFC dialog-based project and add a TeeChart control, no wrapper
classes are created. However once I add a control variable (I named it m_chart)
for the TChart control, the wizard creates one new class named CTchart1, which
inherits CWnd.

Note that when adding the TChart control variable, the ctor for the parent
dialog is modified as follows:

Code: Select all

CTChartDlgDlg::CTChartDlgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTChartDlgDlg::IDD, pParent)
	, m_chart(0)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
Notice m_chart(0) in the initialization list. This is wrong because there is no
ctor for CTchart1 that takes an int. Can you guys fix that? I see in other posts
that this has caused some trouble for other people as well.

Attempting to use the wizard-created CTchart1 class for my chart object, I'm
forced into casting hell. And ultimately, I end up using the same classes that
caused the original problem, and consequently, I still get the "Invalid class
typecast" error.

Code: Select all

void CTChartDlgDlg::InitializeTChart()
{
	string pre_label("label");
	stringstream label;
	string pre_series("series");
	stringstream series;
	unsigned long color;

	for(int i=0;i<3;i++) {
		m_chart.AddSeries(CTchart1::scPoint);
		series.str("");
		series << pre_series << "_" << i;
		
		((CSeries)m_chart.Series(i)).SetTitle(series.str().c_str());
		for(int j=0;j<10;j++) {
			label.str("");
			label << pre_label << "_" << j;
			color = ((CSeries)m_chart.Series(i)).GetColor();
			((CSeries)m_chart.Series(i)).Add(j+i, label.str().c_str(), color);
		}
	}

   // Everything works fine up to here and the chart displays the data points as expected.
	// !!! This next call is where the "Invalid class typecast" message is generated.
	CLineSeries a_line_series = ((CSeries)m_chart.Series(0)).GetAsLine();
}
Is there another way for me to do this so that I can retrieve a CLineSeries object?

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue May 13, 2008 6:22 am

Hi,

using the following code works fine here :

Code: Select all

	m_chart.AddSeries(0);  //line series
	m_chart.Series(0).FillSampleValues(5);

	CLineSeries series = m_chart.Series(0).GetAsLine();
	series.GetLinePen().SetWidth(5);

jonnyg
Newbie
Newbie
Posts: 5
Joined: Fri Feb 22, 2008 12:00 am

Post by jonnyg » Tue May 13, 2008 3:43 pm

The following code also works fine on my computer and my friend's:

Code: Select all

println("hello world");
I don't think that FillSampleValues(5) will do me much good. Are you saying that the code I'm using to populate the graph data is incorrect? If so, please let me know. Did you try running the code that I sent?

John G

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Wed May 14, 2008 10:49 am

Hi John,
I don't think that FillSampleValues(5) will do me much good. Are you saying that the code I'm using to populate the graph data is incorrect?
Of course that not, my code was just to check if the same one worked fine on your machine.
Well, forget it all. Looking to all the lines of your last code you send I've seen where the problem is, it's a small mistake. You are trying to assign the Series of the Chart to LineSeries, using the following line :

CLineSeries a_line_series = ((CSeries)m_chart.Series(0)).GetAsLine();

But at the beginning of the code you add all the series as Point series, instead of LineSeries :

m_chart.AddSeries(CTchart1::scPoint);

So, you cannot cast directly to lineSeries, if you try to change the above line by :
m_chart.AddSeries(CTchart1::scLine);
all should work fine.

Post Reply