Lazarus

Other Languages => Arabic => Topic started by: pascal111 on August 29, 2021, 03:50:54 pm

Title: تحرير المؤشّرات في OnClose أم OnDestroy
Post by: pascal111 on August 29, 2021, 03:50:54 pm
أيّهما أصح؟ تحرير المؤشرات في OnClose أم OnDestroy و مثال ذلكـ البرنامج التالي:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormDestroy(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.   x,y,z:^integer;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.FormCreate(Sender: TObject);
  34. begin
  35.  
  36.   new(x);
  37.   new(y);
  38.   new(z);
  39.  
  40.   x^:=100;
  41.   y^:=200;
  42.  
  43.   showmessage('x = '+inttostr(x^)+' ,y = '+inttostr(y^));
  44.  
  45.   z:=x;
  46.   x:=y;
  47.   y:=z;
  48.  
  49.   showmessage('x = '+inttostr(x^)+' ,y = '+inttostr(y^));
  50.  
  51. end;
  52.  
  53. procedure TForm1.FormDestroy(Sender: TObject);
  54. begin
  55.   dispose(x);
  56.   dispose(y);
  57.   dispose(z);
  58. end;
  59.  
  60. end.
  61.  
  62.  
Title: Re: تحرير المؤشّرات في OnClose أم OnDestroy
Post by: Handoko on August 29, 2021, 04:39:12 pm
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
Title: Re: تحرير المؤشّرات في OnClose أم OnDestroy
Post by: pascal111 on August 29, 2021, 06:56:36 pm
مُداخلة غير مُتوقّعة أيّها الزميل Handoko وأشكُركـ على المعلومات القيّمة فلقد فهمتُ هذه النُّقطة.
Title: Re: تحرير المؤشّرات في OnClose أم OnDestroy
Post by: Zaher on September 19, 2021, 11:20:46 am
اضف للفائدة، المتحولات لا تستفيد منها الا ضمن الفورم form ضعها داخل الفورم

Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.     procedure FormCreate(Sender: TObject);
  3.     procedure FormDestroy(Sender: TObject);
  4.   private
  5.  
  6.   public
  7.      x,y,z:^integer;
  8.   .........
  9.  
TinyPortal © 2005-2018