Dashed line using ExtCreatePen not working

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
tremoflo
Newbie
Newbie
Posts: 5
Joined: Fri Feb 23, 2018 12:00 am

Dashed line using ExtCreatePen not working

Post by tremoflo » Thu May 10, 2018 7:06 pm

Hi,
I am trying to draw a line using a user-defined pen Style but the line prints straight.

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  LLogBrush : tLogBrush;
  LUserstyle : array[0..3] of Double;
begin

  Chart1.Series[0].Visible := true;
  TLineSeries(Chart1.Series[0]).Pointer.Visible := false;

  LUserstyle[0]:= 8;
  LUserstyle[1]:= 4;
  LUserstyle[2]:= 8;
  LUserstyle[3]:= 4;

  Chart1.Canvas.Pen.Handle := ExtCreatePen(PS_GEOMETRIC or PS_USERSTYLE,
                    2, LLogBrush, 4, @LUserstyle);
  Chart1.Canvas.Line(0,150,300,150);
end;
What am I doing wrong?

Thanks
Kim

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

Re: Dashed line using ExtCreatePen not working

Post by Yeray » Fri May 11, 2018 6:57 am

Hello,

I'm getting the same result using the same code (I call MoveTo and LineTo instead of just Line) in a TPaintBox so it doesn't seem anything related to TeeChart, does it?
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

tremoflo
Newbie
Newbie
Posts: 5
Joined: Fri Feb 23, 2018 12:00 am

Re: Dashed line using ExtCreatePen not working

Post by tremoflo » Fri May 11, 2018 1:17 pm

You are right. That might then be a question to Embarcadero. if you found a solution on your side, let me know.

tremoflo
Newbie
Newbie
Posts: 5
Joined: Fri Feb 23, 2018 12:00 am

Re: Dashed line using ExtCreatePen not working

Post by tremoflo » Tue May 15, 2018 4:15 pm

Hi Yeray,

I tried the code again, changed the array of LUserStyle to DWORD. Now it's painting the dashedline on the PaintBox but NOT on the Teechart!
Any idea?

Code: Select all

var
  LLogBrush : tLogBrush;
  LUserstyle : array[0..3] of DWORD;
begin

  Chart1.Series[0].Visible := true;
  TLineSeries(Chart1.Series[0]).Pointer.Visible := false;

  LUserstyle[0]:= 12;
  LUserstyle[1]:= 8;
  LUserstyle[2]:= 12;
  LUserstyle[3]:= 4;

  LLogBrush.lbStyle := BS_Solid;
  LLogBrush.lbColor := clBlue;
  LLogBrush.lbHatch := 0;

  Chart1.Canvas.Pen.Handle := ExtCreatePen(PS_GEOMETRIC or PS_USERSTYLE,
                    2, LLogBrush, 4, @LUserstyle);
  Chart1.Canvas.MoveTo(10,10);
  Chart1.Canvas.LineTo(100,100);


  PaintBox1.Canvas.Pen.Handle := ExtCreatePen(PS_GEOMETRIC or PS_USERSTYLE,
                    2, LLogBrush, 4, @LUserstyle);

  PaintBox1.Canvas.MoveTo(10,10);
  PaintBox1.Canvas.LineTo(100,100);
end;

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

Re: Dashed line using ExtCreatePen not working

Post by Yeray » Wed May 16, 2018 11:14 am

Hello,

I see it works fine in GDI, not in GDIPlus:

Code: Select all

uses TeCanvas;
  //...
  Chart1.Canvas:=TTeeCanvas3D.Create;
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

tremoflo
Newbie
Newbie
Posts: 5
Joined: Fri Feb 23, 2018 12:00 am

Re: Dashed line using ExtCreatePen not working

Post by tremoflo » Wed May 16, 2018 3:55 pm

Hi,
I changed the canvas to GDI, but still printing a solid line without any color. With GDIPlus, it printed the blue colored line. See attached picture: the blue dashed line is from the paintbox which prints well.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Canvas := TTeeCanvas3D.Create;
end;

...
  Chart1.Canvas.Pen.Handle := ExtCreatePen(PS_GEOMETRIC or PS_USERSTYLE,
                    2, LLogBrush, 4, @LUserstyle);
  Chart1.Canvas.MoveTo(10,10);
  Chart1.Canvas.LineTo(100,100);
  Chart1.Canvas.Line(150,150, 300,300);
Do you have a sample project code that you have tested you want to share?
Attachments
dashed line not drawing.png
dashed line not printing
dashed line not drawing.png (16.7 KiB) Viewed 15220 times

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

Re: Dashed line using ExtCreatePen not working

Post by Yeray » Thu May 17, 2018 10:10 am

Hello,

I'm sorry, I'm not sure how I tested it. Now I get the same result than you.
TTeeCanvas3D fires DoChangedPen when you modify the Pen.Handle and this recreates the Handle. However, you can get it working as you want by inheriting TTeeCanvas3D and overriding DoChangedPen as follows:

Code: Select all

type TMyTeeCanvas3D = class(TTeeCanvas3D)
  protected
    procedure DoChangedPen; override;
  end;

procedure TMyTeeCanvas3D.DoChangedPen;
begin
  ReferenceCanvas.Pen.Assign(Pen);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Canvas := TMyTeeCanvas3D.Create;
end;
Find the test project here:
testDashedExtCreatePen.zip
(83.57 KiB) Downloaded 732 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

tremoflo
Newbie
Newbie
Posts: 5
Joined: Fri Feb 23, 2018 12:00 am

Re: Dashed line using ExtCreatePen not working

Post by tremoflo » Thu May 17, 2018 3:10 pm

Thanks Yeray!

in fact, it also works by just assigning ReferenceCanvas.Pen after the assigning the new Pen.Handle as below.

Code: Select all

  Chart1.Canvas.Pen.Handle := ExtCreatePen(PS_GEOMETRIC or PS_USERSTYLE,
                    2, LLogBrush, 4, @LUserstyle);
  Chart1.Canvas.ReferenceCanvas.Pen.Assign(Chart1.Canvas.Pen);
  Chart1.Canvas.MoveTo(10,10);
  Chart1.Canvas.LineTo(100,100);

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

Re: Dashed line using ExtCreatePen not working

Post by Yeray » Fri May 18, 2018 6:15 am

Hello,

Agh, of course! Thanks for sharing!
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

Post Reply