我在做动态生成报表时发现这个问题,本来都很正常
在给qrRichText的lines应用text时发现问题,此问题等价于:s:=tstrings.Create;
SetStrProp(s,'text', 'the text');则会出错,据说RTTI在 对非 PUBLUC 属性不可用,但TEXT是公共的啊?
大侠邦忙啊,快郁闷至死了

解决方案 »

  1.   

    TStrings is an abstract base class for objects that represent a list of strings.这是帮助中第一句话.一个虚类(抽象类),不能创建它的实例的.要用,你就要用它的子类对象来实现.
    var
      s:tstringlist;
    s:=tstringlist.Create;
    SetStrProp(s,'text', 'the text');
      

  2.   

    應該是tstrings是抽象類的緣故,
    你用TStringList就可以了
      

  3.   

    我照样子试了,还是不行
    我用的是DELPHI6
    另外,发现 TStringList = class(TStrings)
    还有TStrings是抽像类么?
      

  4.   

    测试:
    还用原因来的使用 tstrings 
    要是不用 SetStrProp 直接赋值是可以的,我的问题中不能用这种方法
      

  5.   

    //FAINT........var
      s:TStrings;......
    s:=TStringList.Create;
    SetStrProp(s,'text', 'the text');
      

  6.   

    TStrings是抽像类,  
    看原代碼你就可以看到
    abstract方法
      

  7.   

    楼上亲自试过么? 错误并非是抽像错误,而是属性不存在....从一开始就是这样,即使用TStringList
      

  8.   

    我在想楼主在什么情况下需要SetStrProp这样用....
      

  9.   

    RTTI是对published属性有效,不是public
      

  10.   

    樓主用的函數SetPropStr是下面這個函數嗎
     function   SetPropStr(Instance:   TObject;   PropName:   string;   PropValue:   string):   Boolean;
      var   PropInfo:   PPropInfo;
      begin
          Result   :=   True;
          PropInfo   :=   GetPropInfo(Instance.ClassInfo,   PropName);
          if   Assigned(PropInfo)   then
          case   PropInfo.PropType^.Kind   of
              tkEnumeration:   SetEnumProp(Instance,   PropInfo,   PropValue);
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              tkVariant         :   SetVariantProp(Instance,   PropInfo,   Variant(PropValue));
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              tkInteger         :   SetOrdProp(Instance,   PropInfo,   StrToInt(PropValue));
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
              tkFloat             :   SetFloatProp(Instance,   PropInfo,   StrToFloat(PropValue));
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
              tkSet                 :   SetSetProp(Instance,   PropInfo,   PropValue);   
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              tkChar,   
              tkWChar,   
              tkString,
              tkLString,   
              tkWString         :   SetStrProp(Instance,   PropInfo,   PropValue);   
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              tkClass             :   SetPropValue(Instance,   PropName,   Variant(PropValue));   
          else   Result   :=   False;   
          end   else   Result   :=   False;
      end;   ----------------------------------------------------------------------------
    如果是的話,那麼這個錯誤是因為這個函數只能設置published的屬性,
    TStrings的Text屬性沒有發布所以報這種錯誤,
    你如果將TStrings的實例改為TEdit的實例就可以賦值.
      

  11.   

    谢客位了,最起码知道问题的由来了,这才是最重要的,这种办法不行,我再尝试别的方法
    至于用途是这样:我建立了一个报表描述文件如下:
    [label]
    top=906;width=70;height=40;left=614;
    caption=其它;
    font.name=宋体;font.size=12;font.style=[fsBold];transparent=true[richtext]
    top=160;width=246;height=40;left=100;lines.text=其其其其其其其其其其其;
    font.name=宋体;font.size=12;font.style=[fsBold];transparent=true//纵线
    [shape]
    width=1;height=80;left=165;top=210;
    pen.width=2;shape=qrsVertLine;brush.style=bsClear报表控件的生成是态的,属性和值都是用字符串给出,个人喜欢这种方法(除本贴的问题,其它都工作的很好,qrLabel的自动换行对中文支持不好,所以用qrRichtext)打算让这贴子晚结一天,明天再来看看
      

  12.   

    属性设置是这样://///////////////////////////////////
    //设置属性
    procedure SetObjProp(C:TOBJECT;strProp:string;strVal:string);
    var
      PropInfo: PPropInfo;
      plist:TStringList; i:integer;
      b: TOBJECT; f:tfont; k:TTypeKind;PropNm:String;
    begin
      plist:=split(strProp,'.'); //可能含有'.'的属性
      b:=c;
      for i:=0 to plist.Count-1 do begin
        PropInfo := GetPropInfo(b, trim(plist[i]));
        if (not Assigned(PropInfo)) then exit;
        if propInfo^.PropType^.Kind in [tkClass] then
          b:=GetObjectProp(b,trim(plist[i]));
        if (b is tstrings) then break;
      end;
      PropNm:=plist[plist.count-1];
      //k:=propInfo^.PropType^.Kind;  if (b is tstrings) then
        tstrings(b).text:=strVal
      else
        SetPropvalue(b,PropNm, strVal);
    end;注:这里由于简化改用 SetPropvalue
      

  13.   

    - -!,zswang(伴水清清)说的是,我忘了free了,在此感谢提醒