<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor=white lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>As has been mentioned you can use the “built in” enumerator, but
that will only yield Pointer values, so you would then have to typecast the
results, or you should be able to use “absolute” to achieve the typecast “declaratively”
in the var declarations:<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<pre>var<o:p></o:p></pre><pre> addrFormatEnum: Pointer;<o:p></o:p></pre><pre> addrFormat: TCountryAddressFormat absolute addrFormatEnum;<o:p></o:p></pre><pre>begin<o:p></o:p></pre><pre> for addrFormatEnum in Self do<o:p></o:p></pre><pre> begin<o:p></o:p></pre><pre> Strings.AddObject(addrFormat.CountryName, <o:p></o:p></pre><pre> TObject(addrFormat.CountryRefAsInteger));<o:p></o:p></pre><pre> end;<o:p></o:p></pre><pre>end;<o:p></o:p></pre>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>But note that the above code is untested either for compilation
or behaviour. </span><span style='font-size:11.0pt;font-family:Wingdings;
color:#1F497D'>J</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";
color:windowtext'>From:</span></b><span style='font-size:10.0pt;font-family:
"Tahoma","sans-serif";color:windowtext'> delphi-bounces@delphi.org.nz
[mailto:delphi-bounces@delphi.org.nz] <b>On Behalf Of </b>Robert martin<br>
<b>Sent:</b> Thursday, 15 October 2009 10:45 a.m.<br>
<b>To:</b> NZ Borland Developers Group - Delphi List<br>
<b>Subject:</b> Re: [DUG] Stupid /easy question<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Hi<br>
<br>
Yeah I read examples of how to add enumerators but since TObjectList already
has one I didn't think I needed to. Guess I do. Seems like it is a
bit too much work for basic (small) classes not frequently used (such as the
one im working on). Will give it a go anyway :)<br>
<br>
Thanks<br>
Rob<o:p></o:p></p>
<div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-NZ style='color:#FF9900'> </span><o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-NZ> </span><o:p></o:p></p>
</div>
</div>
<p class=MsoNormal><br>
<br>
Jolyon Smith wrote: <o:p></o:p></p>
<pre>You will have to implement an enumerator for your TCountryAddressFormats<o:p></o:p></pre><pre>class that returns TCountryAddressFormat references.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>This isn't a language feature that "just works" - you have to put some<o:p></o:p></pre><pre>infrastructure in place to support it.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>The feature appears to "just work" for a bunch of VCL types (TStringList<o:p></o:p></pre><pre>etc) because the VCL already contains the necessary infrastructure additions<o:p></o:p></pre><pre>(and which should provide the examplar implementations on which you could<o:p></o:p></pre><pre>base your own).<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>-----Original Message-----<o:p></o:p></pre><pre>From: <a
href="mailto:delphi-bounces@delphi.org.nz">delphi-bounces@delphi.org.nz</a> [<a
href="mailto:delphi-bounces@delphi.org.nz">mailto:delphi-bounces@delphi.org.nz</a>] On<o:p></o:p></pre><pre>Behalf Of Robert martin<o:p></o:p></pre><pre>Sent: Thursday, 15 October 2009 10:06 a.m.<o:p></o:p></pre><pre>To: NZ Borland Developers Group - Delphi List<o:p></o:p></pre><pre>Subject: [DUG] Stupid /easy question<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Hi<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>After the D2010 presentation yesterday I decided I should actually use <o:p></o:p></pre><pre>some of the D2007 features I had not gotten around to using. <o:p></o:p></pre><pre>Specifically the For .. in construct.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>I am sure I am missing something but here iss what I want to do<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>I have the following 'old school code' (note the base class here <o:p></o:p></pre><pre>inherits from TObjectList)<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>procedure TCountryAddressFormats.LoadStringListWithCompanies(Strings: <o:p></o:p></pre><pre>TStrings);<o:p></o:p></pre><pre>var<o:p></o:p></pre><pre> Counter : Integer;<o:p></o:p></pre><pre>begin<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> for Counter := 0 to Self.Count - 1 do begin<o:p></o:p></pre><pre> Strings.AddObject( <o:p></o:p></pre><pre>TCountryAddressFormat(Self.Items[Counter]).CountryName, <o:p></o:p></pre><pre>Tobject(TCountryAddressFormat(Self.Items[Counter]).CountryRefAsInteger) );<o:p></o:p></pre><pre> end;<o:p></o:p></pre><pre>end;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>I wanted to replace it with<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>procedure TCountryAddressFormats.LoadStringListWithCompanies(Strings: <o:p></o:p></pre><pre>TStrings);<o:p></o:p></pre><pre>var<o:p></o:p></pre><pre> CountryAddressFormat : TCountryAddressFormat;<o:p></o:p></pre><pre>begin<o:p></o:p></pre><pre> for CountryAddressFormat in Self do begin<o:p></o:p></pre><pre> Strings.AddObject( CountryAddressFormat.CountryName, <o:p></o:p></pre><pre>TObject(CountryAddressFormat.CountryRefAsInteger) );<o:p></o:p></pre><pre> end;<o:p></o:p></pre><pre>end;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>but I get the following error<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>[DCC Error] AddressFormat.pas(157): E2010 Incompatible types: <o:p></o:p></pre><pre>'TCountryAddressFormat' and 'Pointer'<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>what am I missing ?<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>Cheers<o:p></o:p></pre><pre>Rob<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>_______________________________________________<o:p></o:p></pre><pre>NZ Borland Developers Group - Delphi mailing list<o:p></o:p></pre><pre>Post: <a
href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><o:p></o:p></pre><pre>Admin: <a
href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a><o:p></o:p></pre><pre>Unsubscribe: send an email to <a
href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject:<o:p></o:p></pre><pre>unsubscribe<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>_______________________________________________<o:p></o:p></pre><pre>NZ Borland Developers Group - Delphi mailing list<o:p></o:p></pre><pre>Post: <a
href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><o:p></o:p></pre><pre>Admin: <a
href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a><o:p></o:p></pre><pre>Unsubscribe: send an email to <a
href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre></div>
</body>
</html>