Recent

Author Topic: [SOLVED] Signalize from object to main form  (Read 2870 times)

tudi_x

  • Hero Member
  • *****
  • Posts: 532
[SOLVED] Signalize from object to main form
« on: September 21, 2017, 05:42:17 pm »
hi All,
as per attached i need to signalize when edit completed so i can move to next screen.
is it possible to produce an event inside the screen 1 object that would trigger procedure in main form?

thank you

Lazarus 1.8RC4 , cross platform

Code: Pascal  [Select][+][-]
  1. unit screen_1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, ExtCtrls, Graphics, Controls, StdCtrls;
  9.  
  10. type
  11.   TScreen1 = class
  12.   private
  13.     E1: TEdit;
  14.     procedure FinishInput(ASender: TObject);
  15.   public
  16.     constructor Create(AParent: TCustomForm);
  17.     procedure IsVisible(AVisible: boolean);
  18.   end;
  19.  
  20. implementation
  21.  
  22. constructor TScreen1.Create(AParent: TCustomForm);
  23. begin
  24.   E1 := TEdit.Create(AParent);
  25.   E1.OnChange:= @FinishInput;     //hook the check
  26.   E1.Text := 'screen 1';
  27.   E1.Visible := False;
  28.   E1.Parent := AParent;
  29. end;
  30.  
  31. procedure TScreen1.IsVisible(AVisible: boolean);
  32. begin
  33.   E1.Visible := AVisible;
  34. end;
  35.  
  36. procedure TScreen1.FinishInput(ASender: TObject);
  37. begin
  38.   if E1.Text = 'x' then
  39.   begin
  40.     //signalize to switch to screen 2 - to run ShowScreen2
  41.   end;
  42. end;
  43.  
  44. end.
  45.  
« Last Edit: September 22, 2017, 09:16:25 am by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Signalize from object to main form
« Reply #1 on: September 21, 2017, 06:22:59 pm »
You are already using the edit's OnChange event for this.
So you can do what you want much more simply as in the attached project (if I've understood what you are after).

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Signalize from object to main form
« Reply #2 on: September 21, 2017, 06:32:00 pm »
thank you but i need to stick with the objects.
please advise if it is possible to call from the (GUI) objects the main form or this is bad design.

worst case scenario i would convert the units to .inc files so they are friendly classes.



« Last Edit: September 21, 2017, 06:40:17 pm by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Signalize from object to main form
« Reply #3 on: September 21, 2017, 07:57:50 pm »
If you want to use the objects you create, then you must free them correctly.
The standard way to communicate is via an event.
See the attached project which adds a suitable event and frees all the created instances.

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Signalize from object to main form
« Reply #4 on: September 22, 2017, 09:16:11 am »
i will use the notify event for all my screens.
thank you very much
Lazarus 2.0.2 64b on Debian LXDE 10

 

TinyPortal © 2005-2018