Forum > Beginners

With "class-name" do methods?

(1/4) > >>

ojz0r:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TMyClass = Class        procedure One;        procedure Two;        procedure Etc;end; procedure TMyClass.One;begin...end; procedure TMyClass.Two;begin...end; procedure TMyClass.Etc;begin...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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---With TMyClass do begin        procedure One;        begin        ...        end;         procedure Two;        begin        ...        end;         procedure Etc;        begin        ...        end;end; // with class 
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)

marcov:
There is no such way, as definition and implementation can be in separate parts of the sourcefile (header/code aka interface/implementation)

ojz0r:
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?

marcov:

--- Quote from: ojz0r 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?

--- End quote ---

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:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version