例如,我知道字符串 Button1.Font, Size ,11我该如何在运行期设置Button1.Font.Size=11  ?

解决方案 »

  1.   

    不明白
    你是想动态设定button1.font.size吗?
    buttonl onclick
      button1.font.size := 11;
    还是你有别的意思?
      

  2.   

    我将所有控件的属性保存到数据库里,然后从数据库中读取到字符串Button1, Font, size,11,我该怎样去将窗体中控件名是Button1的Button的Font.Size设为11?
      

  3.   

    在Form的OnCreate事件上加上:
      button1.font.size := 11;
      

  4.   

    大哥,从数据库读出的字符串Button1, Font, size,11,始终是一个变量而已
    你无法把它转换成一个对象。
      

  5.   

    procedure form1.FormCreate(Sender: TObject);
    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;
      

  6.   

    TButton(FindComponent('Button1')).Font.Size := 11;
      

  7.   

    從數據庫中讀出數據組合為語句﹐在用Wally_wu(韦利)的方法寫就可以了﹒
      

  8.   

    我可以找到这个Component,但是Button1的属性有很多,难道一个个去赋值???能不能将Button1.Font转换成类?
      

  9.   

    我的意思是把字符串 Button1.Font 转换成类,有没有这种方法?
      

  10.   

    属性应该是不行的吧,我记得以前人家就是用case
      

  11.   

    是说中文id 吗?为什么要买中文id阿,那里可以买?
      

  12.   

    我知道存了哪些属性,可是不同的控件保存的属性不同,
    用Set*Prop可以设置控件的一般属性,可是对于这种复合的属性改怎么办?alphax(赚点可用分,买个中文ID) ,老大,您老在玩什么呢????
      

  13.   

    记录的时候是用了笨方法,将需要的属性保存起来,
    例如,Button1,需要Font,Caption等,
      

  14.   

    那你上面提到的Set*Prop是什么阿?
      

  15.   

    没有这个函数阿,不过我要下班了,你要找我就用msn
    [email protected]
      

  16.   

    unit Unit1;interfaceuses
      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.
      

  17.   

    : alphax(多喝了三五杯)老大,你的方法也太辛苦了吧????!!!!