<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi<br>
<br>
I understand the issue now.&nbsp; I will follow Jolyon's recommendation and
create an enumerator for this otherwise its not much use if I need to
typecast anyway (may as well use my original code).<br>
<br>
I use f for local class variables.&nbsp; No prefix for local variables.&nbsp;
Don't really use globals.&nbsp; Use a for parameters but mostly in
constructors, probably should do this more).&nbsp; <br>
<br>
Cheers<br>
Rob<br>
<br>
<br>
Jeremy North wrote:
<blockquote
 cite="mid:c50871a20910141432u68de331v2561495ef7ea3232@mail.gmail.com"
 type="cite">
  <pre wrap="">It should read -

FCountryList: TStringList&lt;TCountryAddressFormat&gt;;


Do you really not prefix your Local, Global, Field and Parameters with nothing?

I'm a L, _, F and A person myself!


On Thu, Oct 15, 2009 at 8:29 AM, Jeremy North <a class="moz-txt-link-rfc2396E" href="mailto:jeremy.north@gmail.com">&lt;jeremy.north@gmail.com&gt;</a> wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">The enumerator for TStringList returns a pointers not the specific
object type so you still need a typecast.

var
&nbsp; CountryAddressFormat: Pointer;
begin
&nbsp; for CountryAddressFormat in Self do begin
&nbsp; &nbsp; &nbsp; Strings.AddObject(
TCountryAddressFormat(CountryAddressFormat).CountryName,
TObject(TCountryAddressFormat(CountryAddressFormat).CountryRefAsInteger)
);
&nbsp; end;

Didn't test it to see it is 100% correct.

This raises the issues with FOR..IN in pre-generics versions. Unless
you encapsulate your list in a class and implement the enumerator on
the class you will most likely have to still typecast when using
enumerators.

With generics in D2009 and D2010 you wouldn't need to do this because
you'd do something like (untested).


var
&nbsp;FCountryList: TStringList&lt;TCountryAddressFormats&gt;;


....

var
&nbsp; CountryAddressFormat &nbsp;: TCountryAddressFormat;
begin
&nbsp; for CountryAddressFormat in FCountryList do
&nbsp; begin
&nbsp; &nbsp; &nbsp; // no typecasting necessary
&nbsp; end;
end;

cheers,
Jeremy

On Thu, Oct 15, 2009 at 8:06 AM, Robert martin <a class="moz-txt-link-rfc2396E" href="mailto:rob@chreos.co.nz">&lt;rob@chreos.co.nz&gt;</a> wrote:
    </pre>
    <blockquote type="cite">
      <pre wrap="">Hi

After the D2010 presentation yesterday I decided I should actually use
some of the D2007 features I had not gotten around to using.
Specifically the For .. in construct.

I am sure I am missing something but here iss what I want to do


I have the following 'old school code' &nbsp;(note the base class here
inherits from TObjectList)

procedure TCountryAddressFormats.LoadStringListWithCompanies(Strings:
TStrings);
var
&nbsp; &nbsp;Counter &nbsp; &nbsp; : Integer;
begin

&nbsp; &nbsp;for Counter := 0 to Self.Count - 1 do begin
&nbsp; &nbsp; &nbsp; &nbsp;Strings.AddObject(
TCountryAddressFormat(Self.Items[Counter]).CountryName,
Tobject(TCountryAddressFormat(Self.Items[Counter]).CountryRefAsInteger) );
&nbsp; &nbsp;end;
end;

I wanted to replace it with

procedure TCountryAddressFormats.LoadStringListWithCompanies(Strings:
TStrings);
var
&nbsp; &nbsp;CountryAddressFormat &nbsp;: TCountryAddressFormat;
begin
&nbsp; &nbsp;for CountryAddressFormat in Self do begin
&nbsp; &nbsp; &nbsp; &nbsp;Strings.AddObject( CountryAddressFormat.CountryName,
TObject(CountryAddressFormat.CountryRefAsInteger) );
&nbsp; &nbsp;end;
end;

but I get the following error

[DCC Error] AddressFormat.pas(157): E2010 Incompatible types:
'TCountryAddressFormat' and 'Pointer'

what am I missing ?


Cheers
Rob

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: <a class="moz-txt-link-abbreviated" href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a>
Admin: <a class="moz-txt-link-freetext" href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a>
Unsubscribe: send an email to <a class="moz-txt-link-abbreviated" href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe

      </pre>
    </blockquote>
  </blockquote>
  <pre wrap=""><!---->
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: <a class="moz-txt-link-abbreviated" href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a>
Admin: <a class="moz-txt-link-freetext" href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a>
Unsubscribe: send an email to <a class="moz-txt-link-abbreviated" href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe

  </pre>
</blockquote>
</body>
</html>