我在做动态生成报表时发现这个问题,本来都很正常
在给qrRichText的lines应用text时发现问题,此问题等价于:s:=tstrings.Create;
SetStrProp(s,'text', 'the text');则会出错,据说RTTI在 对非 PUBLUC 属性不可用,但TEXT是公共的啊?
大侠邦忙啊,快郁闷至死了
在给qrRichText的lines应用text时发现问题,此问题等价于:s:=tstrings.Create;
SetStrProp(s,'text', 'the text');则会出错,据说RTTI在 对非 PUBLUC 属性不可用,但TEXT是公共的啊?
大侠邦忙啊,快郁闷至死了
var
s:tstringlist;
s:=tstringlist.Create;
SetStrProp(s,'text', 'the text');
你用TStringList就可以了
我用的是DELPHI6
另外,发现 TStringList = class(TStrings)
还有TStrings是抽像类么?
还用原因来的使用 tstrings
要是不用 SetStrProp 直接赋值是可以的,我的问题中不能用这种方法
s:TStrings;......
s:=TStringList.Create;
SetStrProp(s,'text', 'the text');
看原代碼你就可以看到
abstract方法
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的實例就可以賦值.
至于用途是这样:我建立了一个报表描述文件如下:
[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)打算让这贴子晚结一天,明天再来看看
//设置属性
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