PDA

View Full Version : New Delphi features since Delphi 7



savage
02-05-2007, 08:50 AM
CodeGear (http://dn.codegear.com/) has posted a list of features that have been added to the latest version of Delphi, compared to what was there back in version 7.0.

Language features : http://dn.codegear.com/article/34324

IDE features : http://dn.codegear.com/article/34323

VCL features : http://dn.codegear.com/article/34325

dmantione
02-05-2007, 09:41 AM
It is nice to see Borland has restarted development on its compiler. Sadly, many new features are .NET-isms.

marmin
02-05-2007, 09:55 AM
Class type
Should be in any pascal compiler :D

WILL
02-05-2007, 02:26 PM
This is interesting indeed.

I am more interested in the language specific enhancements out of all of this. At least back when I started coding the whole focus was on language and coding practices (in code) not so much all the pretty menus and buttons and code manipulating algorithms.

I've heard it said recently that Object Pascal hasn't evolved much in the last while. It could be true to say that, but at the same time, which Object Pascal are we talking about?

I'd love to see CodeGear take the steps to getting a published standard for the 'Object Pascal' language that Delphi for Win32 and future Delphi suite compilers would conform to. It would make it a more tangible language for other major software tool developers to make use of.

This includes the new features that they have listed at the link provided there. They seem pretty decent additions to the language that we know now.

dmantione
02-05-2007, 04:28 PM
Well, we've repeatedly tried to get usefull contacts with Borland about this in the past. Without any succes, on the contrary, examples:

* FPC had procedure overloading since version 0.5. When Borland released Delphi 5, they had managed to add it in an incompatible way to Delphi.
* FPC implemented operator overloading in version 0.99, intentionally compatible with GNU-Pascal's syntax. With Delphi .NET, Borland implemented operator overloading in an incompatible way.
* To be able to call C functions like printf, we used the well known the "array of const" syntax. For Kylix, Borland had to invent a "varargs" procdir.

I'm going to post a reaction to Nick's blog, Borland got a bit more open in recent years, lets see if there will be a reaction.

WILL
02-05-2007, 04:54 PM
An important thing to note Daniel, is that CodeGear is not the same old Borland. Its literally a NEW company under new management.

I'd suggest taking a fresh page to them as any association with them and former Borland would not be very well received. I'm sure that not of of the current CodeGear team have jars full of warm fuzzes about Borland/Inprise memoirs sitting on their windowsills at home. :)

And I too agree that what I've seen of these guys is far FAR better then the old Borland house of yesteryear.

WILL
02-05-2007, 05:05 PM
I like the new box design too. :)

http://www.codegear.com/article/34017/images/34017/big-shot.jpg

chronozphere
02-05-2007, 05:36 PM
Huh... Records with methods :shock: Aren't that just classes??

I like the operator-overloading and the for..in..do, but i consider the rest of the language changes less usefull, since AFAIK it doesn't enable us to do astonishing new things.
That said, i think the pascal language has all the features, an
average programmer like me needs.
but ehh... Class vars, consts etc can be very usefull for adding structure to your code though. ;)

marmin
02-05-2007, 06:08 PM
Is it me or have they changed logo in the weekend? The box looks nice.. stylish

Robert Kosek
02-05-2007, 06:11 PM
Records with methods are like super-overloads. So I use it in my color unit to blend between colors with just one function call and return my special record. It's not technically a class though, so it is more compact in memory AFAIK.

Pretty handy actually, if you ask me.

Setharian
02-05-2007, 08:27 PM
records with methods are handy, the only thing I do not understand is why they are not inlined by the compiler when they are marked so....

Mirage
03-05-2007, 03:45 AM
The only useful addition I see is sealed classes/methods.
Inlining of course useful as well, but it's not working in most important cases (assembler functions).

jdarling
03-05-2007, 01:36 PM
Yes, Records with Methods are basically classes. The difference is in the VMT and how its transported with the data-structures. Though, Records with Methods isn't anything new, its been around since records and method pointers existed :). CG just made it "easier" to utilize.

Personally, I'd be more interested in seeing the list of things that Borland (I can't say CG yet) screwed up or didn't do since Delphi 7 that the developers (users) strongly pushed for. This listing is greater in length then what they have done right overall.

On the topic of CG, I see the same bad habits starting to show in CG as were found in early Borland. Bad marketing, poor target focus, and "new features" that were lightly requested if requested at all. I'll give credit where credit is due though, integrating FastMM and other freeware solutions into the distro with full native support was a good move.

dmantione
03-05-2007, 04:17 PM
Well, the difference between records with methods and classes is clear to me. What is absolutely not clear to me is the difference between objects and records with methods.

About focus: CG has clearly started work on 64-bit and Unicode-VCL, and has been busy with Vista support too. This is a *lot* of work, it is too early to make conclusions here.

jdarling
03-05-2007, 04:39 PM
An object has a VMT (Virtual Method Table) so that all objects point to the same methods. Change the root method and you change it for all objects. In a record with methods there is no VMT thus the record contains a full copy of the method itself. Changing the method in one record does not affect the other records of the same type.

dmantione
03-05-2007, 05:21 PM
This is incorrect:

type t1=object
a,b:word;
end;


... is binary equivalent to:


type t1=record
a,b:word;
end;


Only when you add a virtual method, a VMT is added to the object.

I don't understand your reply about changing methods. How can you change a method in a running program?

jdarling
03-05-2007, 06:02 PM
You compared an orange to an orange :) since compilers are smart enough to optimize an object w/o any methods into a record. Compare it with a method in each and see if its the same. Unless something major has changed under the hood of Delphi then it shouldn't be.

