|
+ w+ c2 G3 D1 q2 u9 B$ k" R& a; r一.
3 B! l' x) k! p& k' u- Z! hAnsiString nameString("TButton");
9 K/ J% \2 ?2 Y7 N, [# ]TButton * button;
. D# ]0 W8 I' B& f+ x3 |$ mfor(int i=0; i < ComponentCount; i++)
, g% b+ I9 v: U% _8 a L. ~{, E$ B* `& I, J9 q& K# p
//Check to see if the component is a TButton& d# f# L- ^$ i, x/ X+ {
if (Components->ClassNameIs(nameString))
. b/ I: y+ ]) w6 Z5 |$ s{
5 E3 c' F. z/ `4 t6 o( m2 _//cast the component to a TButton *
' }" r1 C- L" ]6 v+ W" y! R; Pbutton = (TButton *)Components;7 g! B1 h! J6 L k, m
button->Font->Name = "Courier";2 u l- @- ?; N' r* s" ~* `
...... 0 y2 `) m: ~) E7 g8 J' }3 f
$ H- ^9 U0 E# @' O二.
O+ O, ` I, Y+ b6 g. O2 o5 M我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
9 T9 ^3 I- T5 \: ]- P! X( \' O" T6 e1 C! ?用一个需循环
/ h5 Y* E0 Y* j! ^TButton* button;
' E# t8 x- i) @. Y' T: P* g% Nfor(int i=0;i<MainForm->ComponentCount;i++){7 C3 U' R5 q8 ^$ S5 L
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )) w4 S) T+ p7 S( l) d
button->Caption="Button";, {# d4 E& z8 s, V, m: P6 o! W7 S
}
' Q* J; b8 Z2 l& l" } |