Recent

Author Topic: Please Explain how Forms and Units Integrate  (Read 5011 times)

flywire

  • Jr. Member
  • **
  • Posts: 85
Please Explain how Forms and Units Integrate
« on: February 04, 2015, 01:07:05 pm »
I am trying to get comfortable with Lazarus. I have a heap of experience with a range of procedural programming languages many years ago but limited experience with OO programming although my database experience means I have no problems with the concepts of objects, properties and instances.

I would appreciate a bit of a guide on how the various files fit together:
  • As I understand it you create a project and need to create a unit at the start. Should the first unit be called main?
  • Where does the application start - first form or main unit?
  • How are the other units called?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Please Explain how Forms and Units Integrate
« Reply #1 on: February 04, 2015, 01:37:34 pm »
1) It "could" be called main as probably most developers make when starting a project, at least if there is not a more descriptive name.
2) The application starts at the LPR project file;
3 ) The other units can be called at any time from the main unit or project file. If you create it at design time, they are created and ready to use.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Please Explain how Forms and Units Integrate
« Reply #2 on: February 04, 2015, 07:03:19 pm »
As I understand it you create a project and need to create a unit at the start. Should the first unit be called main?
No. And program does NOT start from a unit (although it can have initialization section which will be executed before program start), program starts from a program (.lpr in Lazarus project realm).
Where does the application start - first form or main unit?
Back to previous answer.
How are the other units called?
Interlinked recursively via uses clause, starting from the program.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Please Explain how Forms and Units Integrate
« Reply #3 on: February 05, 2015, 10:02:37 am »
Easiest way to open the main source is from menus:
Project -> View Project Source

flywire

  • Jr. Member
  • **
  • Posts: 85
Re: Please Explain how Forms and Units Integrate
« Reply #4 on: February 05, 2015, 11:54:48 am »
Easiest way to open the main source is from menus:
Project -> View Project Source

I am getting errors on the demo programs that I put in out of 'Start Programming using Object Pascal' News application in Object Oriented Pascal p135 because I tried to run it without putting in the form. I want to understand how to fix the errors. What is the best way to work through the program (in procedural terms from beginning to end)?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Please Explain how Forms and Units Integrate
« Reply #5 on: February 05, 2015, 01:21:40 pm »
Pascal is not case sensitive.
You should not call your program "News" and a unit it uses "news".
That is why you get the error message:
News.lpr(11,35) Error: Duplicate identifier "NEWS"

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Please Explain how Forms and Units Integrate
« Reply #6 on: February 19, 2015, 11:53:57 am »
What is the best way to work through the program (in procedural terms from beginning to end)?
As people said before, Pascal programs starts on the PROGRAM file (extension ".lpr" on Linux, ".pas" or ".pp" on FreePascal, ".dpr" on Delphi).  It starts at "BEGIN" and ends at "END." (note the period).  But units may have "INITIALIZATION" and "FINALIZATION" sections that will be executed before and after proper PROGRAM.

Note that Lazarus graphical applications aren't procedural, but multi-thread event driven applications.  So, in most cases you will not see any call to any TForm object.  So trying to follow the application flow will be useless in most cases.

You should take a look to the Lazarus Wiki.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

flywire

  • Jr. Member
  • **
  • Posts: 85
Re: Please Explain how Forms and Units Integrate
« Reply #7 on: February 19, 2015, 12:33:35 pm »
... Note that Lazarus graphical applications aren't procedural, but multi-thread event driven applications. So, in most cases you will not see any call to any TForm object.  So trying to follow the application flow will be useless in most cases. ...

If you need to work with a program then you need to understand how it works and it [can be] fairly easy with a procedural program. So how do you go about understanding code for an object oriented program? I realise that one approach is to just look at the forms and examine those bits of the code that you need to while accepting that the rest exist. Still, you need to understand those bits used throughout the application.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Please Explain how Forms and Units Integrate
« Reply #8 on: February 19, 2015, 02:17:37 pm »
You could see a form as a multi-input machine where only one action (because of the mouse pointer) is available at a time. The flow is not controled by the programmer, but by the user. So the programmer puts event handlers attached on each input point which will make the program work as the user expects -- just like a machine.

When an input point is activated, the event handler attached to it is executed.
« Last Edit: February 19, 2015, 07:24:19 pm by typo »

 

TinyPortal © 2005-2018