我想编程序实现以下操作,谁知道怎么做 For i=0 to Form.Componets.count-1 do
begin
if Exists Componets[i].Items:TStrings then
.......
end;是否可以通过程序实现呢?
begin
if Exists Componets[i].Items:TStrings then
.......
end;是否可以通过程序实现呢?
解决方案 »
- 把word文档加到数据库
- 触发器的困惑!!
- [初学者的困惑]我希望我的Delphi程序有更合理的结构,希望大家不吝赐教!
- 能告诉我哪里有系统介绍TREEVIEW的书和贴子吗?(在线!)
- 没分了, 还请教小弟一个问题...
- 在image上画直线,怎样把它删除掉
- listview中选中checkbox后怎么判断是点击的哪行啊?
- 使用ADO组件 根据一个已存在的access表生成创建该表的sql文件
- 刚才一个问题,已经结了,送出去了一百分,现在没有那么多分了,只能送20分,请问怎么样来取服务器上SQL SERVER 的TCP/IP端口号?
- 选了DBRadioGroup中的一个选项,想再点击去掉这个选项,怎么做
- 请问如果让打印机打印完成后自动停下来
- 祈祷sars早日被消灭!
.......
function getProp():boolean;
begin
try
GetPropValue(button1,'Caption');
result:=true;
except
result:=false;
end;
end;
begin
if Componets[i] is Tclassa then //TClasssA为具有items属性的基类
TClassa(Componets[i]).Items...///
.......
end;
请问 firetoucher: TClasssA为具有items属性的基类
这个基类怎么表示?
mylist:TStrings;
Newvalue:Variant;
begin
mylist:=TSTringList.Create;
mylist.Clear;
mylist.add('1111111111111111');
mylist.add('2222222222222222');
for i:=0 to ComponentCount-1 do
begin
Try
Newvalue:=VarArrayFromStrings(mylist);
Setpropvalue(Components[i],'Items',Newvalue);
Except end;
end;
mylist.free;
end;
if TClassa(Componets[i]).Items is TStrings then
caption:=datetimetostr(now);
delphi里面方法:
function GetPropValue(Instance: TObject; const PropName: string;
PreferStrings: Boolean): Variant;
var
PropInfo: PPropInfo;
begin
// assume failure
Result := Null; // get the prop info
PropInfo := GetPropInfo(Instance, PropName);
if PropInfo = nil then
PropertyNotFound(PropName)
else
begin
// return the right type
case PropInfo^.PropType^^.Kind of
tkInteger, tkChar, tkWChar, tkClass:
Result := GetOrdProp(Instance, PropInfo);
tkEnumeration:
if PreferStrings then
Result := GetEnumProp(Instance, PropInfo)
else if GetTypeData(PropInfo^.PropType^)^.BaseType^ = TypeInfo(Boolean) then
Result := Boolean(GetOrdProp(Instance, PropInfo))
else
Result := GetOrdProp(Instance, PropInfo);
tkSet:
if PreferStrings then
Result := GetSetProp(Instance, PropInfo)
else
Result := GetOrdProp(Instance, PropInfo);
tkFloat:
Result := GetFloatProp(Instance, PropInfo);
tkMethod:
Result := PropInfo^.PropType^.Name;
tkString, tkLString:
Result := GetStrProp(Instance, PropInfo);
tkWString:
Result := GetWideStrProp(Instance, PropInfo);
tkVariant:
Result := GetVariantProp(Instance, PropInfo);
tkInt64:
Result := GetInt64Prop(Instance, PropInfo);
tkDynArray:
DynArrayToVariant(Result, Pointer(GetOrdProp(Instance, PropInfo)), PropInfo^.PropType^);
else
raise EPropertyConvertError.CreateResFmt(@SInvalidPropertyType,
[PropInfo.PropType^^.Name]);
end;
end;
end;
,原来getpropvalue可以得到tkclass,但是setpropvalue只能设置value,不能设置对象。
要用setobjectprop,就可以了。 把上面我贴的中间那句替换成:
SetObjectProp(Components[i],'Items',mylist);就ok了,多谢linzhisong的提示,以及各位DX的帮助。