Page 1 of 1

Dashed line using ExtCreatePen not working

Posted: Thu May 10, 2018 7:06 pm
by 16583082
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

Re: Dashed line using ExtCreatePen not working

Posted: Fri May 11, 2018 6:57 am
by yeray
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?

Re: Dashed line using ExtCreatePen not working

Posted: Fri May 11, 2018 1:17 pm
by 16583082
You are right. That might then be a question to Embarcadero. if you found a solution on your side, let me know.

Re: Dashed line using ExtCreatePen not working

Posted: Tue May 15, 2018 4:15 pm
by 16583082
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;

Re: Dashed line using ExtCreatePen not working

Posted: Wed May 16, 2018 11:14 am
by yeray
Hello,

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

Code: Select all

uses TeCanvas;
  //...
  Chart1.Canvas:=TTeeCanvas3D.Create;

Re: Dashed line using ExtCreatePen not working

Posted: Wed May 16, 2018 3:55 pm
by 16583082
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?

Re: Dashed line using ExtCreatePen not working

Posted: Thu May 17, 2018 10:10 am
by yeray
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 744 times

Re: Dashed line using ExtCreatePen not working

Posted: Thu May 17, 2018 3:10 pm
by 16583082
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);

Re: Dashed line using ExtCreatePen not working

Posted: Fri May 18, 2018 6:15 am
by yeray
Hello,

Agh, of course! Thanks for sharing!