As for changing the method on the fly, you have to change the method pointer to point to a new method or walk the method pointer to the code block and overwrite that block with a new instruction set. Its true polymorphic development.

I'm not going to get into exacts in this thread as its a complicated subject and is way off-topic.

JSoftware
04-05-2007, 11:31 AM
Ahh great find! Those class helpers looks interesting.

I've used operator overloading since I got Turbo Delphi and they are just so extremely nice. All my overloaded operators also work in fpc though.
I for some reason like the delphi implementation better even though the fpc implementation seems more powerfull as it isn't only bound to be sitting in a record already

Class properties are freaking nice. Now I can implement singletons without global variables

savage
04-05-2007, 12:33 PM
Class properties are freaking nice. Now I can implement singletons without global variables

Do you mean static class properties?

JSoftware
04-05-2007, 02:39 PM
No just class properties. These allow me to set a variable in all allocated classes of that type at one time.

I haven't understood the difference between class property and the static class property. Could anyone elaborate?

Chebmaster
28-05-2007, 06:32 AM
Ohhh... If only FPC had class vars... :roll: Then I'd avoid headache with hacking the vmt to store the class-specific indexes when I wrote my persistency system.

Anyone knows if the said aboveapplies to Turbo Explorer? I'm too lazy to reboot my system to WinXP and check for myself. :oops:

JSoftware
28-05-2007, 09:40 AM
I found most of them to work in the win32 edition of turbo explorer

Setharian
28-05-2007, 11:02 AM
Ohhh... If only FPC had class vars... :roll: Then I'd avoid headache with hacking the vmt to store the class-specific indexes when I wrote my persistency system.
class vars are not virtual that is, not every derived class has its own field, they are shared...it's just a form of a global variable tied to the class type and accessible in other classes when declared as public or protected....what you would need is a "virtual class var" which would be class-type specific....such a thing does not exist and I do not even know any language which implements a construct like that....

Chebmaster
28-05-2007, 02:23 PM
class vars are not virtual that is, not every derived class has its own field, they are shared...it's just a form of a global variable
Crap. :evil: I just discovered that by myself. So much for idea to free my prog from the hacks. :(

Chebmaster
28-05-2007, 02:33 PM
Well, there's one idea that *might* work without hacks... All your classes are placed in a solid block of memory, right? It's not that big, they all fit in approx. 100 Kbytes. So if you aren't short of memory, you can create a dynamic array of pointers to your *real* class vars, and treat the classes as integers, substract some offset and use them directly to index the array. Of course, you need some additional code to correct the array size and the offset on the fly if some class doesn't fit.


type
PCVData = ^CVData;
CVData = record
...//your class vars
Fruits: TOranges;
end;
TMyClass = class
...
class function Oranges: TOranges;
end;

var
CVOffset: dword;
CVData: array of PCVData;

...

class function Oranges: TOranges;
begin
<code to check boundaries and grow the array if necessary>
Result:=CVData[(dword(ClassType()) shr 4) - CVOffset]^.Fruits;
end;


-- and no any hacks ^_^

Setharian
28-05-2007, 04:10 PM
yes, this is possible, you could hash the class reference pointer into the array, it would not be that hard :) you just cannot access "inherited virtual fields" this way :)

Mirage
29-05-2007, 06:35 AM
A virtual class variables implementation. With hacks, of course.:)

http://hallvards.blogspot.com/2007/05/hack17-virtual-class-variables-part-i.html

Chebmaster
29-05-2007, 05:35 PM
Almost exactly what I did. Except two facts:
1). in FreePascal VMT is not write-protected, so I didn't stumble to the problem until I ported my stuff to Delphi.
2). VirtualProtect I know, but what the hell does FlushInstructionCache(GetCurrentProcess, Code, SizeOf(Code^)); do? :shock:

JSoftware
29-05-2007, 05:37 PM
It removes cached code from the instruction cache. The snippet just modified the code at runtime. If the cache isn't flushed the old code might be executed

cronodragon
29-05-2007, 05:52 PM
Do records with methods work in the same way as classes in C++, in the way that they are disposed automatically? :?

JSoftware
29-05-2007, 06:33 PM
Do records with methods work in the same way as classes in C++, in the way that they are disposed automatically? :?
I would suspect that still is the case. If the opposite you would logically have to allocate them before they worked :P

cronodragon
29-05-2007, 06:54 PM
I'm translating the book "Physically Based Rendering: From Theory to Implementation" to Delphi.

They use classes and operator overloading to do operations. I tried using classes of Delphi, but soon found that instances are not disposed after operations, instead records do. So I have to transform everything to records, and use overloaded functions instead... and hoping I'll be able to fake inheritance when I need it later on.

If the new Delphi (is Delphi 2007 out?) allows that functionality then I'll finally move from Delphi 7. :D

JSoftware
29-05-2007, 07:10 PM
Couldn't you just use objects?

Delphi 2005 supports traditional records extended with methods and properties

Setharian
29-05-2007, 08:34 PM
records with methods are well records....the record pointer is passed as a hidden "self" parameter in every method for record you declare....so yes since they are allocated on the stack, they are disposed automaticly with function return....

wodzu
30-05-2007, 06:15 PM
I'm translating the book "Physically Based Rendering: From Theory to Implementation" to Delphi.

They use classes and operator overloading to do operations.

I don't think so that Delphi 2007 allows classes overloading(which is not recommended) but is allowing operators overloading for sure.

http://www.excastle.com/blog/archive/2005/11/08/2531.aspx

quite interesting (and one of many) summary;)