Charttool TRectagleTool - Copy!

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

Charttool TRectagleTool - Copy!

Post by Chartist » Sat Mar 22, 2014 12:24 pm

I use the Charttool TRectagleTool, which draws an editable rectangle on my chart.
Works fine.

I adjust the rectangle at runtime, what is done by the mouse. Works fine.

Then I WANT to right click it and choose "draw a twin rectangle slightly above or below of the first one and let me drag it to e.g. the other corner of the chart".

How to do this?

Thanks,
Cheryll
Cheryll

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

Re: Charttool TRectagleTool - Copy!

Post by Yeray » Mon Mar 24, 2014 4:14 pm

Hello Cheryll,

I'm afraid you should do it manually. Here you have a simple example to start with:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
  begin
    Text:='Rectangle Tool 1';
    AutoSize:=true;
    Shape.Transparency:=0;
    Left:=100;
    Top:=75;

    OnClick:=RectClick;
  end;
end;

procedure TForm1.RectClick(Sender:TAnnotationTool; Button:TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button=mbRight then
  begin
    with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
    begin
      Text:=Sender.Text + ' (twin)';
      AutoSize:=Sender.AutoSize;
      Shape.Transparency:=Sender.Shape.Transparency;
      Top:=Sender.Top+Sender.Height;
      Left:=Sender.Left;
    end;
  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: Charttool TRectagleTool - Copy!

Post by Chartist » Tue Mar 25, 2014 3:20 pm

Hi Yeray,

thank you very much for the reply.

It looks very promising to me. Unfortunately I could not find a tutorial about those phantastic tools.
So my ideas about it are only rough and base on try and error.

I copied the code and managed my program do draw the original rectangle several times, what is a start and helps as first aid.
What I did not manage is to copy the size of the EDITED rectangle.

This is due to a problem in pasting the settings.

e.g. this line:
{ in my case: with DBChart_A_Kontrakt.Tools.Add(TRectangleTool) as TRectangleTool do begin }
" AutoSize:=Sender.AutoSize"
gives me the error message "unknown item Autosize " and does not allow compilation.

The moment I put the line into commentary, the new rectange is drawn fine, but with the original settings.

How can I make Delphi "know" those settings?
The "not know item"-error is true for all 4 lines:
{
Text:=Sender.Text + ' (twin)';
AutoSize:=Sender.AutoSize;
Shape.Transparency:=Sender.Shape.Transparency;
Top:=Sender.Top+Sender.Height;
Left:=Sender.Left;
}

I would be glad, to learn more about those tools by study a tutorial.

Kind Regards,
Cheryll
Cheryll

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

Re: Charttool TRectagleTool - Copy!

Post by Yeray » Wed Mar 26, 2014 11:16 am

Hi Cheryll,
Chartist wrote:It looks very promising to me. Unfortunately I could not find a tutorial about those phantastic tools.
So my ideas about it are only rough and base on try and error.
The documentation, tutorials and examples are shipped with the binary installation. You should find them under the Docs and Examples folders in your installation. You should also find shortcuts to them in the Start Menu, under TeeChart's program group.
However, they are focused on the general use of the majority of series, functions, tools and features. Note what you are asking for here is a quite specific feature.
Chartist wrote:I copied the code and managed my program do draw the original rectangle several times, what is a start and helps as first aid.
What I did not manage is to copy the size of the EDITED rectangle.

This is due to a problem in pasting the settings.

e.g. this line:

Code: Select all

{ in my case: with DBChart_A_Kontrakt.Tools.Add(TRectangleTool) as TRectangleTool do begin }
" AutoSize:=Sender.AutoSize"
gives me the error message "unknown item Autosize " and does not allow compilation.

The moment I put the line into commentary, the new rectange is drawn fine, but with the original settings.

How can I make Delphi "know" those settings?
The "not know item"-error is true for all 4 lines:

Code: Select all

{
      Text:=Sender.Text + ' (twin)';
      AutoSize:=Sender.AutoSize;
      Shape.Transparency:=Sender.Shape.Transparency;
      Top:=Sender.Top+Sender.Height;
      Left:=Sender.Left;
}
Difficult to say without the full code. It would be useful if you could arrange a simple example project we can run as-is to reproduce the problem here.

Note in the code I posted above:

Code: Select all

procedure TForm1.RectClick(Sender:TAnnotationTool; Button:TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button=mbRight then
  begin
    with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
    begin
      Text:=Sender.Text + ' (twin)';
      AutoSize:=Sender.AutoSize;
      Shape.Transparency:=Sender.Shape.Transparency;
      Top:=Sender.Top+Sender.Height;
      Left:=Sender.Left;
    end;
  end;
end;
the properties that are being set (Text, AutoSize,...) are from the TRectangleTool just created in the line:

Code: Select all

    with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
while the properties/values being taken (Sender.Text, Sender.AutoSize,...) are from Sender that is the object I created at the FormCreate method.

So, maybe you are doing the assignations out of the "with ... as TRectangleTool do" sentence so the properties in the left part can't be found.
Or maybe it's the other part where the compiler can't find; if you moved the code from the RectClick above to another method, Sender may be undefined or may be an instance of another class that doesn't have an AutoSize property.
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: Charttool TRectagleTool - Copy!

Post by Chartist » Mon Mar 31, 2014 11:45 am

Hi,

thank you for your reply.

Then the reason should be this: I have no button, which is clicked.
I do want to click the rectangle itsself. So I would need a mouse over or so.
But mouse move I cannot use, because it is taken for "big candle".
I want to use a context menu for the rectangle-copy-tool and a right click of the mouse.

In other words I would need this:
- recognize, that the pop-up-menu is clicked (I can to this by myself and land in the code of a method)
- find out, over which rectangle the mouse cursor is placed (I cannot do this)
- use the parameters of this "found" rectangle (I cannot do this) to copy it
- place the new rectangle in a way, that it is visible on the chart (so either above or below, right of left, depending)

Thanks,
Cheryll
Cheryll

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

Re: Charttool TRectagleTool - Copy!

Post by Yeray » Mon Mar 31, 2014 1:21 pm

Hi Cheryll,

I think you just have to make the new TRectangleTool to use the same OnClick event than it's "parent".
This is the new code for a simple example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
  begin
    Text:='Rectangle Tool 1';
    AutoSize:=true;
    Shape.Transparency:=0;
    Left:=100;
    Top:=75;

    OnClick:=RectClick;
  end;
end;

procedure TForm1.RectClick(Sender:TAnnotationTool; Button:TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button=mbRight then
  begin
    with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
    begin
      Text:=Sender.Text + ' (twin)';
      AutoSize:=Sender.AutoSize;
      Shape.Transparency:=Sender.Shape.Transparency;
      Top:=Sender.Top+Sender.Height;
      Left:=Sender.Left;
      OnClick:=RectClick;
    end;
  end;
end;
I only added a line of code to the example I posted above.

If you still find problems with it, please try to arrange a simple example project we can run as-is to reproduce the problem here.
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: Charttool TRectagleTool - Copy!

Post by Chartist » Mon Mar 31, 2014 2:32 pm

Hi,

this brings me a huge step further.
A nice rectangle is created without errors.

Sorry for not being able to do it:
How can I manage, that is has the same size and style as its origin?
I tried something with height and width, but nothing worked.

I attach you a screenshot of the origin and new rectangle, which I see.
I wanted the new one (which looks similar to a balloon hint in our screenshot example) looking alike the old one.

Regards,
Cheryll
Attachments
creation works without errors.jpg
creation works without errors.jpg (55.33 KiB) Viewed 9548 times
Cheryll

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

Re: Charttool TRectagleTool - Copy!

Post by Yeray » Mon Mar 31, 2014 3:24 pm

Hi Cheryll,

It seems to work fine for me here. Take a look at what I get:
2014-03-31_1719.png
2014-03-31_1719.png (32.36 KiB) Viewed 9553 times
Find below the project I used to generate that image.
If you still find problems with it, please, modify the project so we can reproduce the problem here.
testTwinRects.zip
(1.84 KiB) Downloaded 488 times
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: Charttool TRectagleTool - Copy!

Post by Chartist » Tue Apr 01, 2014 10:47 am

yes!!!
Thank you so much for the demo, now it works.

What I changed:
OLD - worked, but only without format copy:
My original code added the rectangle tool at design time and I tried at runtime to add the new functionality and new rectangles.
The new rectangle was created fine, but in a surprising format. I have no idea, where its style and size came from.

NEW - works exactly as intended:
I deleted the prepared desing-time-rectangle-tool and now add everything at runtime: the tool, the very first rectangle and all copies.

The thing looks that nice!
Thanks.

Kind Regards,
Cheryll
Cheryll

Post Reply