OOP in [Free]Pascal 
Author Message
 OOP in [Free]Pascal

Hi, All!

When I studied programming in C and Java I was introduced to the concept
of OOP (although I did not like that much). Before that I had studied
programming in Turbo Pascal for two years, but there was no mention about
OOP.

Now, just for self-educational purposes I decided to learn OOP in Pascal.
I am learning it using book that concernes OOP in Turbo Pascal 5.5. But in
Free Pascal documentation I found place where it is mentioned, that the
compiler supports not only TP style objects, but also delphi style
classes. What are those, are they more similar to the Java/C classes? So
far I have understood that Objects (in Pascal) are structured types, that
also contain funtions.

In general, I would like to ask, what would have more point - learning TP
objects or Delphi classes? And if the latter is more reasonable, where
could I find information about that?

Imot Algma

PS. What is the OBJPAS unit for, just for compatibility with Delphi?



Fri, 05 Aug 2005 19:18:45 GMT  
 OOP in [Free]Pascal

Quote:

> Hi, All!

> When I studied programming in C and Java I was introduced to the concept
> of OOP (although I did not like that much). Before that I had studied
> programming in Turbo Pascal for two years, but there was no mention about
> OOP.

> Now, just for self-educational purposes I decided to learn OOP in Pascal.
> I am learning it using book that concernes OOP in Turbo Pascal 5.5. But in
> Free Pascal documentation I found place where it is mentioned, that the
> compiler supports not only TP style objects, but also Delphi style
> classes. What are those, are they more similar to the Java/C classes? So
> far I have understood that Objects (in Pascal) are structured types, that
> also contain funtions.

There are some differences between TP-Objects and Delphi-Classes.

TP-Objects:
type TMyObject=object(...)
       private/public
       vars...
       procedures/functions
     end;
var o: TMyObject;
begin o.init; o.doThis; o.done; end;

Delphi-Classes:
type TMyClass=class(...)
       private/public/protected...
       vars
       procedures/functions/properties
     end;
var c: TMyClass;
begin c:=TMyClass.Create; c.doThis; c.Free; end;

Delphi classes are always dynamic variables (just a pointer). They have
to be created by a constructor. Properties can be used.
TP-Objects are not dynamic unless you use ^TMyObject. You only have to
use a constructor if you want to use virtual methods.

Quote:
> In general, I would like to ask, what would have more point - learning TP
> objects or Delphi classes? And if the latter is more reasonable, where
> could I find information about that?

I recommend learning Delphi-style classes.
Documentation can be found in the Delphi online help or in the Free
Pascal manual.
Documentation about classes and objects can be found in the Free Pascal
manual: "Reference guide".

Quote:
> PS. What is the OBJPAS unit for, just for compatibility with Delphi?

Yes. See the FPC-manual (Reference guide)

Wolf



Fri, 05 Aug 2005 20:09:28 GMT  
 OOP in [Free]Pascal

Quote:

> Hi, All!

> When I studied programming in C and Java I was introduced to the concept
> of OOP (although I did not like that much). Before that I had studied
> programming in Turbo Pascal for two years, but there was no mention about
> OOP.
> Now, just for self-educational purposes I decided to learn OOP in Pascal.
> I am learning it using book that concernes OOP in Turbo Pascal 5.5. But in
> Free Pascal documentation I found place where it is mentioned, that the
> compiler supports not only TP style objects, but also Delphi style
> classes. What are those, are they more similar to the Java/C classes?

Java classes are different (because dynamical and automatic). C has no classes,
but if you mean C++, the answer is also no (not dynamical per default)

- Delphi classes are dynamical as in that they are basically a pointer to the
object.
- Creating is done by a constructor, destructing by a destructor.

- Supports inheritance, virtual methods, overloading, properties and, in
 1.1, interfaces.

Quote:
> So
> far I have understood that Objects (in Pascal) are structured types, that
> also contain funtions.

Pretty much the principle yes. But
- objects have relations between them, the so called inheritance, and objects can
  be cast to their parent types.
- Can be instanciated. (iow there is room reserved for the attributes). Like allocating
  space on the heap for a record.

. Actually it is much like a module/unit, but the problem is that they

Quote:
> In general, I would like to ask, what would have more point - learning TP
> objects or Delphi classes? And if the latter is more reasonable, where
> could I find information about that?

- FPC documentation
- Delphi helpfiles on the Borland FTP site.
- Delphi tutorials and books on the net.

Quote:
> PS. What is the OBJPAS unit for, just for compatibility with Delphi?

It is an extension of the System unit that adds the extra stuff Delphi adds to the system unit.
It is automatically USED when going to Delphi modi (-Sd, -S2)


Fri, 05 Aug 2005 22:54:53 GMT  
 OOP in [Free]Pascal
Hi,
by the way: Are there any plans to support C++ Classes with FreePascal? I've
read a C++ Book, and I like the C++ OOP more thant the Delphi way.


Sat, 06 Aug 2005 12:50:32 GMT  
 OOP in [Free]Pascal

Quote:

> by the way: Are there any plans to support C++ Classes with FreePascal?

In the long term maybe one can use classes from a C++ library. That's it.

Not very probable that we will adapt the C++ style for programming IN fpc.

Quote:
> I've read a C++ Book, and I like the C++ OOP more thant the Delphi way.

Just curious; why?


Sat, 06 Aug 2005 18:00:44 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Free and great OOP toolkit for Borland Pascal

2. Free OOP programming tool for Pascal

3. Free OOP tool - GREAT!

4. Free OOP toolbox for BP

5. 1 MB free source code in OOP

6. 1 MB free source code in OOP

7. Free and *great* OOP toolkit.

8. The OOP toolkit - free - complete - great!

9. Free OOP toolkit

10. Free and *great* OOP toolkit.

11. Free OOP tool !

12. Free OOP tool - GREAT!

 

 
Powered by phpBB® Forum Software