Recent

Author Topic: Lazarus Pascal Keywords and Examples  (Read 3312 times)

Aruna

  • Hero Member
  • *****
  • Posts: 574
Lazarus Pascal Keywords and Examples
« on: January 11, 2025, 11:07:46 pm »
Hello Everyone,

I put this together to help refresh 'my' memory on anything Pascal-related that 'I' might have forgotten or that seems unclear. And thought this could be a useful resource to someone new who is not familiar with Pascal? So decided to share.

Lazarus Pascal Keywords and Examples

Will something like this be useful to a newbie? Please do add more code snippets and any suggestions are very welcome.

n7800

  • Full Member
  • ***
  • Posts: 235
Re: Lazarus Pascal Keywords and Examples
« Reply #1 on: January 12, 2025, 02:03:59 am »
Interesting reminder. It would be useful to increase the complexity with each new example, from beginner to professional. Add operator overloading, helpers, interfaces, namespaces, generics and everything that can be found in the documentation and wiki.

Right now from the simple, there are no exit, break, continue, raise, initialization in the declaration, pointers to procedures...

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Lazarus Pascal Keywords and Examples
« Reply #2 on: January 12, 2025, 02:16:08 am »
Nice little summary Aruna. How about dynamic arrays ? And maybe mention {mode  objfpc} as default ?

Its a good idea !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 16516
  • Kallstadt seems a good place to evict Trump to.
Re: Lazarus Pascal Keywords and Examples
« Reply #3 on: January 12, 2025, 11:19:25 am »
real is not really a type anymore so does not belong there unless marked as deprecated and with its alternative aliased to double marked as replacement.
Otherwise you would be documenting wrong behavior.
There is the real48utils unit to help out with legacy code that uses real real....

STOP using real without that context! It is B.I.
« Last Edit: January 12, 2025, 11:25:35 am by Thaddy »
But I am sure they don't want the Trumps back...

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Lazarus Pascal Keywords and Examples
« Reply #4 on: January 12, 2025, 03:36:05 pm »
Interesting reminder. It would be useful to increase the complexity with each new example, from beginner to professional. Add operator overloading, helpers, interfaces, namespaces, generics and everything that can be found in the documentation and wiki.

Right now from the simple, there are no exit, break, continue, raise, initialization in the declaration, pointers to procedures...
Hi @n7800, thank you for the suggestions. I will see what I can do.

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Lazarus Pascal Keywords and Examples
« Reply #5 on: January 12, 2025, 03:37:27 pm »
Nice little summary Aruna. How about dynamic arrays ? And maybe mention {mode  objfpc} as default ?

Its a good idea !

Davo
Hey mate how's things down under? I will add mode objfpc and dynamic arrays ( hopefully soonish.. )

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Lazarus Pascal Keywords and Examples
« Reply #6 on: January 12, 2025, 03:56:10 pm »
real is not really a type anymore so does not belong there unless marked as deprecated and with its alternative aliased to double marked as replacement.
Otherwise you would be documenting wrong behavior.
Hi @Thaddy I will change things to reflect what you have pointed out. Is there anywhere 'I' can find out 'what' has been 'deprecated' ? I mean 'you' knew, which is good and you told me so I can change the html to reflect what is current but 'where' and  'how' did you first find out that real is deprecated? I am asking so 'I' will know where to check in the future.

There is the real48utils unit to help out with legacy code that uses real real....
Thank you I will read up on this.

STOP using real without that context! It is B.I.
I do not know what B.I. means. Behavioral Intervention? Business Intelligence?  Before Installation? Body Integrity? or Bad Interpretation?

Why does your email say: thaddy@-removethispart-thaddy.com (??) why have -revmovethispart- at all if it needs to be removed?

PS: Oh and I stole your animation I liked it so I went and took it: Thaddy's CSS animation-frame Gee-Wow!!

Thaddy

  • Hero Member
  • *****
  • Posts: 16516
  • Kallstadt seems a good place to evict Trump to.
Re: Lazarus Pascal Keywords and Examples
« Reply #7 on: January 12, 2025, 06:56:39 pm »
But I am sure they don't want the Trumps back...

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Lazarus Pascal Keywords and Examples
« Reply #8 on: January 13, 2025, 12:48:48 am »
https://www.freepascal.org/docs-html/ref/refsu5.html

That does not actually say that real is deprecated, just not absolutely defined. I use it from time to time where I need a float but have no concerns about precision. A habit going back to TP perhaps ? Are you saying I should change that to 'single' ?

I like what Aruna is doing here, as a Delphi (1 and 2) user many, many years ago, I found its Help system very useful, little code snippets scattered every where. We have discussed a snippit repository in the wiki but I find, to my surprise, I don't use it. The official documentation (that Thaddy believes in with such fervor) is hard work. Maybe Aruna is on to something here ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

TRon

  • Hero Member
  • *****
  • Posts: 3923
Re: Lazarus Pascal Keywords and Examples
« Reply #9 on: January 13, 2025, 01:37:18 am »
We have discussed a snippit repository in the wiki but I find, to my surprise, I don't use it. The official documentation (that Thaddy believes in with such fervor) is hard work. Maybe Aruna is on to something here ?
fwiw there is code-librarian package in OPM that adds a snippet manager to Lazarus. Can be useful, especially for newcomers but also pretty neat to see other implementations/approaches.

