解决方案 »
- 请指教,如何将access数据库导出为mysql数据库?
- 如何控制StringGrid单元格的属性,例如cells的背景颜色及其是否可以编辑等属性?
- dbgrid的单元格被修改后是立即更新到数据库还是要update一下?
- 有两个adoquery,如何让adoquery2从adoquery1的数据集中搜索数据?
- 我的TSQLConnection连接数据库时找不到gds32.dll,是怎么回事?急,在线等!!!
- 高分问EHLIB的问题,会很快结帖!!!
- ***界面问题,修改之后Save button才能有效,如何做!!
- 關於在SQL SERVER 中復制一個資料表的問題,急急急!!!
- Borland 推出 C++Builder 6!
- 紧急:请各位兄弟帮帮忙,请教如何在我的程序中终止其他程序的运行?????
- 在控件类的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值。有什么好的办法解决吗?