Direct drawing on Form canvas (TCanvas) from custom method lazarus / 39-Graphics ---------------------------------------------------------------------- whips · 2014-01-14 10:53 Hi all, I am verry sorry but I have to ask again I finished small unit with 2 methods Code: [Select] unit vector; {$mode objfpc}{$H+ $M+} interface  uses   Classes, SysUtils,Graphics; type       type   { TForm1 }   {$M+}   Tlcd7 = class(TComponent)   private      { private declarations }      upper,leftupper {... etc cut-off.. }: array[0..8] of Tpoint;   public      { public declarations }      procedure initvectors; //initialize values      procedure drawobject(canv : Tcanvas);   end;    And I wish to use this unit this way Code: [Select] TForm1 = class(TForm)     CheckBox1: TCheckBox;      lcd : Tlcd7; and somewhere in event handler wan't to use this way. Quote// onChange for example begin   lcd.initvectors();   .... { zoom vectors, or else move, rotate, etc.... }   .... lcd.drawobject(need to pass parrent/form canvas);   .... end; Quoteprocedure Tlcd7.draw7lcdsegment(canv : Tcanvas); begin    canv.Brush.color:= clwhite;    //drawtest(upper);    canv.Polygon(upper,true,1,8);    canv.Polygon(leftup,true,1,8);    canv.Polygon(middle,true,1,7);    canv.Polygon(rightup,true,1,7);    canv.Polygon(rightdown,true,1,7);    canv.Polygon(botton,true,1,7);    canv.Polygon(leftdown,true,1,7); end;    How to do it right way I don't want create custom widget only simply drawing on canvas and have small unit for next aplication in future. I have no experience with creating custom elements and it's over my skill make it now. ---------------------------------------------------------------------- taazz · 2014-01-14 11:02 use forms onPaintEvent for your code. eg Code: [Select]procedure TMainForm.FormPaint(Sender : TObject); begin   lcd.initvectors();   .... { zoom vectors, or else move, rotate, etc.... }   ....   lcd.drawobject(Self.Canvas);    end; ---------------------------------------------------------------------- whips · 2014-01-14 12:21 Thank to Taaz I forgot call constructor before working with class. That's produce runtime error with (SIGSEG) Code: [Select]procedure TForm1.FormCreate(Sender: TObject); begin   lcd := Tlcd7.Create(self); end;