Hi I understand the issue now. 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). I use f for local class variables. No prefix for local variables. Don't really use globals. Use a for parameters but mostly in constructors, probably should do this more). Cheers Rob Jeremy North wrote: It should read - FCountryList: TStringList<TCountryAddressFormat>;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 <jeremy.no...@gmail.com> wrote:The enumerator for TStringList returns a pointers not the specific object type so you still need a typecast. var CountryAddressFormat: Pointer; begin for CountryAddressFormat in Self do begin Strings.AddObject( TCountryAddressFormat(CountryAddressFormat).CountryName, TObject(TCountryAddressFormat(CountryAddressFormat).CountryRefAsInteger) ); 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 FCountryList: TStringList<TCountryAddressFormats>; .... var CountryAddressFormat : TCountryAddressFormat; begin for CountryAddressFormat in FCountryList do begin // no typecasting necessary end; end; cheers, Jeremy On Thu, Oct 15, 2009 at 8:06 AM, Robert martin <r...@chreos.co.nz> wrote: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' (note the base class here inherits from TObjectList) procedure TCountryAddressFormats.LoadStringListWithCompanies(Strings: TStrings); var Counter : Integer; begin for Counter := 0 to Self.Count - 1 do begin Strings.AddObject( TCountryAddressFormat(Self.Items[Counter]).CountryName, Tobject(TCountryAddressFormat(Self.Items[Counter]).CountryRefAsInteger) ); end; end; I wanted to replace it with procedure TCountryAddressFormats.LoadStringListWithCompanies(Strings: TStrings); var CountryAddressFormat : TCountryAddressFormat; begin for CountryAddressFormat in Self do begin Strings.AddObject( CountryAddressFormat.CountryName, TObject(CountryAddressFormat.CountryRefAsInteger) ); 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: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe_______________________________________________ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe |
_______________________________________________ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe