<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Comments for Templates in Object Pascal</title>
<link rel="alternate" type="text/plain" href="http://dn.codegear.com/article/27603" title="Templates in Object Pascal" />
<link rel="self" type="application/atom+xml" href="http://dn.codegear.com/article/27603/feed" title="Comments for Templates in Object Pascal" />
<id>http://dn.codegear.com/article/27603</id>
<updated>2008-11-21T14:32:39-08:00</updated>
<entry>
<title>The article is also available in English now</title>
<author>
<name>Thomas Mueller</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38545</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38545</id>
<updated>2005-07-16T05:42:53-07:00</updated>
<published>2005-07-16T05:42:53-07:00</published>
<summary>The article is also available in English now</summary>
<content>Hi,The article mentioned in my previous post is now also available in English:http://www.dummzeuch.de/delphi/object_pascal_templates/english.htmltwm</content>
</entry>
<entry>
<title>Templates in Object Pascal</title>
<author>
<name>Craven Weasel</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38085</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38085</id>
<updated>2005-01-17T19:05:58-08:00</updated>
<published>2005-01-17T19:05:58-08:00</published>
<summary>Templates in Object Pascal</summary>
<content>You tell us how to use the Vector interface, but not Collection class template.How do you create/initialize the Collection Class template to add new items to it?</content>
</entry>
<entry>
<title>re: One include file is enough</title>
<author>
<name>Thomas Mueller</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=34724</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=34724</id>
<updated>2003-05-31T10:20:48-07:00</updated>
<published>2003-05-31T10:20:48-07:00</published>
<summary>re: One include file is enough</summary>
<content>&gt; If you want to see an example, visit http://www.dummzeuch.de&gt; (The article is in German only, but the code examples should&gt; be easy to understand.)Just in case anybody is still interested: I have translated my article to English now.twm</content>
</entry>
<entry>
<title>Interfaces with templates in Object Pascal</title>
<author>
<name>Ritchie Annand</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=33532</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=33532</id>
<updated>2002-11-14T13:05:16-08:00</updated>
<published>2002-11-14T13:05:16-08:00</published>
<summary>Interfaces with templates in Object Pascal</summary>
<content>FYI, too, it is possible to use interfaces with these Object Pascal templates as well.  It all hinges on syntax I previously didn't know Delphi supported.You can declare an interface as:  _ITERATOR_INTF_ = interface    ['{9F522A03-F6AC-11D6-9250-0004AC5359AE}']    function Next: _ITEM_;  end;Putting this in the templates will of course cause problems, as all interface GUIDs need to be unique, so if you use the template more than once, you'll run into trouble.However, there's another way to declare an interface:const  _ITERATOR_INTF_IID_ = '{9F522A03-F6AC-11D6-9250-0004AC5359AE}';type  _ITERATOR_INTF_ = interface    [_ITERATOR_INTF_]    function Next: _ITEM_;  end;This means that the IID can be defined elsewhere, such as the unit that uses the include files.  So, in my interface section, I can put in the section:const  _ITERATORREFS_IID_ = '{9F522A02-F6AC-11D6-9250-0004AC5359AE}';  _ITERATOR_IID_ = '{9F522A03-F6AC-11D6-9250-0004AC5359AE}';  _ITERABLELIST_IID_ = '{9F522A04-F6AC-11D6-9250-0004AC5359AE}';type  _ITEM_ = ICOREListener;  {$INCLUDE GIterableList.inc}  TCOREListenerList = _ITERABLELIST_;  TCOREListenerListIterator = _ITERATOR_;  ICOREListenerList = _ITERABLELIST_INTF_;  ICOREListenerListIterator = _ITERATOR_INTF_;A little more work than an object list, but works great!- Ritchie Annandhttp://members.shaw.ca/nimble</content>
</entry>
<entry>
<title>re: Templates in Object Pascal</title>
<author>
<name>Ritchie Annand</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=33531</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=33531</id>
<updated>2002-11-14T12:59:35-08:00</updated>
<published>2002-11-14T12:59:35-08:00</published>
<summary>re: Templates in Object Pascal</summary>
<content>I used to use smart pointers in C++ as well (VisualAge/C++) - one thing they were not good at (and that we implemented various template schemes to get around) was circular references, which is a trouble you get in any reference-counting scheme (including TInterfacedObject with interfaces in Delphi :)  We made an 'anchor_ptr&lt;&gt;' which would act as the one external reference to the circularly-referenced object group, which worked most of the time, but... oh, what a pleasure to debug :)I'm going to assign myself the task of figuring out the internals of garbage collectors to see how they handle and track the dependency trees to get rid of circularly-dependent objects.Thierry made mention of Ada generics, and I would agree that they would make a much more appropriate addition to Delphi than C++-style templates would.  With Ada generics, you create the equivalent of a unit (a 'package') which is termed a 'generic', and contains the named, substitutable type information in the header of the generic (like Stack_Item, Stack_Size, etc.)When it comes time to *use* it, you declare a new package from the generic, e.g.  package Integer_Stack is new Stack(Integer);Integer_Stack is now available as a class for you to use. I like its explicit nature, both in terms of type information and dependencies.The C++ ones, by contrast, seem to crack the way the language works (at least from a compiling/linking point of view) by having templates generate at point of use (which isn't a great spot to inline the generated template class code :)The error codes that templates used to generate - especially at link time - ouch :)Loki - is that the company making all those Linux translations of things like Sim City 3000?  Saw those at a CUUG open house here - looked interesting :)</content>
</entry>
<entry>
<title>re: One include file is enough</title>
<author>
<name>Thomas Mueller</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=33082</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=33082</id>
<updated>2002-09-07T12:56:57-07:00</updated>
<published>2002-09-07T12:56:57-07:00</published>
<summary>re: One include file is enough</summary>
<content>&gt; Very interesting idea. A bit more preprocessor stuff lets&gt; you include the same file twice:&gt; {$IFNDEF SECOND_PASS}&gt; // interface&gt; ...&gt; {$DEFINE SECOND_PASS}&gt; {$ELSE}&gt; // implementation&gt; ...&gt; {$ENDIF}&gt; Since there is a limit of one such class to a unit anyway&gt; and unit defines go out of scope, there is no need for&gt; $UNDEF either.You can even go one step further by adding some more ifdefs: You can start with a normal unit, with header, uses clauses etc. Just use it as a normal unit in a test program until you are sure the template works as expected.Then you put some additional ifdefs around the header, uses clauses etc. and bang, you get your includeable template, which can still be used as a normal unit in case there is a bug.If you want to see an example, visit http://www.dummzeuch.de (The article is in German only, but the code examples should be easy to understand.)MfG :-)Thomas</content>
</entry>
<entry>
<title>re: Templates in Object Pascal</title>
<author>
<name>Dietmar Brueckmann</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=32732</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=32732</id>
<updated>2002-07-22T06:59:05-07:00</updated>
<published>2002-07-22T06:59:05-07:00</published>
<summary>re: Templates in Object Pascal</summary>
<content>Sorry if I've misunderstood you:&quot;That is to say you can't step through the code in the include files. &quot;but with D6 I can step through include filesBest regardsDietmar</content>
</entry>
<entry>
<title>&lt;this message deleted&gt;</title>
<author>
<name>Clinton Johnson</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30180</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30180</id>
<updated>2002-02-21T02:33:07-08:00</updated>
<published>2002-02-21T02:33:07-08:00</published>
<summary>&lt;this message deleted&gt;</summary>
<content>&lt;this message deleted&gt;</content>
</entry>
<entry>
<title>re: Templates in Object Pascal</title>
<author>
<name>Tony Sanchez</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30335</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30335</id>
<updated>2001-10-22T04:09:31-07:00</updated>
<published>2001-10-22T04:09:31-07:00</published>
<summary>re: Templates in Object Pascal</summary>
<content>I wouldn't compare C++ smart pointers with a reference based PL using a grabage collector such as Java: GCs are supossed to explore the whole graph of dependencies amongst instances, so they can detect cycles in it and safely remove all the instances involved when no other external instance references any of them. C++ smart pointers haven't that wide scope, they just garantee the persistance of the instance they hold, and are completely unaware of instance dependencies. Obviously they are much more efficient, but don't overcome the same problems that GCs do.</content>
</entry>
<entry>
<title>re: Templates in Object Pascal</title>
<author>
<name>Thierry Coq</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30245</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30245</id>
<updated>2001-10-15T02:57:26-07:00</updated>
<published>2001-10-15T02:57:26-07:00</published>
<summary>re: Templates in Object Pascal</summary>
<content>I wholly agree with you.</content>
</entry>
</feed>
