Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit uReturn_TObject;
- interface
- uses
- Forms, Controls, SysUtils,
- Rtti, Generics.collections;
- Type
- TReturn_TObject = class
- class function Instanciar<T:Class>:T;
- class procedure InstanciarForms<T:Class>(Owner:TWinControl);
- end;
- implementation
- uses
- typInfo;
- { TReturn_TObject<T> }
- class function TReturn_TObject.Instanciar<T>: T;
- var
- valor: TValue;
- ctx: TRttiContext;
- tipo: TRttiType;
- tipoInstancia: TRttiInstanceType;
- begin
- tipo := ctx.GetType(TypeInfo(T));
- tipoInstancia:= (Ctx.FindType(Tipo.QualifiedName) as TRttiInstanceType);
- Valor:=Tipoinstancia.MetaclassType.Create;
- Result := valor.AsType<T>;
- end;
- class procedure TReturn_TObject.InstanciarForms<T>(Owner: TWinControl);
- var
- Form:TForm;
- valor: TValue;
- ctx: TRttiContext;
- tipo: TRttiType;
- tipoInstancia: TRttiInstanceType;
- begin
- tipo := ctx.GetType(TypeInfo(T));
- tipoInstancia:=
- (Ctx.FindType(Tipo.QualifiedName) as TRttiInstanceType);
- Valor:=Tipoinstancia.MetaclassType.Create;
- form := Tform(valor.AsType<T>).Create(Owner);
- Form.ShowModal;
- Form.Free;
- end;
- { TReturn_TObjecStringt }
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement