Posted By: sysrpl | Sep 15th @ 7:36 PM
page 1 of 3
Comments: 54 | Views: 1559

I've been using C# and Visual Studio at work, but I still keep coming back to Delphi. Here what I think Delphi has over C# and VS.

Some features I prefer/need:

sets and set operations
virtual constructors
deterministic and virtual destructors
virtual static methods
messaged based method and DefaultHandler
implementation through delegation
assign and assignto
property promotion
published section
access to source code examples of property editors, component editors, experts, design time support
full library source code
interface and implementation sections
design time binary/string properties, easy support to stream to/from dfm
class types
global level procedures and functions
block declarations
better com support
better windows api support
better visual control library
both graphic and windowed controls
onevents rather than method sounding events (click in c# vs onclick in delphi)
native code, no runtimes
asm, mmx, sse, sse2, sse3

Importantly from above organization

Block delcaration and interface/imeplementation sections really make a difference in organizing code. With the interface section I get to see the outline of the class/types, and with block declaration I see everything organized in a strict order.

 

class
  private
    field
    field
    field
    method
    method
    method
  protected
    method
    method
    method
    property      
    property      
    property      
  public
    constructor
    destructor
    method
    method
    property
    property
  published
    promoted property
    promoted property
    promoted event
    promoted event

 

I love the above. Delphi forces you to place fields before methods, methods before, properties, properties before events. Delphi does not put the implemenation and declaration together, C# is nowhere near this organized. C# is a bunch of implemenation code rolled into declaration code, usually appearing in no organized pattern (ie.e things come in any order).

 

With C# you cannot block declare things such as:

 

const
  WM_A = WM_USER;
  WM_B = WM_A + 1;
  WM_C = WM_B + 1;

  WM_D = WM_C + 1;

 

Regarding class types, you can't do this in C#:

 

procedure ExecuteForm(FormClass: TFormClass): Boolean;
begin
  with FormClass.Create(Appllication) do
  try
    Result := ShowModal = mrOk;
  finally
    Free;
  end;

end;

 

To me, property promotion is also a big deal. I wrote a winform control in C# recently and was quite disappointed to learn of all the derived properties which were exposed as public which I would preferred to have hidden.

The windows control section of is also much more powerful. The base control, graphic control, custom control classes have so many more methods.

Event naming in C# irks me to no end. I really want to know if something is an event by looking a it. OnClick to me automatically tells me, "Hey, I'm a click event", whereas Click seems to me like an action (method) "Click the button". Then c# messes up events further with their virtual names using On (it's Do in Delphi).

Oh, and I'm not totally sold on EventArgsTypes. It is so annoying in VS to break open the help, searching for the an event to see the type, clicking the type to get to the about page for the type, clicking the EventArgsTypes, then click members, and finally learning what the parameters actually are. In case that want click, here it is in diagram form:

In VS highlight MouseDown in the property grid -> F1 help pops up
public event MouseEventHandler MouseDown -> click MouseEventHandler
public delegate void MouseEventHandler(Object sender, MouseEventArgs e) -> click MouseEventArgs
public class MouseEventArgs : EventArgs -> click members
MouseEventArgs Members -> scroll down past the constructor and methods inherited from system.object
Ah what type is "Button"? -> click "Button" to find public MouseButtons Button { get; }

 

In Delphi (using version 7 here) highlight MouseDown in the object inspector -> F1

 

type

  TMouseEvent = procedure (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) of object;

 

Boom! Now that was a lot easier. The event has 5 parameters, and Button is type TMouseButton.


That's enough for now. You get the idea.

You can't compare lemons with strawberries, and I think you got some stuff wrong e.g. "better visual control library" among others, a fairer comparison would be Delphi.NET with C#, you also seem to dismiss BCL from C#'s side. Just some personal thoughts...

WinForms is largely deprecated by WPF though, which is extremely powerful and expressive.  WinForms is more of a Win32 wrapper library, although they added some nice things in 2.0 like DataGridView.  I still use WinForms for new code because its very lightweight, it depends on the requirements.  

 

I'd like to hear how COM Interop is better in Delphi though, considering its been practically transparent when I've done it in .NET.

W3bbo
W3bbo
The Master of Baiters

It looks to me like you just took the "differences between Delphi and C#/.NET" article and just listed the features in Delphi that aren't in C#.

 

A lot of the stuff you describe are moot points: C# doesn't have "globals" because that's what static class members are for, we know from C that a single global namespace is a bad thing and that's why it doesn't have it. Other concerns are subjective, like "better foo library": there's no way to prove that.

 

The CLR makes use of machine-specific processor instructions when it's available to it, like MMX and SSEn. Assembly code isn't allowed in .NET assemblies because otherwise it wouldn't be portable, which is by-design. I consider this an advantage over Delphi's machine-specific approach.

 

Also, what are you talking about when you say "virtual static methods"? there's no such thing. In .NET a derived class can implement new static members with names that "override" (or shadow, rather) the old one with the 'new' modifier keyword. Otherwise you could be using singleton instances and factory patterns.

actually in C# it would be a one liner, but I think you know that...

 

 

I think its great that delphi has shell32.dll stubbed out for you.  I assume they update the bindings everytime a new version of Windows comes out?  But what does this have to do with COM interop?  COM seems to have little to do with your example besides the fact you are calling some shell functions that take COM objects as parameters.  In .NET I can reference a COM library in visual studio, and instantiate the objects like first-class .NET objects, or implement a COM interface like any other managed interface.  I don't see how Delphi improves on interop with "Generic COM Library".

vesuvius
vesuvius
Das Glasperlenspiel

Maybee the langage designer of Delphi was better than the language designer of C#

True, but your example in Delphi only works because the types from Shell32.dll have been pre-wrapped for you. If you're going to compare C# and Delphi in this respect then you need to write the Delphi code without using the built in helpers for shell32 (otherwise the .NET BCL methods are just as valid and a lot easier).

 

 And while I agree that some of the structure inherited from Pascal is quite nice for forcing tidy code, it also inherits the fact that object-orientation is clearly a bolted on afterthought. Polymorphism in Delphi, for one thing, is just plain ugly.

 

Other things: Virtual Constructers are just syntactic sugar around class factories, which are easily done in C#. Global anything is just plain horrid. And I'm not sure I really see your point on the EventArgs things, but then maybe that's because I let Intellisense tell me rather than breaking my workflow to have a search through the help files. 

TommyCarlier
TommyCarlier
I want my scalps!

That must have been it. Wink

exoteric
exoteric
I : Next<I>

"A lot of the stuff you describe are moot points: C# doesn't have "globals" because that's what static class members are for, we know from C that a single global namespace is a bad thing and that's why it doesn't have it. Other concerns are subjective, like "better foo library": there's no way to prove that."

 

No reason to have "globals", just namespaced functions. Extension methods mitigate this.

exoteric
exoteric
I : Next<I>

Technically speaking it was not the same set of people Wink

I agree with you on the whole EventArgs thing. I never understood how that makes things easier. It just means I have to make pointless wrapper classes for one property for my own events if I want my events to look like the built-in ones.

Couple of points about the EventArgs stuff:

 

- This makes possible for a "future version" to provide more information with an event. You can add fields and properties to the event args class but you cannot add parameters to an existing delegate.

- It allows the event handler to return information to the event invoker (see CancelEventArgs) without using ref/out paramters.

- The event args classes can form a hierarchy (see what inherits from WinForms's MouseEventArgs for example).

- Some event args classes have more than 2-3 properties. How do you like a function with 8 parameters from which most of the time you only need 2?

 

And for the common case where you need to pass only one value to an event you can create an EventArgs<T> if you find creating a new class such a hassle.

Dr Herbie
Dr Herbie
Horses for courses

+1

 

EventArgs is a good OOP design because you can change the structure of the parameter class to add more properties\methods without affecting method signatures all over the code.

I do this in normal code too (where there is no way around extensive parameters).

 

Herbie

No you're incorrecting referring to a bunch of random DLL exports as COM interop, you're just using pinvoke.  A type library is how you make COM components usable by other devs.  If I'm going to be using COM components in code its safe to assume they're in a type library?

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...

A type library is required to make COM usable in pretty much any language except C/C++ (in which case you can make do with the headers generated by the IDL compiler). With nothing but the DLL (no type libraries or headers), COM objects are as good as unusable.

The only thing I find truly frustrating between .NET and Delphi is a linker (does anyone remember those) is missing from .NET.  I understand the framework is supposed to be installed, but in a corporate environment there are multiple versions of .NET, a computer may have .NET 1.1, 2.0, 3.0, 3.5...etc....I was a true believer in the .NET concept, but in the real world where we have web servers with multiple versions of the framework running and Microsoft has lost the concept of "backwards compatibility"  I traded dll hell for .NET hell.  I work for the local government we don’t have the budget to rewrite code for every new version of the framework.  The irony of this is we have Delphi applications that run on Vista better than the .NET applications.  With Delphi I build and it links dependencies, I can copy just the executable to another machine and it just works, like magic.  I guess I would say Microsoft needs to give us a linker or make the framework more backwards compatible. 

 

Also I know if ILMerge (But it does not play well with third party assemblies at least that has been my experience)

http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx

 

My $0.02

 

You do make an interesting argument for Delphi.

vesuvius
vesuvius
Das Glasperlenspiel

You do have valid arguments, and win some, lose some. People always think that just because some new language has come along, all the previous languages are obsolecsent.

 

Not if Regnwald has anything to do with it Big Smile

 

I am lucky enough to have programmed MSM Server/Mumps, Delphi, then C++ and finally C#/Visual Basic. For all these languages, there are some very big companies here in the UK still harnessing all of them, even as I write this post.

 

Thus far programming wise, I miss less using .NET though, being a full on WPF developer (dayjob). I still think Windows Forms was and is harder than WPF, and all these people diminishing Winforms developers have a thing to learn or two. WPF itself is riddled with bugs at present (.NET 3.5) and will take a few more iterations before it fully realises it's potential.

 

Software changes do not happen overnight, whatever the language. You are probably in a unique position in that you can judge the best tools (be it delphi or whatever) for the job, and not choosing tech because it is the latest and greatest. Thats not to say one cannot use something new, because in some situations there is a business need to use Silverlight for example, but Stack Overflow is an awsome website  and all written in pure HTML and dollops of AJAX.

 

You are a leader and not a follower.

Nope, type libraries are not required but yes, if you don't have the type library you need either the C/C++ header or the IDL file. And if you have any of these 3 you can use a COM component from C#.

 

To make it short: it is possible to use a COM object from C# even if you don't have a typelib and even if the object doesn't implement IDispatch.

 

page 1 of 3
Comments: 54 | Views: 1559
Microsoft Communities