PDA

View Full Version : Delphi and Object Pascal in FPC?



WILL
28-08-2005, 12:09 PM
I'm just wondering... there is a Delphi Mode for the FPC, but is this a required mode to support Object Pascal?

And how does one define what dialect of the language is supported or are all dialects supported by default depending on your code? If so, how is that determined?

Being as Object Pascal is it's own standard, dispite what Borland seems to think and no matter how confused the general public gets, Free Pascal does support it in this respect, but how much and how?

A question I think that is often passed over for more Delphi/Borland-esk type tainted questions that only confuse the point.

Bart
28-08-2005, 05:26 PM
Delphi is an Object Pascal dialect if i'm right. FreePascal supports Object Pascal by default but if you want to use Delphi additions (such as Result is, if i'm right) you should set the mode to Delphi.

You can also set other dialects such as Mac Pascal, Turbo pascal, GNU pascal. You should use the compiler derective $mode for it.

cairnswm
29-08-2005, 05:41 AM
The Delphi mode is also needed to use the Delphi method of pointer hiding.

WILL
29-08-2005, 08:52 AM
Well, Delphi is the IDE... many people follow Borland's (--or should we say Inprise's :evil:) BAD example and calls Object Pascal Delphi. :P WRONG!!!

I'm sorry for those that actually believe that Borland did something so great and wonderful since Delphi was created and along with it a revamped dialect of Apple's version of the original language called Object Pascal, up until whatever version it was (I think 5 or 6 since that was about when someone in management started with all this funny naming nonsense) that justifies renaming a language that had been called what is has been for so many years, simply because Borland had an identity crisis and forgot how to name things properly. :lol:

It's sick really. :P


Hmm... so is it fair to say that you cannot use Object Pascal unless you set 'Delphi Mode'? I'd opt that this Delphi Mode be changed to 'Object Pascal Mode'. :) Being as the mode's name will last longer, I think.

I mean you could continue to follow in Borland's foot steps, but then again we'd have to come up with 20 different names for each port of Free Pascal just because it's running on a different platform. :lol:

cairnswm
29-08-2005, 10:46 AM
You can use Object Pascal in FPC without Delphi Mode. You cannot use Delphi Pascal in FPC unless you set the Delphi Mode On.

Object Pascal requires you to manage pointers etc.


Item := ^OtherItem


While Delphi Pascal hides these pointer activities from you


Item := OtherItem;


Object Pascal handles Objects in a similar method to C++ - one of the big reasons I dislike C++ so much. Delphi Pascal understands that passing a pointer to an object to another object means you want to pass a reference to that object and not actually pass the address of the object pointer to the other object.

This is the reason I like Delphi so much. The standard silly memory manageemnt mistakes are less likely as it already abstracts that away from the developer.

PS. My understanding is that Delphi is a derivitive of the pascal language now. It is now considered its own language and is no Longer considered pure pascal. (Just like Oracle PL/SQL is no longer considered SQL but is its own dirivitive)

Almindor
04-09-2005, 05:04 PM
Not so true, let me elaborate:

Free Pascal supports atleast 5 dialects (Tp, Fpc, ObjFpc, Delphi, MacPas) maybe more, but I know only these.

Fpc and TP dialects are NOT object oriented, they are old procedural style along with not-hiding pointers etc. Fpc dialect differes in that it allows later non-OOP additions like overloading operators etc.

MacPas is a macintosh original dialect and I know nothing about it since I never even touched a mac :)

ObjFpc and Delphi dialects ARE BOTH OBJECT ORIENTED. They are VERY common. In fact I bet you could make "auto-translators" for them in one day or so. Let me write the difference I know about:

Both allow CLASSES AND OBJECTS. Both disallow mixing them together(ie assignment) because things like RTTI and VMT are different in them.

Delphi mode is more restrictive for order of methods and variables in classes(members) like for example:

TOne = class
procedure One;
x: integer; // error, this is impossible in delphi and delphi-mode fpc

The above example is valid in objfpc mode.
Delphi mode hides pointers as you sayed. This is NOT some hyper advanced feature. It's actualy a bad practice IMHO because it makes the code not-so-obvious.
Objfpc requires explicit dereferencing.
Delphi mode has limitations when it comes to array handling(perhaps it change IIRC delphi finaly added this functionality as of late). You couldn't make a pointer and use it directly as an array IE:

var
p: Pointer;
p[2]:=something;

This is valid in objfpc mode. ObjFpc also allows things specific for FPC which are not yet in delphi. Global properties, and other funky stuff, operator overloading etc.

To sum it up the difference between ObjFpc and Delphi modes is that ObjFpc mode requires explicit dereference and adds FPC specific addons which are not in Delphi, while in turn Delphi mode is specific for staying compatible to Delphi and it's limitations. ObjFpc mode has limitations too like for example enforcing different names in classes and methods etc.(make your own opinion)
Most important is tho they both are OOP in classes sense.

I myself use ObjFPC mode since I don't plan to touch delphi (I work in FreeBSD/Linux and make things as cross-platform as possible so delphi is not an option)
Using Delphi mode is good if you want to be compatible with delphi + if you don't need one of the more advanced features of free pascal.

Hope this helps :)

WILL
04-09-2005, 05:58 PM
Hmm indeed it does. A lot actually. I think it might even have opened up some other eyes to the implimentation of Object Pascal in FPC.

Thanks guys for your help! ;)

Raskolnikov
11-09-2005, 10:13 AM
Fpc and TP dialects are NOT object oriented


How so? both Turbo Pascal and FPC support Objects; am i missing something?

Almindor
16-09-2005, 08:59 AM
I ment Classes. You can use old style stack-based "object" in them but not classes.

Sly
16-09-2005, 01:18 PM
Sometimes those "old-style stack-based objects" have their distinct advantages over the newer class types. For example, using one in local scope does not mean you have to have a call to allocate some memory to hold the class instance, with a try..finally statement to make sure it gets freed. You can also easily create an array of them. You can initialize that array to zero with one call to FillChar. And the list goes on. Borland call them deprecated. I call them useful.

Almindor
19-09-2005, 09:12 PM
Well the only two downsides are that they are not interassignable with classes and that they don't have a full blown RTTI. Otherwise they are actualy faster too.