I had just last evening spent about two hours in the
Generics.Collections unit myself, and though I found these classes quite
interesting, I wasn't able to remember a time when I could have used them in
my own work! <g>  Of course that could be because they weren't previously
available.  In any case I'm spending as much time as I can experimenting
with these new classes because in the past, when I'd simply just jump into
the editor and start writing, I  missed many things that might have been a
great help to me.  This happened when Interfaces first came along, and by
the time I got around to even considering them the next version of Delphi
was already on its way!
        BTW...I hadn't heard of the tiOPF object persistence framework
before.  So I checked it out on the Embarcadero site.  Do you know if it
works under D2009?  The specs, at least for the download listed there only
mentions D2007.  With this new project I'm about to start working on I
really want to further separate the dB access code from the user side better
than I've done before.  It will have an embedded dB of some kind...hopefully
Blackfish if it runs as good as I've heard...but every time I work on
projects like this I find myself taking shortcuts that although not a
problem itself, is a problem later if I change dB's or even the user side.
So I'd like to get the entire dB side separated as a reusable object that
can be added into a project with the least amount of work being needed.    

from "Robert Meek" dba "Tangentals Design"
Creative Concepts Programming for Windows Vista
E-mail:  ffo...@comcast.net
"Most people would sooner die than think; in fact, they do so!"
        [Bertrand Russell  1872-1970]

-----Original Message-----
From: delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] On Behalf
Of Sean Cross
Sent: Sunday, April 26, 2009 5:14 PM
To: Borland's Delphi Discussion List
Subject: RE: Generics in D2009

The type of your specialised  class is set at compile time.  However you can
have multiple specialisations for a single generic class.

One of the obvious uses for generics is lists and container classes. E.g. in
the Generics.Collections unit in D2009 there are a bunch of classes such as 

  TList<T> = class(TEnumerable<T>)  
  TQueue<T> = class(TEnumerable<T>)
Etc

You can create a specialised list(s) simply by going:
var
  MyList: TList<TMyClass>;
  MyOtherList: TList<TMyOtherClass>;
  MyYetOtherList: TList<TMyYetOtherClass>;

  MyList now has all the methods of a list, specialised to TMyClass.  Ie Add
will only take a TMyClass, Items will only take and return a TMyClass,
enumerators will use TMyClass ...  All this happens without any required
typecasting.


I use this with the tiOPF object persistence framework.  In tiopf, a
complete container class takes about 100 loc for basic functionality.  This
can be replaced with a single line of code using generics.  I have 13 such
containers in my project.





Regards
 
Sean Cross
CIO
Catalyst Risk Management

-----Original Message-----
From: delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] On Behalf
Of Robert Meek
Sent: Sunday, 26 April 2009 4:44 p.m.
To: delphi@elists.org
Subject: Generics in D2009

        Even though I had done some limited work using Oxygene, ( now Delphi
Prism ), I never got into or even tried to make use of Generics.  There was
too much to learn in .NET already so I was saving them for after I became
comfortable with it.
Now however, and since Delphi has gone to a lot of trouble to include them,
I figured it was time to take a good look at them.  Once again though,
Cantu's D2009 handbook and his theoretical approach to Generics has left me
a little cold.
        It's easy enough to create and instantiate a Generic Class all
right, but at the same time, the mere fact that once a Generic Type has been
set for that class you cannot alter it leaves me wondering exactly when and
why I would put this language feature to practical use...if of course, that
is truly how Generics work!   
        In this example:

type
TSampleClass <T> = class
private
data: T;
public
function GetDataSize: Integer;
function GetDataName: string;
end;
function TSampleClass<T>.GetDataSize: Integer;
begin
Result := SizeOf (T);
end;
function TSampleClass<T>.GetDataName: string;
begin
Result := GetTypeName (TypeInfo (T));
end;
end;

        Am I correct in assuming that 'data : T;' cannot be altered to a
different type once the class is created and a value/Type is given to 'T',
because that is how it came across to me despite it not seeming to make much
sense!  If such is the case why would I even bother using a Generic Class?
        If on the other hand, I created an instance of the class and gave
'T' a value of '0' or 'nil', depending upon the type of data I wish to pass
it, then I could write a procedure that first sets the Value/Type of 'T' to
any I want to at the moment, and then call the three class functions from
within, it would be possible for me to reset 'T' to a different Value/Type
each time I call this procedure!  THAT I can see as being very useful!  
        Which of these is true?  I'm hoping I missed something along the way
and the latter description of a Generic Class's use is correct or at least
closer to the truth!



from "Robert Meek" dba "Tangentals Design"
Creative Concepts Programming for Windows Vista
E-mail:  ffo...@comcast.net
"Most people would sooner die than think; in fact, they do so!"
        [Bertrand Russell  1872-1970]


_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to