Delphi RTTI 동적 생성 Form

728 단어 delphi
셀을 참조하지 않고 Form을 직접 생성
  
procedure MyShowForm(FormName: string);
  var
    ctxRtti: TRttiContext;
    typeRtti: TRttiType;
    methRtti: TRttiMethod;
    LClass: TRttiInstanceType;
    aForm: TCustomForm;
  begin
    ctxRtti  := TRttiContext.Create;
    try
      for typeRtti in ctxRtti.GetTypes() do
      begin
        if SameText(typeRtti.Name, FormName) then
        begin
          LClass := typeRtti.AsInstance;
          aForm := LClass.MetaclassType.Create as TCustomForm;
          aForm.Create(Application);
          aForm.Show;
          aForm.BringToFront;
        end;
      end;
    finally
      ctxRtti.Free;
    end;
  end;
  MyShowForm('TForm2');

좋은 웹페이지 즐겨찾기