[solved] Tool: HintTool - "invalid type cast" lazarus / 55-TAChart ---------------------------------------------------------------------- Nicole · 2025-12-19 16:21 There is a TAChart with a huge amount of series: TLineSeries. Today I addes an OHLC series. On mouse over I read "invalid type cast". Not surprising, because I refer to TLineSeries and nothing else. How can I work around? Ideal would be to have BOTH of the series in my hint: the values of the active line series and that of the OHTLC as well. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFrame_cot_dis.Tool_HintHint(ATool: TDataPointHintTool;  const APoint: TPoint; var AHint: String);var ser: TLineSeries;    idx: Integer;    yidx: Integer;    ttl: String;    s: string;begin  with TDatapointHintTool(ATool) do begin    ser := Series as TLineSeries;  idx := PointIndex;    yidx := YIndex;  end;   if ser <> nil then begin    if yidx > 0 then      ttl := TLineSeries(ser).Styles.Styles[yidx].Text    else begin      ttl := ser.Title;      s := Zeit.StringDoubleWirdString(FloatToStr(ser.GetXValue(idx)));      AHint := ttl +': '+ FloatToStrF(ser.GetYValue(idx), ffFixed, 4, 0)+ ' (' + s + ')';        end    end else AHint := '';end; ---------------------------------------------------------------------- jamie · 2025-12-19 23:04 Hmm Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Series as TSeriesClass;  don't know but maybe using the base class will help, not sure if that is too low of a check.. Jamie ---------------------------------------------------------------------- wp · 2025-12-20 00:10 Quote from: Nicole on December 19, 2025, 05:21:03 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   with TDatapointHintTool(ATool) do begin    ser := Series as TLineSeries;...A hard-cast by means of the "as" operator raises an exception if the types do not match. Better to check the type first and then do a manual cast: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  lineSer: TLineSeries;  ohlcSer: TOHLCSeries;...  with TDatapointHintTool(ATool) do begin    if Series is TLineSeries then    lineSer := TLineSeries(Series)    else if series is TOHLCSeries then      ohlcSer := TOHLCSeries(Series)    else      exit;... Now, how to combine the hints: I am assuming that all series share the same x values, or in other words: For every data point index every series sees the same x value. In this case you get the point index from the tool (ATool.PointIndex), and now you can query the values that you want to combine in the hint from all series needed even when they are not hit by the tool Example (untested): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFrame_cot_dis.Tool_HintHint(ATool: TDataPointHintTool;  const APoint: TPoint; var AHint: String);var  idx: Integer;  O, H, L, C: Double;  volume: Double;  dt: TDateTime;begin  idx := ATool.PointIndex;  dt := OHLCSeries.XValue[idx];  O := OHLCSeries.YValues[idx, OHLCSeries.YIndexOpen];  H := OHLCSeries.YValues[idx, OHLCSeries.YIndexHigh];  L := OHLCSeries.YVAlues[idx, OHLCSeries.YIndexLow];  C := OHLCSeries.YValues[idx, OHLCSeries.YIndexClose];  volume := VolumeSeries.YValue[idx];  // Assuming that this is a TLineSeries displaying the volume of transactions on this date  AHint := Format(    'Date: %s' + LineEnding +    'Open: %.2n $'+LineEnding+    'High: %.2n $' + LineEnding +    'Low: %.2n $' + LineEnding +    'Close: %.2n $' + LineEnding +    'Volume: %.2n $', [    ShortDateToStr(dt),    O, H, L, C,    volume  ]);end; ---------------------------------------------------------------------- Nicole · 2026-01-03 09:11 Thank you so very much! Here is my version and a second one, case somebody needs it on a rainy day. No, the second one is not from me neither, but also from WP long ago: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // gibt die Werte der Kurven unter dem Cursor ausprocedure TFrame_cot_dis.Tool_HintHint(ATool: TDataPointHintTool;  const APoint: TPoint; var AHint: String);var lineSer: TLineSeries;    ohlcSeries: TOpenHighLowCloseSeries;    idx: Integer;    O, H, L, C: Double;    volume: Double;    dt: TDateTime;    yidx, YWert: Integer;    ttl: String;    s: string;begin  with TDatapointHintTool(ATool) do begin  // Vorteil zu "with.. as" => keine Exception    if Series is TLineSeries then begin      lineSer := TLineSeries(Series);      idx := PointIndex;      YWert := YIndex;      if lineser <> nil then begin        if yidx > 0 then            ttl := TLineSeries(lineser).Styles.Styles[yidx].Text          else begin          ttl := lineser.Title;            s := Zeit.StringDoubleWirdString(FloatToStr(lineser.GetXValue(idx)));          AHint := ttl +': '+ FloatToStrF(lineser.GetYValue(idx), ffFixed, 4, 0)+ ' (' + s + ')';              end          end else AHint := '';    end    else if series is TOpenHighLowCloseSeries then begin    ohlcSeries := TOpenHighLowCloseSeries(Series);      idx := ATool.PointIndex;      dt := OHLCSeries.XValue[idx];      O := OHLCSeries.YValues[idx, OHLCSeries.YIndexOpen];      H := OHLCSeries.YValues[idx, OHLCSeries.YIndexHigh];      L := OHLCSeries.YVAlues[idx, OHLCSeries.YIndexLow];      C := OHLCSeries.YValues[idx, OHLCSeries.YIndexClose];      //VolumeSeries.YValue[idx];  // Assuming that this is a TLineSeries displaying the volume of transactions on this date      AHint := Format(        'Date: %s' + LineEnding +        'Open: %.2n'+LineEnding+        'High: %.2n' + LineEnding +        'Low: %.2n' + LineEnding +        'Close: %.2n'    // 'Volume: %.2n $'      , [        DateToStr(dt),        O, H, L, C        // ,volume      ]);     end    else exit; end; end; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // verschiebt das Ausgabefenster vom Mauscursor wegprocedure TFrame_cot_dis.Tool_HintHintLocation(ATool: TDataPointHintTool;  AHintSize: TSize; var APoint: TPoint);begin  APoint.Y := APoint.Y - AHintSize.CY;end;