Recent

Author Topic: Calling a form within a project from another project  (Read 1501 times)

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Calling a form within a project from another project
« Reply #15 on: July 05, 2022, 11:40:14 am »
Yes, it works like that within a button procedure, but can't we do the trick of showmessage and inputbox  in FormCreate procedure with another form like I tried to do?
You'll need to do it after the OnShow of Form1.

Look at https://wiki.lazarus.freepascal.org/Event_order#Forms for the order.

You could do it in TForm1.OnActivate but I'm not entirely sure this is fired only once during your program.

It will depend on what exactly you are trying to accomplish (also see note of Handoko about the Splash screen).

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: Calling a form within a project from another project
« Reply #16 on: July 05, 2022, 11:46:57 am »
project1.lpr
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads,
  8.   {$ENDIF}
  9.   {$IFDEF HASAMIGA}
  10.   athreads,
  11.   {$ENDIF}
  12.   Interfaces, // this includes the LCL widgetset
  13.   Forms, Unit1
  14.   { you can add units after this };
  15.  
  16. {$R *.res}
  17.  
  18. begin
  19.   RequireDerivedFormResource:=True;
  20.   Application.Scaled:=True;
  21.   Application.Initialize;
  22.   Application.CreateForm(TForm1, Form1);
  23.   Application.Run;
  24. end.
Unit1.pas
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   InputBoxUnit;
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Edit1: TEdit;
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure FormCreate(Sender: TObject);
  19.   private
  20.     FOldOnIdle: TIdleEvent;
  21.     procedure InboxModal(Sender: TObject; var Done: boolean);
  22.   public
  23.  
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.Button1Click(Sender: TObject);
  36. begin
  37.   edit1.Text := inputboxform.Edit1.Text;
  38. end;
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42.   { Delay creation and ShowModal of InputBoxForm until application is quiet }
  43.   if not Assigned(FOldOnIdle) then begin
  44.     FOldOnIdle := Application.OnIdle;
  45.     Application.OnIdle := @InboxModal;
  46.   end;
  47.  
  48. end;
  49.  
  50. procedure TForm1.InboxModal(Sender: TObject; var Done: boolean);
  51. begin
  52.   Done := True;
  53.   Application.OnIdle := FOldOnIdle;
  54.   FOldOnIdle := nil;
  55.   if not Assigned(InputBoxForm) then begin
  56.     Application.CreateForm(TInputBoxForm, InputBoxForm);
  57.     inputboxform.ShowModal;
  58.     FreeAndNil(InputBoxForm);
  59.   end;
  60. end;
  61.  
  62. end.

pascal111

  • Sr. Member
  • ****
  • Posts: 423
  • Un trabajo en equipo para programas serias.
Re: Calling a form within a project from another project
« Reply #17 on: July 05, 2022, 02:21:52 pm »
I think "Done" variable has no effect, am I right?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.InboxModal(Sender: TObject; var Done: boolean);
  2. begin
  3.   //Done := True;
  4.   Application.OnIdle := FOldOnIdle;
  5.   FOldOnIdle := nil;
  6.   if not Assigned(InputBoxForm) then begin
  7.     Application.CreateForm(TInputBoxForm, InputBoxForm);
  8.     inputboxform.ShowModal;
  9.     FreeAndNil(InputBoxForm);
  10.   end;
  11. end;          
  12.  
La chose par la chose est rappelé.

 

TinyPortal © 2005-2018