Forum > TAChart
DatePointHintTool - invalid typ cast
Nicole:
I have this code in the onHint-Event
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var ser: TOpenHighLowCloseSeries; ser_Vol: TLineSeries; ser_Oi: TBarSeries; punkt: Integer; o, h, l, c: double; s: String; d: double; dat: TDate; .... with TDatapointHintTool(ATool) do begin / ser := ATool.Series as TOpenHighLowCloseSeries; // works fine //these 2 give me "invalid typ cast" ser_Vol := ATool.Series as TLineSeries; ser_oi := ATool.Series as TBarSeries; punkt := PointIndex; end;.............
So of 3 types, the first one works fine.
The others show "invalid type cast" or give me an protection error on mouse over.
Not sure, the thing changes.
Yes, the mistake can be elsewhere.
To my mind it is in those construction above.
If yes, does anybody have the clou "what"?
If you ask, if I see the 2 problem series on my chart - no.
This would suggest, that the error is somewhere else.
But how to search for it?
I have the illusion, that I did everything the same as in all other TCharts.
And the illusion, that I did the with the 2 series the same as with the first, the working one.
:'(
wp:
ATool.Series is always the series which is clicked by the tool. So, when you clicked the OpenHighLowCloseSeries the cast "ATool.Series as TOpenHighLowCloseSeries" is correct. But when you have in the same procedure a LineSeries and cast the same clicked ATool.Series to a TLineSeries it must fail - because the clicked series simply is not a LineSeries.
If you want to handle different series types in the same event handler you should not use the "as" operator. Check the series type with "is" instead and then do a soft cast - this does not raise an exception:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var ser: TOpenHighLowCloseSeries; ser_vol: TLineSeries; ser_Oi: TBarSeries; tool: TDatapointHintTool;... tool := TDatapointHintTool(ATool); if tool.Series is TOpenHighLowCloseSeries then ser := TOpenHighLowCloseSeries(tool.Series) else if tool.Series is TLineSeries then ser_vol := TLineSeries(tool.Series) else if tool.Series is TBarSeries then ser_Oi := TBarSeries(tool.Series);
Nicole:
Thank you for the answer.
For me this attempt ended in a disaster, my source did not start any more and I have to go back to a backup. Somehow this was not just an error-line, but I had to delete a bundle of graphics starting with the tool (did not help) and the charts.
Adding one by one again of my frame I found the line, which is the ► problem
How to work around?
Thanks.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- var ser: TOpenHighLowCloseSeries; ser_vol: TLineSeries; ser_Oi: TBarSeries; tool: TDatapointHintTool; begin ► // tool := TDatapointHintTool(ATool); //if tool.Series is TOpenHighLowCloseSeries then // ser := TOpenHighLowCloseSeries(tool.Series) //else if tool.Series is TLineSeries then // ser_vol := TLineSeries(tool.Series) //else if tool.Series is TBarSeries then // ser_Oi := TBarSeries(tool.Series);end;
this is the error message
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---[Window Title]Fehler [Content]Projekt project_x hat Exception-Klasse »External: ACCESS VIOLATION« ausgelöst mit der Meldung:Access violation reading from address $0000000000000008. In Datei 'tagraph.pas' in Zeile 1361:Result := Point(XGraphToImage(AGraphPoint.X), YGraphToImage(AGraphPoint.Y)); [Ok]
and this the jump
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TChart.GraphToImage(const AGraphPoint: TDoublePoint): TPoint;begin Result := Point(XGraphToImage(AGraphPoint.X), YGraphToImage(AGraphPoint.Y));end;
wp:
In which context is this code used? In a handler for a DataPointHintTool it should work. In case of other handlers you should check the tool class which has the Series property. The first tool in the tools hierarchy which has a Series property is the TDataPointTools:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var ser: TOpenHighLowCloseSeries; ser_vol: TLineSeries; ser_Oi: TBarSeries; tool: TDatapointHintTool;begin if not (ATool is TDatapointTool) then exit; tool := TDatapointTool(ATool); if tool.Series is TOpenHighLowCloseSeries then ser := TOpenHighLowCloseSeries(tool.Series) else if tool.Series is TLineSeries then ser_vol := TLineSeries(tool.Series) else if tool.Series is TBarSeries then ser_Oi := TBarSeries(tool.Series); ...end;
Nicole:
it is in the OnHint-Event in the DataPointHintTool.
Same problem, same error message.
I wrote the text below now
Pls be aware, that I filled in the word "hint" because the compiler complained.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Var tool: TDatapointHintTool; begin if not (ATool is TDataPointHintTool) then exit; tool := TDatapointHintTool(ATool);
PS: The Supergau came back. The code does compile, but it does not run any more.
Not even the // in front of the var-declaration helped, no exit helped.
I think, I need my backup again. ;-((
Navigation
[0] Message Index
[#] Next page