[DUG] Stupid /easy question

Jolyon Smith jsmith at deltics.co.nz
Thu Oct 15 12:37:55 NZDT 2009


Delphi 2007 was mentioned - no (Win32) generics.  And that creates a not
insignificant problem with using generics and other new language features in
code from (or that may be shared with) existing (i.e. pre-D2009) projects:

 

-          They were introduced in Delphi 2009, along with the unavoidable
transition to Unicode

 

-          Consequently if you convert existing classes derived from
TObjectList to TObjectList<T> or similar then you also have to migrate your
code to Unicode

 

-          If you find (or fear) that Unicode creates issues for your code
that you don't have time to deal with for your next release you have created
(generics) code that does not migrate back to Delphi 2007 and the
"sanctuary" of ANSIString

 

-          Similarly you cannot use these language features if your code has
to be shared with other projects that are not migrating to Unicode, although
that is perhaps a less likely scenario.

 

The only safe way to deal with this is to deal with Unicode migration as a
separate, pre-requisite project before then making any changes that exploit
or take advantage of new language features introduced in the Unicode only
version(s) of Delphi.

 

Only once you are 100% certain that the Unicode transition has not
introduced undesirable side effects can you consider using language features
which commit your code to the Unicode compiler/RTL.

 

Sadly successful compilation without errors or warnings is no guarantee
against some side effects, so unless you have 100% automated test coverage,
achieving that certainty is not necessarily going to be straightforward.

 

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Sean Cross
Sent: Thursday, 15 October 2009 11:41 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Stupid /easy question

 

If you are using a version of Delphi with generics, you should be able to
use a generic list and it'll work fine.

 

eg

var myList : TObjectList<TMyObject>;

 

Regards

 

Sean Cross
CIO

 

Catalyst Risk Management
PO Box 230
Napier 4140
DDI: 06-8340362
Mobile: 021270 3466

 

Visit us at http://www.catalystrisk.co.nz <http://www.catalystrisk.co.nz/> 

 

Offices in Auckland, Hamilton, Napier, Wellington, Christchurch & Dunedin

 

Disclaimer:
"The information contained in this document is confidential to the
addressee(s) and may be legally privileged. Any view or opinions expressed
are those of the author and may not be those of Catalyst Risk Management. No
guarantee or representation is made that this communication is free of
errors, viruses or interference. If you have received this e-mail message in
error please delete it and notify me. Thank you."

 

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Robert martin
Sent: Thursday, 15 October 2009 10:45 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Stupid /easy question

 

Hi

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 :)

Thanks
Rob

 

 

 



Jolyon Smith wrote: 

You will have to implement an enumerator for your TCountryAddressFormats
class that returns TCountryAddressFormat references.
 
This isn't a language feature that "just works" - you have to put some
infrastructure in place to support it.
 
The feature appears to "just work" for a bunch of VCL types (TStringList
etc) because the VCL already contains the necessary infrastructure additions
(and which should provide the examplar implementations on which you could
base your own).
 
 
-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Robert martin
Sent: Thursday, 15 October 2009 10:06 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: [DUG] Stupid /easy question
 
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 at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe
 
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe
 
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20091015/59212781/attachment-0001.html 


More information about the Delphi mailing list