How to NAME a charttool?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Chartist
Newbie
Newbie
Posts: 60
Joined: Wed Sep 18, 2013 12:00 am

How to NAME a charttool?

Post by Chartist » Wed Jul 23, 2014 10:57 am

Hi,

I added a charrtool at runtume:

Form1.Chart1.Tools.Add(TCursorTool);
(Chart1.Tools.Items[1] as TCursorTool).Series:=line1;

Fine.
How to NAME my tool?

I want to address it by e.g.
Form1.MyFunnyCursor. ..... := *anything *

in other words: How to encode, that "Chart1.Tools.Items[1]" is known as "MyFunnyCursor"?
(or Chart1.Tools.MyFunnyCursor)

Thanks!
Cheryll
Cheryll

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How to NAME a charttool?

Post by Sandra » Thu Jul 24, 2014 9:04 am

Hello Cheryll,

To encode a tool is added directly to the chart, you must do the same as code below:

Code: Select all

procedure TForm1.FormShow(Sender: TObject);
var MyCursor :TCursorTool;
begin
    Chart1.Tools.Add(TCursorTool);
    MyCursor := Chart1.Tools.Items[0] as TCursorTool;
    Self.MyCursor := Series1;
end; 
Hoping it will help.
Thanks in advance,
Best Regards,
Sandra Pazos / 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

Chartist
Newbie
Newbie
Posts: 60
Joined: Wed Sep 18, 2013 12:00 am

Re: How to NAME a charttool?

Post by Chartist » Thu Jul 24, 2014 10:12 am

Hi Sandra,

thank you!
This works nicely.
Unfortunately it causes 2 add-on questions.

(is "Sandra" German? in case not: "Fadenkreuz" = "Crosshair")

So this works fine in my code:
Chart_MP.Tools.Add(TCursorTool);
Fadenkreuz:= Chart_MP.Tools.Items[0] as TCursorTool;
Fadenkreuz.Series:=candle1;

non of this attempts works:
// Chart_MP.Fadenkreuz:=candle1;
// Chart_MP.Tools.Fadenkreuz:=candle1;
// Fadenkreuz.ParentChart:=Chart_MP;
// Chart_MP.Tools.Item.Fadenkreuz:= candle1;
// Fadenkreuz.Parent:=Form_MPs; {Form_MPs is the container}

The error-message keeps saying "Fadenkreuz is not known".
I declared all Vars in the interface part oy my unit Form_MPs.

So my addon-questions:
1) How can I addres "Fadenkreuz" from another unit?
2) How can I find out the items number (in our case zero) of Fadenkreuz later on?
(in my software there will be checkboxes to check and uncheck different drawing tools).

I use both types TChart and TDBChart.

Thank you!
Cheryll
Cheryll

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How to NAME a charttool?

Post by Sandra » Thu Jul 24, 2014 3:48 pm

Hello Cheryll,

We are working with it, we will try to give you a good answer in short time as possible.

Thanks in advance,
Best Regards,
Sandra Pazos / 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

Chartist
Newbie
Newbie
Posts: 60
Joined: Wed Sep 18, 2013 12:00 am

Re: How to NAME a charttool?

Post by Chartist » Fri Jul 25, 2014 3:40 pm

Hallo,

thank you.

To add: I would need an OnChange event on my "Fadenkreuz" to synchronzise it with a subchart crosshair.
The procedure is ready and looks fine, but I have no idea, how to fit the onChange event.
At the moment I am not able to pass on "Fadenkreuz" with proper values. They stay zero.

The call would be:

Code: Select all

