如果性属存在一个变量中,Delphi如何设置这个变量啊,如:
var s:='Caption';怎么通过s设置一个From的Caption属性? 如:
form1.s:='标题';
var s:='Caption';怎么通过s设置一个From的Caption属性? 如:
form1.s:='标题';
解决方案 »
- cxGrid的一些问题
- 为什么事务回滚不生效,明明已经Rollback了。
- 如何将两个表关联后select的结果放到一个临时的表中?
- 如何将毫米(MM)单位转换为像素(Pixel)单位,请大家帮帮忙呀!
- 谁用过或研究过Tera Term? 请高手指点一下。
- 怎样在DBGrid中查找?
- 如何让我的datasnap变为无状态?
- 这是什么错误多谢帮助!赶紧!,incompatible types: 'Integer' and 'Extended'
- 高手请进,有关向oracle中blob字段存入word文档的问题???
- 使用UniDac读取Sqlite3存储在Text字段类型内的二进制数据出错
- 如何DELPHI7中使用指针调用?
- 查询
s :='Caption';if isPublishedProp(Form1,s) then
SetPropValue(Form1,s,'标题');
var
s: string;
begin
s := 'Caption';
if GetPropInfo(Form1, s)<>nil then
SetPropValue(Form1, s, '标题');
end;
typinfo;
procedure TForm1.btn3Click(Sender: TObject);
var
PropInfo:PPropInfo;
S:string;
begin
s:='Caption';
PropInfo:=GetPropInfo(Form1, S,tkProperties);
if PropInfo=nil then
ShowMessage('Not found')
else
SetPropValue(Form1,'Caption', '标题');
end;
最简单的方法~
在TForm1类的public部分加入
property S: string write PutCaption;
然后在private部分定义
procedure PutCaption(S: string);
代码如下
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
procedure PutCaption(const S: string);
{ Private declarations }
public
published
property Caption;
property S: string write PutCaption;
{ Public declarations }
end;procedure TForm1.PutCaption(const S: string);
begin
Caption := S;
end;然后就可以用Form1.S := 's';改变标题~
改变和读取属性值是通过相应的函数或者过程来实现的~
通过read 和 write将属性指向相关的功能函数~
如
TMyClass = class
private
{Private}
....
FA: string; //A对应的私有成员
procedure PutA(S: string); //写属性,注意参数类型
function GetA(): string; //读属性,注意返回值类型
...
public
property A: string read GetA write PutA; //属性,注意类型;read一定要在write前面
end;{功能代码不要忘了}function TMyClass.GetA(): string;
begin
Result := FA;
end;procedure TMyClass.PutA(S: string): string;
begin
FA := S;
end;