2014-10-02 2 views
2

데이터베이스 (QualifiedName)에 이전에 저장 한 유형의 이름으로 클래스를 만들고 싶습니다. 내가 함수 TRttiContext.FindType ('qualifiedName가')를 호출 할 때하지만, 내가 찾은 몇 클래스RttiContext를 사용하여 런타임에 유형 찾기

참고 : 모든 클래스는 공개되며 모든 클래스는 동일한 단위에있는 ALLCLASSES이 TMyClassParent

에서
Procedure TMyObjects.Load; 
var s, typeName : string;    
ctx : TRttiContext; 
    t: TRttiInstanceType; 
    tp: TRttiType; 
    o: TMyClassParent; 
begin 
ctx := TRttiContext.Create; 
try 
    While not Table.Eof do begin 
     typeName := format('%s.%s',[FieldByName('UnitName').AsString,FieldByName('TypeName').AsString]); 
    if trim(typeName) <> '' then begin 
     tp := ctx.FindType(typeName); 
     ///..here when I debug some Types exists (tp <> nil) and for others tp = nil... 
     t := tp as TRttiInstanceType; 
     if Assigned(t) then begin 
      o := t.MetaClassType.Create; 
     //... 
     ///... 
     end; 
     ///.... 
    end; 
    //.... 
finally 
    ctx.free; 
end; 
을 상속

저에게 도움이 될 수있는 사람이 있습니까? 저는 영어로 Delphi XE5와 죄송합니다.

+0

OT : RTL에는 기본 제공 메커니즘이 있습니다. [RegisterClass] (http://docwiki.embarcadero.com/Libraries/XE5/en/System.Classes.RegisterClass) 프로 시저에 의해 클래스를 등록하고 ['GetClass'] (http : // docwiki.embarcadero.com/Libraries/XE5/en/System.Classes.GetClass) 또는 ['FindClass'] (http://docwiki.embarcadero.com/Libraries/XE5/en/System.Classes.FindClass) 함수를 호출합니다. – TLama

+2

이유는 여기에서 찾을 수 있습니다 : [Delphi 2010 RTTI-RttiContext.FindType] (http://stackoverflow.com/q/3460382/576719). 클래스는 링커에 의해 제외 될 수 있습니다. –

+0

고마워요. 이걸 시도 할께. – relghers

답변

1

나는 적어도 한 번 클래스를 사용하거나 컴파일러/링커가 실행 파일에서 스트립 할 수 없도록 프로그램의 어느 곳에서나 클래스를 사용할 수 있습니다. The Solution 감사합니다. s to All