Zeichentools.CursorSynchronize(Fadenkreuz1,Fadenkreuz);
(The content is taken from the Steema help and will probably work fine:
Procedure TZeichenTools.CursorSynchronize( Source, Dest: TCursorTool );
Dest.ParentChart.AutoRepaint:=False; // stop repainting
Dest.RedrawCursor; // hide cursor
Dest.YValue := Source.YValue;
Dest.XValue := Source.XValue;
Dest.RedrawCursor; // draw cursor again
Dest.ParentChart.AutoRepaint:=True; // enable repainting)


Warm Regards,
Cheryll
Cheryll

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How to NAME a charttool?

Post by Sandra » Thu Jul 31, 2014 11:53 am

Hello Cheryll,

Sorry for the delay. We have been investigating how you can do as you want, but I am afraid we need your code. Could you please, send us your project because we can try to find a good solution for you?

Thanks in advance,
Best Regards,
Sandra Pazos / 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

Chartist
Newbie
Newbie
Posts: 60
Joined: Wed Sep 18, 2013 12:00 am

Re: How to NAME a charttool?

Post by Chartist » Fri Aug 01, 2014 11:50 am

Hi Sandra,

the code is linked to a DB, which unfortunately cannot be sent.
And why do you need my code? This question has nothing to do with my code.

We want to know, how to address "Fadenkreuz" (or however you will name the runtime-created CursorTool) in a plain "Form1" (see above).
"Form1.Fadenkreuz" does not work.
What works?


Thanks.

Regards,
Cheryll
Cheryll

jens.mertelmeyer
Newbie
Newbie
Posts: 60
Joined: Fri Nov 22, 2013 12:00 am

Re: How to NAME a charttool?

Post by jens.mertelmeyer » Mon Aug 04, 2014 8:36 am

I'm confused. The cursor tool is a regular component, just like the chart itself, a button or whatever. You can rename it to whatever you like:
charttool.png
charttool.png (37.27 KiB) Viewed 25519 times
This also enables you to use this reference in code (like "myFancyFadenkreuz.Active := checkItsRainingOutside();") without having to introduce another variable or do any casting.

Chartist
Newbie
Newbie
Posts: 60
Joined: Wed Sep 18, 2013 12:00 am

Re: How to NAME a charttool?

Post by Chartist » Mon Aug 04, 2014 3:37 pm

Hi Jens,

thank you for your reply.

Are we talking about the same?
The topic is a cursor tool named and added at RUNTIME.
(see above code in the thread)

Regards,
Cheryll
Cheryll

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How to NAME a charttool?

Post by Sandra » Tue Aug 05, 2014 10:02 am

Hello Cheryll,

Sorry for the dealy.
And why do you need my code? This question has nothing to do with my code.
We wanted see the code are you using, because it would be very useful for us to find an accurate solution based in your code.
1) How can I addres "Fadenkreuz" from another unit?
To address your cursor from another unit, you have to declare the tool as public in your unit and add this unit in the uses clause on the unit where you want to access the tool.You can do something as next:
Tool declaration:

Code: Select all

 unit Unit1;
interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,Chart, CandleCh, Series, TeeTools;
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    MyCursor:TCursorTool;
  end;
Call the tool from other unit:

Firstly, add the unit1 in the uses clause on the unit where you want to access the tool. The lines code below show how you can do it:

Code: Select all

uses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,Unit1...
Then you need only call the tool as do next:

Code: Select all

procedure TForm2.FormCreate(Sender: TObject);
begin
Form1.MyCursor.Pen.Color := clRed;
End; 
2) How can I find out the items number (in our case zero) of Fadenkreuz later on?
(in my software there will be checkboxes to check and uncheck different drawing tools).
The best way to get the tools indexes there are in Chart, is use a loop to search tool index you want; in your case, cursor tool. The code below shows how you can do it.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i,indexCursor:Integer;
begin
  Chart1:=TChart.Create(Self);
  Chart1.Parent:=Self;
  Chart1.Align:=alClient; 
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;
  candle1:=Chart1.AddSeries(TCandleSeries) as TCandleSeries;
  candle1.FillSampleValues; 
  line1:=Chart1.AddSeries(TLineSeries) as TLineSeries;
  rsiFunc1:=TRSIFunction.Create(Self);
  line1.SetFunction(rsiFunc1);
  line1.DataSource:=candle1;
  Chart1.Tools.Add(TDrawLineTool);
  Chart1.Tools.Add(TCursorTool);
  for i := 0 to Chart1.Tools.Count-1 do
    If Chart1.Tools[i] is  TCursorTool then
      indexCursor:= i;
  MyCursor := Chart1.Tools.Items[indexCursor] as TCursorTool;
  MyCursor.Series := line1;
end;
Also, I would like inform you that "Tools" are small objects that perform additional charting functionality, like interactive drawing of lines, mouse rotation, etc. Therefore, you don’t have access to own tools through Chart and the code you use in the lines below is incorrect:

