SOLVED!!! - What is wrong with this code lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- esvignolo · 2017-02-19 15:45 Hi, i made a simple program, this work fine on Windows and Linux, but on macOS (Carbon y cocoa) raise a exception on click 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 objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);  private   public   end; var  Form1: TForm1;  Button2: TButton; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin   Button2:=TButton.Create(Form1);   Button2.Parent:=Form1;   Button2.Caption:='Release';   Button2.OnClick:=@Button2Click;   Button2.Left:=0;   Button2.top:=0;end; procedure TForm1.Button2Click(Sender: TObject);begin   Button2.Free;end; end. ---------------------------------------------------------------------- balazsszekely · 2017-02-19 15:54 Freeing an object from inside its own event is not a "healthy" thing to do. It's like a software hara-kiri. ---------------------------------------------------------------------- jacmoe · 2017-02-19 15:56 More like software-banzai.  Why not simply: 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  Close;end; ---------------------------------------------------------------------- jwdietrich · 2017-02-19 16:37 The odd thing is that your code didn't raise an exception on Windows and Linux. ---------------------------------------------------------------------- esvignolo · 2017-02-19 16:43 Because this is sample, the real thing is more complex, the problem is, i need a button when i pressed, the button must be destroyed. Quote from: jacmoe on February 19, 2017, 04:56:47 pmMore like software-banzai.  Why not simply: 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  Close;end; ---------------------------------------------------------------------- jacmoe · 2017-02-19 16:47 When you close the form, everything associated with that form is destroyed because the owner has left the building. Unless you have created the objects dynamically (AFAIK). ---------------------------------------------------------------------- Bart · 2017-02-19 16:49 Quote from: esvignolo on February 19, 2017, 05:43:34 pmBecause this is sample, the real thing is more complex, the problem is, i need a button when i pressed, the button must be destroyed. Try Code: [Select]procedure TForm1.Button1Click(Sender: TObject); begin   Application.ReleaseComponent(Sender); end; It will ensure that the releasing of the buttons is not done in the buttons's onclick event. You should not destroy an object if it is stll performing something (like an event). Bart ---------------------------------------------------------------------- esvignolo · 2017-02-19 16:51 Thanks Bart! i supuse the same thing, but i don't know how do it. I will try.