Recent

Author Topic: Namespaces UNIT1 does not see unit2  (Read 2615 times)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Namespaces UNIT1 does not see unit2
« Reply #15 on: September 03, 2020, 06:38:29 pm »
@ is the AddressOf operator.

In Delphi mode, addresses of methods are taken automagically, and the syntax does not require "@" when referencing a method as a parameter when you call its code. In obfpc mode the syntax is stricter, and where you are calling the code of a method, it is required to use the @ operator on the method's name (which returns the method's address).

Because the code I provided is a GUI app rather than a console app it requires an extra level of synchronisation because it becomes a multi-threaded program. Its main thread, governed by the Application instance, processes OS messages and manages the GUI. The other threads that are spawned as philosophers know nothing about the main thread. The main thread of a GUI program needs to be synchronised with any other threads that are running which wish to interact with the main thread. In this case those threads need to post new lines in the memo and get the OS to update the memo widget. The call to Synchronize ensures that those threads do not collide with the non re-entrant main GUI thread.
Console apps can generally spew WriteLns to the console with impunity, and will not be interfering with a main GUI thread (since there is none).

At least, that is my understanding.  I do little thread programming, so others may have more helpful things to say about this than me.

« Last Edit: September 03, 2020, 06:47:22 pm by howardpc »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Namespaces UNIT1 does not see unit2
« Reply #16 on: September 03, 2020, 07:28:11 pm »
I have tried to find the Reference Manual (chapter 16, section 16.4: Unit dependencies), but I went lost in the numerous Lazarus documentation.
Perhaps you could give me a direct link

Sure: Free Pascal Reference Guide, and inside that: 16.4 - Unit Dependencies
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.

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Re: Namespaces UNIT1 does not see unit2
« Reply #17 on: September 04, 2020, 05:27:39 pm »
Tanks Howardpc for your enlighten exposition. I think I understand the code a little better.
After all was not so a simple task for a beginner tu tray to convert the program. I have see programming in Algol in 1970 during my time at the University in Germany, but done professionally totally different jobs. But I have liked programming ever since, and since Algol is similar to Pascal I though I give Delphi a try . And here I am

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Re: Namespaces UNIT1 does not see unit2
« Reply #18 on: September 04, 2020, 05:59:14 pm »
Thanks Lucamar .I will peruse the guide

 

TinyPortal © 2005-2018