例如,我知道字符串 Button1.Font, Size ,11我该如何在运行期设置Button1.Font.Size=11 ?
解决方案 »
- 有没这种注释插件~~~?
- DateTimePicker1控件的賦值問題,,姐姐哥哥們。幫幫哦
- Visual FoxPro数据源如何建立
- 请教老冯,编译完成后在运行时没有办法输入任何字符是为什么啊?
- 关于stringgrid中删除选定行的问题
- 关于控件的一个问题
- 各位大哥,帅哥,救救小弟。。。5555555555555555555555
- 刚刚注册成功,各位以后多关照啊!
- 戒CSDN一月,天天只能来这边看别人的贴子 可怜……,一个问题都不能回答 可悲……还是充充电再来!顺便送点分,留着又不能当饭吃^_^(有史以来第一次送分)
- 如何将RGB的JPG图片转成CMYK的JPG,请指点下,谢谢。
- 我在用ActiveX的TShockwaveFlash的时候,当改变窗体大小的时候,TShockwaveFlash却不能………
- 我做的flash播放器,请大家提点意见,有分加的哦.
你是想动态设定button1.font.size吗?
buttonl onclick
button1.font.size := 11;
还是你有别的意思?
button1.font.size := 11;
你无法把它转换成一个对象。
var
i: integer;
begin
for i:=0 to form1.componentcount -1 do
begin
if Components[i].Name = 'Button1' then
button1.font.size := 11;
end;
end;
用Set*Prop可以设置控件的一般属性,可是对于这种复合的属性改怎么办?alphax(赚点可用分,买个中文ID) ,老大,您老在玩什么呢????
例如,Button1,需要Font,Caption等,
[email protected]
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
uses
TypInfo;var
tk : TTypeKind;procedure ParseProp(var aText, aProp: string; const aDelimiter: Char);
var
P, Q: Integer;
function IsSetProp: Integer;
begin
if aText = '' then begin Result := -1; Exit; end;
Result := 1;
for Result := 1 to Length(aText)-1 do
begin
if not (aText[Result] in ['[', ' ', #9]) then
Break
else if aText[Result] = '[' then Exit
end;
Result := -1;
end;
procedure Error; //overwrite this function
begin
end;
begin
P := IsSetProp;
if P = -1 then
begin
P := Pos(aDelimiter, aText);
if P > 0 then
begin
aProp := Copy(aText, 1, P-1);
aProp := Trim(aProp); if aProp = '' then Error;
Delete(aText, 1, P);
end
else
begin
aProp := Trim(aText);
aText := '';
end;
end
else
begin
for Q := P to Length(aText) do
begin
if aText[Q] = ']' then Break;
end;
if aText[Q] <> ']' then Error;
aProp := Copy(aText, P, Q-P+1);
Delete(aText, 1, Q);
end;
end;procedure SetPropCmd(aForm: TForm; aSetCmd: string);
var
I: Integer;
ObjProp, ValueProp: string;
Obj: TObject;
SetValues: TStringList; procedure Error; //overwrite this function
begin
end;begin
ParseProp(aSetCmd, ObjProp, ',');
Obj := aForm.FindComponent(ObjProp);
if Obj = nil then Error;
while True do
begin
ParseProp(aSetCmd, ObjProp, ','); case PropType(Obj, ObjProp) of
tkClass: Obj := GetObjectProp(Obj, ObjProp);
tkInteger:
begin
ParseProp(aSetCmd, ValueProp, ',');
SetOrdProp(Obj, ObjProp, StrToInt(ValueProp));
Break;
end; tkLString, tkWString, tkString:
begin
ParseProp(aSetCmd, ValueProp, ',');
ValueProp := AnsiDequotedStr(ValueProp, '''');
SetStrProp(Obj, ObjProp, ValueProp);
Break;
end; tkSet:
begin
ParseProp(aSetCmd, ValueProp, ',');
if ValueProp[1] <> '[' then Error;
SetSetProp(Obj, ObjProp, ValueProp);
Break;
end; tkEnumeration:
begin
ParseProp(aSetCmd, ValueProp, ',');
SetEnumProp(Obj, ObjProp, ValueProp);
Break;
end; //tkChar, tkFloat... implementation your self else
tk := PropType(Obj, ObjProp);
Error;
end;
end;
end;
procedure Usage;
begin
SetPropCmd(Form1, 'Edit1, Text, ''不要吝惜你的可用分'''); //str value must be quoted
SetPropCmd(Form1, 'Edit1, Font, Style, [fsBold]'); //set value
SetPropCmd(Form1, 'Edit1, Color, $00C9C9C9'); //int value
SetPropCmd(Form1, 'Edit2, BorderStyle, bsNone'); //enum value //do not forgot the below note
SetPropCmd(Form1, 'Edit2, Text, ''<<<捐点分给我吧>>>''');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Usage;
end;end.