2017-01-29 1 views
0

델파이 IDE에서 컴포넌트를 변환하고 자동 생성하는 패키지를 구현하고 있습니다. GExperts는 비슷한 기능을 가지고 있지만 특정 속성을 사용자 정의해야한다는 사실을 알고 있습니다. 내가 올바른 방법이다 RTTI에서 TValue를 사용 여부를 정말 확실하지 않다델파이 OpenTools API는 컴포넌트 속성을 얻습니다.

var 
    aVal : TValue; 
    aSqlS : TStrings; 
begin 
    [...] 
    if (mycomp.GetComponentType = 'TADOQuery') then 
     if mycomp.GetPropValueByName('SQL', aVal) then 
     begin 
      aSqlS := TStrings(aVal.AsClass); 
      if Assigned(aSqlS) then    <----- problem is here 
       ShowMessage(aSqlS.Text);  <----- problem is here 
     end; 
end; 

:

는 지금은 TStrings를의 인스턴스 인 TADOQuery.SQL 속성을 액세스하는 방법에 붙어 가기.

+1

IIRC, 'aVal'은'IOTAComponent' 또는 'TIComponentInterface'유형이어야합니다. 'mycomp'의 타입에 달려 있습니다. –

답변

2

GetPropValueByName() 가정

덕분에 SQL 속성 게터는 메타 클래스 형식을 반환하지 않기 때문에 유효한 TValue가 (당신이 그 코드를 보여주지 않았다), 다음 aVal.AsClass을 사용하는 것은 잘못 반환합니다. 객체 포인터를 반환하므로 aVal.AsObject 또는 aVal.AsType<TStrings>을 사용하십시오.


업데이트comp 경우 TValue보다 IOTAComponent 전혀 사용 분명히 잘못된 사실이다.

var 
    aVal: IOTAComponent; 
    aSqlS : TStrings; 
begin 
    [...] 
    if (mycomp.GetComponentType = 'TADOQuery') then 
     if mycomp.PropValueByName('SQL', aVal) then 
     ShowMessage(TStrings(aVal.GetComponentHandle).Text); 
end; 

하지만, 더 나은 방법이 대신 실제 TADOQuery 개체에 액세스하는 것 : IOTAComponent.GetPropValueByName()의 출력 특성 값의 미가공 데이터 또는 TPersistent 유래 객체에 대한 IOTAComponent 수신 지정되지 않은 var이다

if (mycomp.GetComponentType = 'TADOQuery') then 
    ShowMessage(TADOQuery(comp.GetComponentHandle).SQL.Text); 
관련 문제