delphi中能否变通地实现宏代换?
delphi中能否变通地实现宏代换?
var strEditName:string; Begin strEditName:='edtStudentName'; //从数据库的配置表中读取此值 TEdit(Self.FindComponent(strEditName)).visible:=False;
var strEditName:string; strControlKind:string;Begin strEditName:='edtStudentName'; //从数据库的配置表中读取此值(控件名称) strControlKind:='TEdit'; //从数据库的配置表中读取此值(控件类型) strControlKind(Self.FindComponent(strEditName)).visible:=False;
procedure TForm1.Button1Click(Sender: TObject);var mstr1: string;begin mstr1 := 'Edit1'; TControl(FindComponent(mstr1)).Visible := false;end;
[解决办法]
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;
[解决办法]
class procedure TFunction.LoadPropValues(query: TADOQuery; obj: TComponent);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;
[解决办法]