Code: Select all

// Chart_MP.Fadenkreuz:=candle1;
// Chart_MP.Tools.Fadenkreuz:=candle1;
// Chart_MP.Tools.Item.Fadenkreuz:= candle1; 
The only code line you have attached me that should work without problems is next:

Code: Select all

Fadenkreuz.ParentChart:=Chart_MP;
There is more information about TeeChart tools in the help documentation. You find the help documentation in a similar path as next:
%Program Files%\ Steema Software\TeeChart 2014 for RAD XE6\Docs
I would need an OnChange event on my "Fadenkreuz" to synchronzise it with a subchart crosshair.The procedure is ready and looks fine, but I have no idea, how to fit the onChange event. At the moment I am not able to pass on "Fadenkreuz" with proper values. They stay zero.
I would like inform you that when you create an own tool that is based in a specifically tool, you can use same methods and events there are implemented in base tool. Therefore, you should use OnChange event and do the same as do in Demo example All Features\Tools\Cursor\Synchronizing Two.
Best Regards,
Sandra Pazos / 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

Chartist
Newbie
Newbie
Posts: 60
Joined: Wed Sep 18, 2013 12:00 am

Re: How to NAME a charttool?

Post by Chartist » Tue Aug 12, 2014 2:45 pm

Hi Sandra,

thank you very much for your reply.
It starts to work now.
The origin of the problem was, that we want to synchronise 2 CursorTools.
So about this code ("finding the crosshair = fadenkreuz"):


perhaps I split the problem:

a) FINDING myCursor by name

your posting was:

Code: Select all

 for i := 0 to Chart1.Tools.Count-1 do
    If Chart1.Tools[i] is  TCursorTool then
      indexCursor:= i;
  MyCursor := Chart1.Tools.Items[indexCursor] as TCursorTool;
As far as I understand it, this will give a match for the second added cursor tool, but not for the first one.
I need both of them to synchronize them.

Is it a good idea to look for "MyCursor"?
Unfortunately ...Tools.Items[indexCursor] .name"
has the value ' '.
So '.name' seems not the correct choice?

In other words:
How can I "catch" my both CursorTools in a way, that allows me to say,
"SynchroniceMyCursorTools(mycursortool1, mycursortool2);"
and send e.g. the thing to a function

The thing is, we never know, if and how many subcharts with crosshairs the user has asked for.
May be there is none, maybe 5 of them.


b)
Assigning the thing.
To declare the item from within my Form would work nicely. Unfortunately I am asked every little scratch again,
"this...has no assigned component. Do you like to remove it"?
Is there a way to teach the compiler, not to ask anymore?
It is nagging and sooner or later I hit "yes" by mistake.

Thank you,
Cheryll
Cheryll

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How to NAME a charttool?

Post by Sandra » Thu Aug 14, 2014 2:44 pm

Hello Cherryll,
a) FINDING myCursor by name.....
As I have told you previously, we would like see the code are you using, because it would be very useful for us to find an accurate solution for you. Therefore, could you please send us a simple code where we can see, exactly, what are you doing, because we try to find a good solution for you?
b) Assigning the thing.
To declare the item from within my Form would work nicely. Unfortunately I am asked every little scratch again,
"this...has no assigned component. Do you like to remove it"?
Is there a way to teach the compiler, not to ask anymore?
It is nagging and sooner or later I hit "yes" by mistake.
I am afraid I don’t understand what you want achieve, the explanation you have posted is very generic. We need a more specific explanation, so we can offer you a good answer. Could you please explain exactly what do you want achieve?

Thanks in advance,
Best Regards,
Sandra Pazos / 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

Chartist
Newbie
Newbie
Posts: 60
Joined: Wed Sep 18, 2013 12:00 am

Re: How to NAME a charttool?

Post by Chartist » Fri Aug 15, 2014 4:41 pm

Hi,

thank you for your answer.

SHORT VERSION:
I need a crosshair, which shows up at all my chart's series from top to bottom.


LONG VERSION:
It is not bad will, that I do not add my code. The code is connected to a DB.
Obviously I cannot publish the DB.

So you want me to me to build an easy version of the problem?
- Well, this is what I have tried all the time.

