🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.delphi
Article #334823

Re: E2032 For loop control variable must have ordinal type

#334823
From: jh
Date: Mon, 16 Jan 2012 22:17
79 lines
3231 bytes
W dniu 16.01.2012 17:32, R.e.m.e.K pisze:
> Dnia Mon, 16 Jan 2012 17:06:56 +0100, Piotr Rezmer napisał(a):
>
>> Błąd polega na tym że użyłeś Integer jako placeholder po lewej stronie
>> deklaracji typu generycznego. W ten sposób nadpisałeś definicję typu
>> Integer, i kompilator nie rozpoznał deklaracji zmiennej I w bloku
>> zmiennych metody doParsePacketList().
>
> To brzmi sensownie, tylko czemu (zacytuje moj pierwszy post):
>
> "Ale jak pomiedzy implementation a metode wsadzisz:
>
> function nothing : Integer;
> begin
> end;
>
> to bledu juz nie ma."
>
> Cos tu jednak smierdzi.

Kod poprawiony i oczywiście działa - to w ramach nauki nowości (w D2007 
nie było wielu rzeczy z tego, co pojawiło się w D2009/2010/XE). Kupiłem 
sobie PDFa Marco Cantu i męczę literaturę :)

Teraz mam problem z dziedziczeniem generyków. Taki przykład:

TCustomList<T> = class(TObjectDictionary<Integer, T>)
   private
     FListID: Integer;
     FListName: string;
   public
     class function CreateList(const AListName: String; const AListID: 
Integer): TCustomList<T>;

     property ListName: string read FListName write FListName;
     property ListID: Integer read FListID write FListID;
   end;

   TSingleList = class(TCustomList<string>)
   public
   end;

   TMultiList = class(TCustomList<TSingleList>)
   public
   end;

implementation

{ TCustomList<T> }

class function TCustomList<T>.CreateList(const AListName: String; const 
AListID: Integer = -1): TCustomList<T>;
begin
   Result := TCustomList<T>.Create();
   Result.FListName := AListName;
   Result.FListID := AListID;
end;


Jak zrobić, żeby dziedziczące klasy umiały korzystać z funkcji klasowej 
CreateList i żeby ona zwracała obiekt właściwej klasy? Zgodnie z 
powyższym kodem oczywiście to nie zadziała:

var
   sl: TSingleList;

sl := TSingleList.CreateList('Single List', -1);

A jeszcze lepiej, żeby (wiem, że to niepoprawny zapis, chodzi mi o 
uzyskanie takiej funkcjonalności) było tak:

var
   cl: TCustomList<T>;

cl := TCustomList.CreateList('Single List', -1); (zwraca obiekt klasy 
TSingleList lub TMultiList - a decyduje o tym funkcja klasowa CreateList 
zależnie np. od otrzymanych parametrów. Da się tak?

jh
Technical Details
Message-ID: <jf27m9$is9$1@inews.gazeta.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail
References: <jf1eso$r2g$1@inews.gazeta.pl> <jf1hvq$6dj$1@inews.gazeta.pl> <15e8um5ehdue7.dlg@hell.heaven>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail
From: jh <no-email@sorry.com>
Newsgroups: pl.comp.lang.delphi
Subject: Re: E2032 For loop control variable must have ordinal type
Date: Mon, 16 Jan 2012 23:17:45 +0100
Organization: "Portal Gazeta.pl -> http://www.gazeta.pl"
Lines: 79
Message-ID: <jf27m9$is9$1@inews.gazeta.pl>
References: <jf1eso$r2g$1@inews.gazeta.pl> <jf1hvq$6dj$1@inews.gazeta.pl> <15e8um5ehdue7.dlg@hell.heaven>
NNTP-Posting-Host: nat.netcity.pl
Mime-Version: 1.0
X-Trace: inews.gazeta.pl 1326752265 19337 91.195.57.2 (16 Jan 2012 22:17:45 GMT)
X-Complaints-To: usenet@agora.pl
NNTP-Posting-Date: Mon, 16 Jan 2012 22:17:45 +0000 (UTC)
X-User: jh0909nowe
In-Reply-To: <15e8um5ehdue7.dlg@hell.heaven>
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0) Gecko/20111222 Thunderbird/9.0.1
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit