解决方案 »
- 创建窗体内存错误~~求解
- 又是大字段 从excel导入到oracle的大字段
- 如何通过程序为windows创建用户,授与权限,共享文件夹?
- 用什么代码可以实现生成一个ToolButton?
- 怎样用installshiled打包安装程序,由于是第一次用,请解答得详细一些
- Operation not allowed on a unidirectional dataset错误?
- 讨论一个算法
- 关于idhttp的一个简单问题
- 如何把网页(连同图片、FALSH文件)编成EXE文件,并且无法分解。
- 那有中文帮助下载
- 在控件类的published中增加了属性(非只读),但是Object inspector中没有显示
- 创建删除文件的功能实现(求助!)
procedure TForm1.Button1Click(Sender: TObject);
var
mstr1: string;
begin
mstr1 := 'Edit1';
TControl(FindComponent(mstr1)).Visible := false;
end;
不只是控制visible还有其他属性,需要明确到控件类型,所以TControl还不行,
------------------------------------------------我主要是用text属性,界面上有TEdit类型和TDBEditEh类型等控件,要取得每个控件的text属性,所以用TControl不行啊。
var
PropInfo: PPropInfo; //uses TypInfo
mcp: TComponent;
begin
mcp := FindComponent('Edit1');
PropInfo := GetPropInfo(mcp.ClassInfo,'Text');
if Assigned(PropInfo) then
begin
ShowMessage(GetStrProp(mcp,'Text'));
SetStrProp(mcp,PropInfo,'changed');
end;
end;
procedure SetEditText(const AClassName, AEditName, AEditText: String);
var
FVcl: TComponent;
begin
FVcl := FindComponent(AEditName);
if Assigned(FVcl) then
begin
if AClassName = 'TEdit' then
TEdit(FVcl).Text := AEditText
else if AClassName = 'TDbEditEh' then
TDbEditEh(FVcl).Text := AEditText
else
ShowMessage(AClassName + '不可识别!');
end
else
ShowMessage(AEditName + '不存在!');
end;
我现在是这样实现的var
strEditName:string;
strControlKind:string;
strTmp
Begin
...
strEditName:=qryTmp.Fieldbyname('ControlName').asstring;//从数据库的配置表中读取此值(控件名称)
strControlKind:=qryTmp.Fieldbyname('ControlType').asstring;//从数据库的配置表中读取此值(控件类型)
if strControlKind=‘TEdit' then
begin
strTmp:=TEdit(Self.FindComponent(strEditName)).visible:=False;
end
else if strControlKind=‘TDBEditEh' then
begin
strTmp:=TDBEditEh(Self.FindComponent(strEditName)).text;
end
...
感觉这样实现有些繁琐,关键的问题是,如果数据表中某一记录的ControlType字段的值没有在程序的if判断语句中被包含的话,程序就无法取得这个控件的text属性。
感谢gobiz的关注你提供的方法很好,与我上述的方法相比,可以省去数据表中ControlType字段
搞错了,你的方法也还是要使用ControlType字段的。
呵呵,我的方法不用ControlType字段的。
AClassName 其实就是从ControlType字段取值的。
请教,如何用变量替换下列语句中的TEdit呢?
strTmp:=TEdit(Self.FindComponent(strEditName)).visible:=False;
var
i, nCount: Integer;
PropList: PPropList;
PropName:string;
Field :TField;
begin
ncount := GetTypeData(obj.ClassInfo).PropCount;
GetPropList(obj.ClassInfo,PropList);
try
for i := 0 to ncount - 1 do
begin
PropName := PropList[I]^.Name;
Field := query.FindField(PropName); if Assigned(Field) then
begin
case (PropList[I]^.PropType)^.Kind of
tkInteger,tkInt64:
SetOrdProp(obj,PropName,Field.AsInteger);
tkString, tkWChar,tkLString:
SetStrProp(obj,PropName,Field.AsString);
tkWString:
SetWideStrProp(obj,PropName,Field.AsWideString);
end;
end;
end;
finally
FreeMem(PropList);
end;
end;
var
PropInfo: PPropInfo; //uses TypInfo
mcp: TComponent;
begin
mcp := FindComponent('Edit1');
PropInfo := GetPropInfo(mcp.ClassInfo,'Text');
if Assigned(PropInfo) then
begin
ShowMessage(GetStrProp(mcp,'Text'));
SetStrProp(mcp,PropInfo,'changed');
end;
TWinControl(mcp).SetFocus;
end;
好像有classclass、classof之类的
交流第一,得分第二erhan正解youthon的方法很有参考价值
procedure TForm1.Button1Click(Sender: TObject);
var
PropInfo: PPropInfo; //uses TypInfo
mcp: TComponent;
begin
mcp := FindComponent('Edit1');
PropInfo := GetPropInfo(mcp.ClassInfo,'Text');
if Assigned(PropInfo) then
begin
ShowMessage(GetStrProp(mcp,'Text'));
SetStrProp(mcp,PropInfo,'changed');
end;
end;
如果'Edit1'为TRzDBEdit的话,则 PropInfo := GetPropInfo(mcp.ClassInfo,'Text'); 返回nil值。有什么好的办法解决吗?