Recent

Author Topic: With "class-name" do methods?  (Read 4211 times)

ojz0r

  • Jr. Member
  • **
  • Posts: 61
With "class-name" do methods?
« on: November 11, 2021, 02:44:02 pm »
Hello all.

I have a, maybe stupid, question regarding objects/classes/advanced records and their methods.
Lets say i have created a new class with some methods like this example:
Code: Pascal  [Select][+][-]
  1. type TMyClass = Class
  2.         procedure One;
  3.         procedure Two;
  4.         procedure Etc;
  5. end;
  6.  
  7. procedure TMyClass.One;
  8. begin
  9. ...
  10. end;
  11.  
  12. procedure TMyClass.Two;
  13. begin
  14. ...
  15. end;
  16.  
  17. procedure TMyClass.Etc;
  18. begin
  19. ...
  20. end;

Is there any way to do it like this to encapsule every method to the specific class (to reduce the typing of the specific class):
Code: Pascal  [Select][+][-]
  1. With TMyClass do begin
  2.         procedure One;
  3.         begin
  4.         ...
  5.         end;
  6.  
  7.         procedure Two;
  8.         begin
  9.         ...
  10.         end;
  11.  
  12.         procedure Etc;
  13.         begin
  14.         ...
  15.         end;
  16. end; // with class
  17.  

When i tried to compile a test program it throwed a ""BEGIN" expected but "WITH" found".

Any expert thoughts?

(My FPC version is 3.3.1)
Just trying to learn.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: With "class-name" do methods?
« Reply #1 on: November 11, 2021, 04:08:47 pm »
There is no such way, as definition and implementation can be in separate parts of the sourcefile (header/code aka interface/implementation)

ojz0r

  • Jr. Member
  • **
  • Posts: 61
Re: With "class-name" do methods?
« Reply #2 on: November 11, 2021, 04:35:59 pm »
To bad, that would have been a neat feature.

Is there any point in petitioning it to be added or would this be seen as redundant and not worth wasting precious developement time on?
Just trying to learn.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: With "class-name" do methods?
« Reply #3 on: November 11, 2021, 05:28:42 pm »
To bad, that would have been a neat feature.

Is there any point in petitioning it to be added or would this be seen as redundant and not worth wasting precious developement time on?

To me, it doesn't make sense, and seems like redundant copying from languages which subscribe to different paradigms.  You can always file a bug, but in my experience, purely syntactic suggestions that don't solve problems are rarely added anyway.

ojz0r

  • Jr. Member
  • **
  • Posts: 61
Re: With "class-name" do methods?
« Reply #4 on: November 11, 2021, 06:18:14 pm »
Perhaps its my inexperience talking. Pascal is my first and only language so i don't know the other paradigms, only been using it for hobby use since january.
I do all my programming in gnu nano then compile with FPC so this "with" just stoke me as a shortcut eliminating the repetetiveness of adding the class name to the method, but if there's been no mentions of this so far then its probably my inexperience.

Thank you for clearing it up.
Just trying to learn.

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: With "class-name" do methods?
« Reply #5 on: November 12, 2021, 01:03:11 am »
I believe the IDE has a feature that allows you to make the IDE generate all the blank entries in the implementation section.

So when doing so I believe code tools has it. etc..

I would need to look it up but I know its there.
The only true wisdom is knowing you know nothing

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: With "class-name" do methods?
« Reply #6 on: November 12, 2021, 02:36:33 am »
That is called code completion, I use it a lot. It support class too:
https://wiki.freepascal.org/Lazarus_IDE_Tools#Class_Completion

dbannon

  • Hero Member
  • *****
  • Posts: 2802
    • tomboy-ng, a rewrite of the classic Tomboy
Re: With "class-name" do methods?
« Reply #7 on: November 12, 2021, 04:11:18 am »
I do all my programming in gnu nano then compile with FPC so this "with" just stoke me as a shortcut eliminating the repetetiveness of ....

As Jamie and Handoko suggest, the Lazarus IDE will do that, and a great deal more for you, while Lazarus may seem to be all about making GUI apps, its also very comfortable in making 'pure FPC' ones.  You will find you get syntax highlighting, on line help and code completion.

For example, if you wrote your declaration of "procedure Etc;", with the cursor on Etc, Ctrl-shift-C will have the IDE create the procedure template for you, down in the implementation section. That save a lot more typing that your suggested model.

Join us, do not be afraid, you will be assimilated ....

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

440bx

  • Hero Member
  • *****
  • Posts: 4070
Re: With "class-name" do methods?
« Reply #8 on: November 12, 2021, 06:34:14 am »
Join us, do not be afraid, you will be assimilated ....
We are the Lazarus.  Typing is futile.  You will be assimilated. :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

ojz0r

  • Jr. Member
  • **
  • Posts: 61
Re: With "class-name" do methods?
« Reply #9 on: November 12, 2021, 09:28:50 am »
As Jamie and Handoko suggest, the Lazarus IDE will do that, and a great deal more for you, while Lazarus may seem to be all about making GUI apps, its also very comfortable in making 'pure FPC' ones.  You will find you get syntax highlighting, on line help and code completion.

I wish i was able to use Lazarus more frequently.
I'm in a perculiar situation. My daytime work is not related to this kind of programming (electrical/automation engineering so commercial control systems) so Pascal is just a hobby and brain exercise. With a toddler at home and another on the way i don't have time to spend the nights infront of the main computer - so all coding is with Nano on Termux on my android phone, that way i can code when i get a few minutes of free time.
I'm not complaining though, Nano and 6" screen was clunky in the beginning but i got used to it  8-)
Just trying to learn.

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: With "class-name" do methods?
« Reply #10 on: November 12, 2021, 10:57:54 am »
You can consider to buy yourself a portable mini computer. Pyra seems good, it comes with Debian Linux so you can install Lazarus.

https://pyra-handheld.com/boards/pages/pyra/

ojz0r

  • Jr. Member
  • **
  • Posts: 61
Re: With "class-name" do methods?
« Reply #11 on: November 12, 2021, 11:23:03 am »
Thats true, in that case i would probably get a Steam Deck (roughly same price but more power) - but that would mean hauling another device. The phone is always with me as is.
For mobility i could set up a raspberry pi 4 and VNC into it for Lazarus.
Just trying to learn.

Thaddy

  • Hero Member
  • *****
  • Posts: 14393
  • Sensorship about opinions does not belong here.
Re: With "class-name" do methods?
« Reply #12 on: November 12, 2021, 12:26:07 pm »
With a toddler at home

Oh dear. My youngest is thirteen and again behaves like a toddler....Or worse...
(the eldest is 28 and "somewhat" under control. She has her M.A, no further costs....)

This is relevant, moderators, because the parent concept is essential to OOP.

It also takes a lot of debugging skills... :-X :P
« Last Edit: November 12, 2021, 12:45:11 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

ojz0r

  • Jr. Member
  • **
  • Posts: 61
Re: With "class-name" do methods?
« Reply #13 on: November 12, 2021, 06:47:03 pm »
Yes it certainly seem to go in waves.

My son inherited bad methods from me that are impossibe to debug  %)
Just trying to learn.

Thaddy

  • Hero Member
  • *****
  • Posts: 14393
  • Sensorship about opinions does not belong here.
Re: With "class-name" do methods?
« Reply #14 on: November 12, 2021, 08:36:33 pm »
Yes it certainly seem to go in waves.

My son inherited bad methods from me that are impossibe to debug  %)
I can give you only a bit of advice:

These words do not exist: Robux, creditcard,... O:-)
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018