OnPaint not being seen in Object Inspector lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- unixwizard · 2016-10-08 02:11 Gentlefolk -- old hacker (40 year UNIX developer), one time Pascal person - newbie with FreePascal and Lazarus. Mac OSX 10.11.6/MBP 15in mid 2012, 2.3Ghz Core i7 (aka Intel *64), 16GB 1600 MHZ DD3 From the Lazarus "about" screen: Lararus 1.6 [2016-02-15]                                                  FPC Version: 3.0.0                                                  SVN Revision: exported                                                  i386-darwin-carbon I'm trying to teach a young man a little about programming and wanted to start him with Pascal.  So I looked for a Pascal, found your system and it looked wonderful.   I bought the "Getting Started with Lazarus and Free Pascal" book from Amazon and off we went. For my Mac, I installed the 3 dmg files (fpc, fpcsources and larazus) per the read me... etc...  Note I only could find a single file called:  lazarus-1.6-i686-macosx.dmg     From the above, I gather this uses carbon, not cocoa or qt which some of my reading says works better on the Mac, but so far have not seen anything for 1.6 that does anything other than this.  Similarly, I would have expected the default install file be Intel-64 binaries not 32 bit.  But it was all I could find on the download site so I installed it. All was good and the basic examples work calling fpc directly and was making progress until I tried the Lazarus examples from the book [which sadly are Winders examples primarily].   Lazarus fires up and I drop buttons, etc... except when after I hit the "green compile" button - things compile fine but the program never runs.   I can run the examples "manually" if I open the foo.app file with the finder.   Moreover, I can not exit lazarus - I have to "kill -9" the gdb task. But being a systems guy and long time hacker I kept at it.  Google is your friend etc...  We were making progress until.... I discovered that 2 (I think related) problems which I can not find answers, so I thought I would throw myself to the mercy of you folks and ask if you folks had any hints/thoughts/helpful things to try/experiences here that might match. None of the graphics examples using Buttons would work (page 191 if you have the book).    None of the calls to canvas.line(mumble) displays on the Mac.   I note that the book's examples are the same as the ones described in a video from the UK, so I was think I should be ok.  I tried things exactly the same as the video (other than Mac vs Win7) and nothing with graphics displays.     After much googling and reading what I can find, I understand that the LCL library does not 100% match the Mac Carbon interface and I'm guessing this might be part of the problem And from on page 194 they talked about setting onPaint in the object inspector.   Yet there is no OnPaint event for the Button!! (see attachment)  After watching the video, I typed in the OnPaint example directly for grins and giggles.  It compiles but no love.   I added a call to "Invalidate" in the ButtonClick routine as per some other instrux, but that did not help either. So my questions are:  how do I get Graphics to display on a form? which I think is how to do I get painting, onPaint interfaces for Lazarus to work properly on the Mac. Any hints, thoughts are welcome. Many thanks. ---------------------------------------------------------------------- Thaddy · 2016-10-08 06:13 The OnPaint event is for the control itself and fired when it is painted. TButton does not have such a published OnPaint event, that's why you don't see it. What you are looking for is the canvas property. e.g: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  form1.canvas.Ellipse(100,100,200,200);  form1.canvas.Pen.color := clRed;  form1.canvas.MoveTo(100,100);  form1.canvas.LineTo(200,200);end; ---------------------------------------------------------------------- unixwizard · 2016-10-08 17:14 Thaddy, Many thanks for the quick responce.   I'm gather then that the missing OnPaint property is not the issue - although it does seem strange to me as I understand how I thought painting is supposed to work (but I probably misunderstanding something - as I am an OS/distributed systems/networking guy - not a ``graphic's weenie'' as Prof. Andy VanDam used to affectionately call his Graphics Team in our Stellar Computer days). That said -- when I try your suggestion there is sadly no difference in my result between having Form1. or leaving it implied in the calls to canvas.   Nothing is displayed.  The routine TForm1.Button1Click is acting like the system paint routine is never being called after we scribbled on the canvas. I can not seem to figure out how to force the update.   I've tried calling invalidate (with and without the explicit naming of Form1 - but it makes no difference.  So I'm still befuddled, it seems like this is supposed to work, but it does not. Since I'm a newbie your wonderful system, I hate to scream bug here and am assuming I have done something incorrect - but man I've followed the instructions for the installation on my Mac, tried the examples from the book and it just does not work for graphics.  BTW, I even tried the old Microsoft trick of nuked FreePascal, Lazarus and reinstalling. Just for grins and giggles I added a call to showmessage('mesg X'); were I increment X each time I recompile, so I know that I am actually changing the code.   The showmessage box appears, but no graphics are displayed in the form - so I'm confident that changes are being added to the code.  I also do have a finder window open during the compile and see different files comes and go as compilation proceeds. Again many, many thanks for your generous gift of time and wisdom to help enlighten us. Clem ---------------------------------------------------------------------- Thaddy · 2016-10-08 19:04 I tried that actual code before I posted it! Maybe you missed that you have to doubleclick on the Buttons OnClick event in the object inspector  to open the editor with an empty body for that event to fill in? Or set the OnClick handler in code, but Lazarus will do that for you. See screenshot on what you should obtain (any platform) And full code here: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode delphi} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; { TForm1 } type  TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  form1.canvas.Ellipse(100,100,200,200);  form1.canvas.Pen.color := clRed;  form1.canvas.MoveTo(100,100);  form1.canvas.LineTo(200,200);end; end. project: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; {$mode delphi} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Interfaces, // this includes the LCL widgetset  Forms, Unit1  { you can add units after this }; {$R *.res} begin  RequireDerivedFormResource := True;  Application.Initialize;  Application.CreateForm(TForm1, Form1);  Application.Run;end. ---------------------------------------------------------------------- Cyrax · 2016-10-08 20:23 You should only access TCanvas instance inside OnPaint event. Depending on widgeset and underlying OS, it is one and only place where TCanvas have correct handle created and assigned. The exception on this rule is TBitmap class. You can access its TCanvas class instance at any time. So create instance of TBitmap class, do some drawing on it and inside TForm.OnPaint method, draw TBitmap contents unto TForm.Canvas. ---------------------------------------------------------------------- unixwizard · 2016-10-10 19:16 Thaddy, Many thanks for the example code and demonstration.  Clearly this is supposed to work.  I looked carefully at your example and my own the only difference between the code that was generated for me by my copy of Lazarus and that was generated for you was the {mode Delphi} vs.   {$mode objfpc}{$H+} I changed those lines in the two pascal files and recompiled, but sadly I get the same results.   So I can only assume something is different between your set up on your Mac and my own.  I send my system info in the original; but I'll repeat it here. Mac OSX 10.11.6/MBP 15in mid 2012, 2.3Ghz Core i7 (aka Intel *64), 16GB 1600 MHZ DD3 From the Lazarus "about" screen: Lararus 1.6 [2016-02-15]                                                  FPC Version: 3.0.0                                                  SVN Revision: exported                                                  i386-darwin-carbon I assume there are configuration file(s) somewhere that I post.   You tell me.