Forum > General

OOP in FreePascal

(1/3) > >>

MuteClown:
Hey,
another noob question from me ::)
I have been trying to figure out how OOP works in FeePascal, but only confused myself. I have not found a tutorial out there on how it works, and have been trying to figure out exactly how it works from the docs. I have done some small OOP in C++, but can't seem to get it in FreePascal.
Was hoping someone could write me a quick example showing me how its done, i should be able to figure it out with an example. Or if someone knows a tut on it that be great, i read the docs and off the wiki, but TBH not very help just made me confused. 

osvaldotcf:
Perhaps:
http://pressobjects.org

MuteClown:
I have been reading and rereading pieces of the doc, and starting to get whats going on. Still iffy on few things.

AH whats the difference between an Object and a Class?
All it said was that Objects are stored on the Stack and Classes on the Heap while store a pointer on the Stack. All i know about Heap and Stack is that, stack is where the data is stored before run time and heap stores the data during run time, correct? With each one what is gained or lost with these different methods of storing the data?
Where should i be using one over the other?   

Leledumbo:
First, you can read this.

--- Quote ---All i know about Heap and Stack is that, stack is where the data is stored before run time and heap stores the data during run time, correct?
--- End quote ---
Correct.

--- Quote ---With each one what is gained or lost with these different methods of storing the data?
--- End quote ---
Stack allocated objects are added to your final executable size, so your program will get bigger if you use them much. However, the access is fast since they're already created. Heap allocated ones are just the opposites.

--- Quote ---Where should i be using one over the other?
--- End quote ---
Consider size and speed of your program, which one you need more.

Zoran:
Classes are introduced in Delphi Pascal language and their usage was encouraged over older Objects from Turbo Pascal.
With classes you have full OOP possibilities. Have in mind also that LCL, as well as Delphi's VCL, is fully built on classes aproach. There is actually nothing you can do with objects, that you cannot do with classes.
You might gain some extra speed with objects, but I'd advice classes, at least there is much more other peoples code, you will have to read code with classes all the time. Old Turbo Pascal objects are almost abandoned in new code, so for a beginner object aproach can make a lot unneceserry confusion.

So, my advice is -- start learning OOP with classes.
Note that the term "object" will be used often there, though, but it will have nothing to do with another aproach. Try to forget that object aproach even exist, I might be wrong, but that is my advice for an easier start.

Navigation

[0] Message Index

[#] Next page

Go to full version