Recent

Author Topic: How to call out the form at main program  (Read 3418 times)

zkdjeksa

  • New Member
  • *
  • Posts: 10
How to call out the form at main program
« on: September 08, 2018, 05:45:25 pm »
I opened the main program and several forms, but I want to call TForm1 out in the main program.
Do I have to write the procedures? How?

This is how the program looks like now:

program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, unit1, unit2, unit3, SysUtils, FileUtil, Forms, Controls,
  Graphics, Dialogs, StdCtrls, Interfaces;
  { you can add units after this }

begin

  end.

       
How to call the form out?
 

Handoko

  • Hero Member
  • *****
  • Posts: 5507
  • My goal: build my own game engine using Lazarus
Re: How to call out the form at main program
« Reply #1 on: September 08, 2018, 06:21:34 pm »
Have you tried:

Code: Pascal  [Select][+][-]
  1.   Form1.Show;

Maybe you want to know this:
https://forum.lazarus.freepascal.org/index.php/topic,38667.msg263400.html#msg263400
« Last Edit: September 08, 2018, 06:29:37 pm by Handoko »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to call out the form at main program
« Reply #2 on: September 08, 2018, 08:04:26 pm »
Generally, in GUI applications Form1 (or whatever is your MainForm) is the main program--or can be considered so.

If you're using Lazarus, and unless you have special needs, you should leave the "program" maintenance to Lazarus and call/open other forms from your main form. That's the easiest way to manage a multi-form application.

More specific advice can only be given if you show us (some of) your code and/or describe more thoroughly what you're attempting to do.

For completeness sake, this is how a Lazarus-maintained "main program" may look like:
Code: Pascal  [Select][+][-]
  1. program Textpad;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, lazcontrols, fileinfo,
  11.   {From here on, my application's forms, units, etc.}
  12.   fmain, foptions, feditor, fcheckstr, markup, doctypes,
  13.   fdatetime, gstrings, ulogging;
  14.  
  15. {$R *.res}
  16.  
  17. begin
  18.   Application.Scaled := True;
  19.   RequireDerivedFormResource := True;
  20.   Application.Initialize;
  21.   Application.CreateForm(TMain, Main);
  22.   Application.Run;
  23. end.
« Last Edit: September 08, 2018, 08:12:54 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

zkdjeksa

  • New Member
  • *
  • Posts: 10
Re: How to call out the form at main program
« Reply #3 on: September 09, 2018, 03:07:09 am »
Thank you so much lucamar, it works.

zkdjeksa

  • New Member
  • *
  • Posts: 10
Re: How to call out the form at main program
« Reply #4 on: September 09, 2018, 03:13:21 am »
Thank you for your reply, Handoko. I have tried the Form1.show. But it didn't work.

And now I have solved the problem.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to call out the form at main program
« Reply #5 on: September 09, 2018, 04:17:57 am »
Thank you so much lucamar, it works.

The thing to remember is that if you create a new "application" project in Lazarus you should let him manage your program file (which is also the project .. root, let's say)---unless you have special needs, of course. And if you don't know if you have them then you haven't  ;D

Anything else can be done from your main form, or from other forms or units.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018