aşağıdaki düşünün yöntem türlerini çözme değil:Jenerik doğru
{$APPTYPE CONSOLE}
uses
Generics.Collections;
type
TObjProc = procedure of object;
TFoo = class
public procedure DoFoo;
public procedure DoBar;
end;
procedure TFoo.DoFoo;
begin
WriteLn('foo');
end;
procedure TFoo.DoBar;
begin
WriteLn('bar');
end;
var
ProcList : TList<TObjProc>;
Foo : TFoo;
aProc : TObjProc;
begin
Foo := TFoo.Create;
ProcList := TList<TObjProc>.Create;
ProcList.Add(Foo.DoFoo);
ProcList.Add(Foo.DoBar);
for aProc in ProcList do aProc;
ReadLn;
end.
Bu Şimdi listeden bir prosedür atamak istediğiniz varsayalım
foo
bar
beklenen çıktıyı üretir. Yukarıdaki gibi numaralandırma işleri.
aProc := ProcList.Items[0];
aProc;
Ama bu bir derleyici hatası atar: Bu da çalışır Yani
function TList<T>.First: T;
begin
Result := Items[0];
end;
beri iki kat garip
aProc := ProcList.First;
// E2010 Incompatible types:
//'procedure, untyped pointer or untyped parameter' and 'TObjProc'
... Ne oluyor?
Bu, Delphi'nin daha yeni sürümlerini de etkiler mi? Bu işe yaraması için makul bir beklenti varsa (eğer olduğunu düşünüyorum), QC cezbediyorum.
C#, C, C++, Python ve diğer dillerden. VB dışında. Kendinizi bir boyut ikiye bulduğunuzda ve diğer üye VB olduğunda daima kötüdür! –
Ve AFAIK, Swift, o zaman üçlü bir takım haline gelir. –