Edit: I forgot to mention jan, a new feature in the making for those that can't live without a trusty assistant .
« Last Edit: January 13, 2025, 01:40:56 am by TRon »
I do not have to remember anything anymore thanks to total-recall.

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Lazarus Pascal Keywords and Examples
« Reply #10 on: January 13, 2025, 02:48:55 am »
https://www.freepascal.org/docs-html/ref/refsu5.html

Feel free to use the css.  ;D
Thank you for the link and also for granting permission to use the CSS. I have dabbled with CSS over decades but what you have done with simple straightforward plain text just took things to a whole other level. Very smooth and classy animation. I was amazed and also highly impressed. I should have technically asked before grabbing it but I was too taken and tempted and wanted to see how hard or easy it was going to be to modify, so I stole it!

This is something I did many years ago and this is also mainly css (about 99% css) enjoy:

 CSS CUBE FOR UBUNTU

1. You should see a fractal 3D cube of sorts once the page loads.
2. Befdre you do anything else please click on an empty white area of teh background this is important.
3. Move the mouse cursor onto the 3D cube you see ( This was done using Blender if I recollect right, it has been so long)
4. Now move mouse cursor onto the smaller cube that rose up out of the larger cube and enjoy the ubuntu sound.

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Lazarus Pascal Keywords and Examples
« Reply #11 on: January 13, 2025, 03:14:32 am »
https://www.freepascal.org/docs-html/ref/refsu5.html

That does not actually say that real is deprecated, just not absolutely defined. I use it from time to time where I need a float but have no concerns about precision. A habit going back to TP perhaps ? Are you saying I should change that to 'single' ?
Davo, have a careful look at the attached screenshot. I am hovering over the 'y' variable.

I also ran this just for kicks:
Code: Pascal  [Select][+][-]
  1. aruna@debian:~/lazarus3/lazarus$ find -type f -exec grep -i 'deprecated since' {} +
  2. ./tools/gir2pascal/girpascalwritertypes.pas:    FTestPascalBody.Add('  //g_type_init();'); // deprecated since GLib 2.36
  3. ./components/opengl/glcocoanscontext.pas:    //Add(kCGLPFAWindow); deprecated since 10.9
  4. ./lcl/interfaces/gtk3/gtk3widgets.pas:  // this is deprecated since 3.8 .add() should be used
  5. ./lcl/interfaces/gtk2/gtk2proc.inc:          // Deprecated since 2.10.
So some things are actually documented in the source as being deprecated I just have to refine and fine-tune my search filter.

I was also wondering why the link @Thaddy sent does not 'specifically' state anywhere real is now deprecated. But this is not a biggie I just found it confusing. Maybe we should have a page in the wiki where it specifically says what is deprecated and why and when and what has now replaced it?  How difficult can that be to do? And the link @Thaddy sent says 'The Real native type is processor dependent, but it is either a Single or a Double.'

I like what Aruna is doing here, as a Delphi (1 and 2) user many, many years ago, I found its Help system very useful, little code snippets scattered every where. We have discussed a snippit repository in the wiki but I find, to my surprise, I don't use it. The official documentation (that Thaddy believes in with such fervor) is hard work. Maybe Aruna is on to something here ?
I have no idea if any of you ever used something known as the Norton Guides. This was our go-to and Clipper resource that was a god-send that literally saved us many hours of searching for information that was closely and jealously guarded by those who knew from experience or had the $:$$ to go purchase the books which we did not. So the point is Norton Guides had a description of the command and how to use it and more importantly a code snippet you could copy and paste into your editor and compile and run and test and learn from and extend. I am trying to do something similar for my own journey of learning with Lazarus IDE and Free Pascal and if folks find it useful I will gladly share. 

Davo if you have any *remote* work please send it my way times are starting to get a bit rough up here in the great white north. And thank you for the kind words and support always.

« Last Edit: January 13, 2025, 03:22:36 am by Aruna »

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Lazarus Pascal Keywords and Examples
« Reply #12 on: January 13, 2025, 05:34:52 am »
Code: Pascal  [Select][+][-]
  1. aruna@debian:~/lazarus3/lazarus$ find -type f -exec grep -i 'deprecated since' {} +
  2.  
  3. ./tools/gir2pascal/girpascalwritertypes.pas:    FTestPascalBody.Add('  //g_type_init();'); // deprecated since GLib 2.36
  4. ./components/opengl/glcocoanscontext.pas:    //Add(kCGLPFAWindow); deprecated since 10.9
  5. .......
So some things are actually documented in the source as being deprecated I just have to refine and fine-tune my search filter.
I found 15K uses of 'deprecated', so, maybe your search term is a bit restricted ! I see several deprecated warnings (or notes?) when I compile my app so they are sure in there. But nothing when I declare a var as 'real'.

Quote
Maybe we should have a page in the wiki where it specifically says what is deprecated and why and when and what has now replaced it?   
These things are often mentioned in release notes but they take some searching.

Quote
Davo if you have any *remote* work please send it my way .....
Not me I am afraid. Have been retired for some time now, the organizations I were involved no longer exist, eg https://en.wikipedia.org/wiki/Melbourne_Bioinformatics I am quite sure their demise was not, ever, due to my leaving but there is a pattern .....

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5851
  • Compiler Developer
Re: Lazarus Pascal Keywords and Examples
« Reply #13 on: January 13, 2025, 09:11:42 pm »
Right now from the simple, there are no exit, break, continue, raise, initialization in the declaration, pointers to procedures...

Please note that Exit, Break and Continue are not keywords. They are intrinsic identifiers declared in the System unit.

 

TinyPortal © 2005-2018