0
我使用德爾福2010年錯誤從類傳遞一個泛型類型到另
我得到的錯誤:E2506法在接口部分聲明不得使用本地符號參數化類型。
有沒有辦法完成這項任務?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Rtti;
type
MyFormType<T: TForm> = class
class procedure SpecialOpen(var FormVar: T; Params: array of TValue);
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ShowForm<T1: TForm>(var aForm: T1);
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.ShowForm<T1>(var aForm: T1);
begin
if aForm = nil then
MyFormType<T1>.SpecialOpen(aForm, [Self]) // <-- Error
else
aForm.Show;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowForm<TForm2>(Form2)
end;
{ MyFormType<T> }
class procedure MyFormType<T>.SpecialOpen(var FormVar: T; Params: array of TValue);
var lRttiContext: TRttiContext;
begin
FormVar := lRttiContext.GetType(TClass(T)).GetMethod('Create').Invoke(TClass(T), Params).AsType<T>;
FormVar.Show;
end;
end.
坦克和抱歉,我的英語。