Thanx for the explanation rob.  I'll definitely have a look at it!

from Robert Meek dba Tangentals Design


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Rob Kennedy
Sent: Tuesday, January 10, 2006 2:16 PM
To: Borland's Delphi Discussion List
Subject: [SPAM]Re: Class helpers and StringList alternatives

Robert Meek wrote:
> Also that's interesting about TObject.  Has it been that way since
> version 1?

Of course not. Before version 8, there was no other class for 
TObjectHelper to help. Class helpers were introduced so that Borland 
could tack the old TClass and TObject methods that we're used to onto 
.Net's System.Object without having to write a completely separate class 
hierarchy. The .Net class is missing several methods that Delphi 
programs use, especially ClassName, Dispatch, and Free.

Delphi's TClass is sort of like System.Type, but not quite. TObject is 
sort of like System.Object, but not quite. Class helpers aim to bridge 
the gap.

Class helpers cannot include any instance variables. They can only 
contain methods and class variables. This is because the class helper 
does not get instanciated with the original class. TObjectHelper.Free 
could have been written as a standalone function, if .Net supported such 
a thing. It would look like this:

procedure Free(Self: TObject);
begin
   if Assigned(Self) and (Self is IDisposable) then begin
     // etc.
   end;
end;

But that makes it inconvenient to call since the scope of Free is no 
longer related to the scope of TObject.

Internally, a class helper is a class of its own. Whereas we usually 
think of a method of a normal class having a "hidden" Self parameter, 
class-helper classes actually have an explicit Self parameter added to 
whatever parameters were declared in the source code. If you look at 
TObjectHelper.Free in Reflector, you'll see that it's declared something 
like this:

procedure TObjectHelper.Free(Self: System.Object);

The class-helper instance never operates on itself. Instead, it operates 
on the instance of the related class.

Delphi doesn't provide any language support for class helpers in Win32, 
but it's possible to write classes that do the same task. The technique 
is described in one of the newsgroup articles in the search I mentioned 
yesterday.

> I was under the assumption that this was something new but maybe
> not.  As I've never even looked at the code for that class I think now
would
> be a good time for me to check it out!

To get a better idea of what you're looking at, be sure to compare the 
.Net code with the Win32 version.

-- 
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to