Forum > Arabic

تحرير المؤشّرات في OnClose أم OnDestroy

(1/1)

pascal111:
أيّهما أصح؟ تحرير المؤشرات في OnClose أم OnDestroy و مثال ذلكـ البرنامج التالي:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);  private   public   end; var  Form1: TForm1;  x,y,z:^integer; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin   new(x);  new(y);  new(z);   x^:=100;  y^:=200;   showmessage('x = '+inttostr(x^)+' ,y = '+inttostr(y^));   z:=x;  x:=y;  y:=z;   showmessage('x = '+inttostr(x^)+' ,y = '+inttostr(y^)); end; procedure TForm1.FormDestroy(Sender: TObject);begin  dispose(x);  dispose(y);  dispose(z);end; end.  

Handoko:
The opposite of OnCreate is OnDestroy.
The opposite of OnShow is OnClose.

If the form is a mainform, closing the form will automatically call OnDestroy event.

But if it is not a mainform:
After a form is closed, it is not destroyed. It is still exist in the system memory.

When the program is running, a form (not the mainform) can be shown and closed multiple times. So if you want to set and reset default values for variables or objects, put them in OnShow and OnClose events.

But if you want to set default values for variables or objects and free them only once, put them in OnCreate and OnDestroy events.

If you want to learn more about form's events:
https://wiki.freepascal.org/Event_order#Forms

pascal111:
مُداخلة غير مُتوقّعة أيّها الزميل Handoko وأشكُركـ على المعلومات القيّمة فلقد فهمتُ هذه النُّقطة.

Zaher:
اضف للفائدة، المتحولات لا تستفيد منها الا ضمن الفورم form ضعها داخل الفورم


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);  private   public     x,y,z:^integer;  ......... 

Navigation

[0] Message Index

Go to full version