Recent

Author Topic: [SOLVED] DataPointDistanceTool programmatically clear result  (Read 238 times)

mig-31

  • Sr. Member
  • ****
  • Posts: 260
[SOLVED] DataPointDistanceTool programmatically clear result
« on: September 24, 2019, 05:57:48 pm »
Hi,

I set DataPointDistanceTool.Options to dpdoPermanent  to leave the result of distance measurement in the TChart. I need to clear(remove) distance measurement (distance line, label mark...) from the TChart programmatically for example on Button.Click event.

I go through the DataPointDistanceTool code, but don't see where is it. :'( It should be there, because clearing is done automatically, when the DataPointDistanceTool.Options sets to []. 

How can I do this?

Thank you.
« Last Edit: September 25, 2019, 03:31:27 pm by mig-31 »
Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

wp

  • Hero Member
  • *****
  • Posts: 6319
Re: DataPointDistanceTool programmatically clear result
« Reply #1 on: September 24, 2019, 06:51:08 pm »
Difficult...

At first I thought of "Hide", but this works only when the tool is active.

Finally I had the idea to destroy and recreate the tool. This works. But it seems that the "Assign" of the TDataPointDistanceTools has not been implemented, and some properties have to be transferred manually:

Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   t: TDataPointDistanceTool;
  4. begin
  5.   t := TDataPointDistanceTool.Create(ChartToolset1DataPointDistanceTool1.Owner);
  6.   t.Assign(ChartToolset1DataPointDistanceTool1);
  7.   t.DrawingMode := ChartToolset1DataPointDistanceTool1.DrawingMode;
  8.   t.Options := ChartToolset1DataPointDistanceTool1.Options;
  9.   // transfer more properties here...
  10.   ChartToolset1DatapointDistanceTool1.Free;
  11.   ChartToolset1DataPointDistanceTool1 := t;
  12.   ChartToolset1DataPointDistanceTool1.Toolset := ChartToolSet1;
  13.   Chart1.Invalidate;
  14. end;

[EDIT]
Above text is a translation of my original answer which inicidentally had been in German:
Quote
Schwierig...

Zunächst dachte ich "Hide", aber das funktioniert nur, solange das Tool aktiv ist.

Schließlich bin ich darauf gekommen, dass man das Tool zerstören und wieder erzeugen könnte. Das funktioniert, nur ist anscheinend das "Assign" beim DataPointDistanceTool nicht implementiert und man muss einige Properties von Hand übertragen
« Last Edit: September 25, 2019, 10:23:51 am by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: DataPointDistanceTool programmatically clear result
« Reply #2 on: September 25, 2019, 10:11:44 am »
Thank you.

I don't speak German, but Google Translator helped me :D

I also think by this way, but I try to find "more elegant" way.
Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

wp

  • Hero Member
  • *****
  • Posts: 6319
Re: DataPointDistanceTool programmatically clear result
« Reply #3 on: September 25, 2019, 10:25:06 am »
OMG - I am writing too many posts... Replaced the text by an English version.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10