The base problem is a ridicoulous little line, I cannot grab.
Some code done by the support and me you will find here:
http://www.teechart.net/support/viewtop ... =3&t=14908

The story behind is this:
I have several series and several axis. The annoying thing: The crosshair does not show all over these series, ....
(see the old topic and screenshot).

So the old solution / workaround was: 'add 2 crosshairs and "synchronize" them.'
Adding is easy, but how to synchronize them? The point is, that I do not know, how many series/crosshairs there will be at runtime.
So I cannot use the synchronize example from the help directly.
I tried it in a function where I wanted to send both the cursors to.

like:
procedure MyDrawingToolUnit . MySynchronizeGenie(cursor1,cursor2);

Did not work for me, because I could not ADRESS my crosshairs "anytime at runtime".
So: This was the beginning of "our story" / thread.

If you need some code example, please look at the source codes and screenshots of the old thread.
For the "new" problem, I do not have an example.
If I had it, there would be not need to ask for it any more.

Thank you for having read down to here.

Regards,
Cheryll
Cheryll

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

Re: How to NAME a charttool?

Post by Yeray » Tue Aug 19, 2014 10:28 am

Hi Cheryll,

Find below a simple example, based on the last code at the thread you've just referenced showing how to put your TCursorTools in an array as you create them and how to use the TCursorTools OnChange event to synchronize all the TCursorTools in the array:

Code: Select all

uses Chart, CandleCh, Series;

var MyCursorTools: array of TCursorTool;

procedure TForm1.FormCreate(Sender: TObject);
var
    Chart_MP: TChart;
    candle1: TCandleSeries;
    line1: TLineSeries;
    rsiFunc1: TRSIFunction;
    MyAxis : TChartAxis;
begin
  Chart_MP:=TChart.Create(Self);
  Chart_MP.Parent:=Self;
  Chart_MP.Align:=alClient;

  Chart_MP.View3D:=false;
  Chart_MP.Legend.Visible:=false;

  candle1:=Chart_MP.AddSeries(TCandleSeries) as TCandleSeries;
  candle1.FillSampleValues;

  line1:=Chart_MP.AddSeries(TLineSeries) as TLineSeries;
  rsiFunc1:=TRSIFunction.Create(Self);
  line1.SetFunction(rsiFunc1);
  line1.DataSource:=candle1;

  MyAxis := TChartAxis.Create(Chart_MP);
  line1.CustomVertAxis := MyAxis;

  MyAxis.StartPosition:=95;
  MyAxis.EndPosition:=100;

  Chart_MP.Axes.Left.EndPosition:=95;

  with AddCursorToArray((Chart_MP.Tools.Add(TCursorTool) as TCursorTool)) do
  begin
    OnChange:=CursorChange;
    Series:=candle1;
  end;

  with AddCursorToArray((Chart_MP.Tools.Add(TCursorTool) as TCursorTool)) do
  begin
    OnChange:=CursorChange;
    Series:=line1;
  end;
end;

function TForm1.AddCursorToArray(ACursor: TCursorTool): TCursorTool;
var i: Integer;
begin
  result:=nil;

  for i:=Low(MyCursorTools) to High(MyCursorTools) do
    if ACursor = MyCursorTools[i] then
      exit;

  SetLength(MyCursorTools, Length(MyCursorTools)+1);
  MyCursorTools[length(MyCursorTools)-1]:=ACursor;

  result:=ACursor;
end;

procedure TForm1.CursorChange(Sender:TCursorTool; x,y:Integer; Const XValue,YValue:Double; Series:TChartSeries; ValueIndex:Integer);
var i: Integer;
begin
  for i:=Low(MyCursorTools) to High(MyCursorTools) do
    if Sender <> MyCursorTools[i] then
    begin
      MyCursorTools[i].XValue:=XValue;
      MyCursorTools[i].YValue:=YValue;
    end;
end;
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

Chartist
Newbie
Newbie
Posts: 60
Joined: Wed Sep 18, 2013 12:00 am

Re: How to NAME a charttool?

Post by Chartist » Fri Aug 22, 2014 1:49 pm

Hello Yeray,

thank you so much!
This solution is genius.

Warm Regards,
Cheryll
Cheryll

Post Reply