|
. G( d: S8 |* c5 Y: }! m
一.; j1 o# A( {& }5 k: F1 N) t% ^2 \# q4 q
AnsiString nameString("TButton");* V$ S# x! F' v
TButton * button;0 E/ j5 U+ k7 [2 i( d
for(int i=0; i < ComponentCount; i++)
; {* Y4 y& S. m# _{/ a, h w( S2 f
//Check to see if the component is a TButton
. w2 s& b" @) K4 q$ mif (Components->ClassNameIs(nameString))
+ i' O* H6 s6 M6 F7 Y+ e0 q{
4 W: k* B# h% C! o2 E//cast the component to a TButton *. n7 W; X- Q# t% U4 P6 P1 ^ |
button = (TButton *)Components;; m5 E3 W4 q: d6 C8 c) P
button->Font->Name = "Courier";
" ?. x) U8 I K. c6 p0 I2 ^ ......
9 |7 ?$ q0 F* m
8 v& ^+ W$ b" V2 R二.! u. P9 ~: ?1 Y. s, b
我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
$ O3 K0 X. g$ V" A( I8 c7 ~用一个需循环
2 X {! q8 ^" w+ MTButton* button;
8 W1 D9 H9 L6 Y: Q3 }6 Z$ rfor(int i=0;i<MainForm->ComponentCount;i++){
9 v5 f! H" D( `! hif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
" \ f) L1 n" a7 W! Z) R& W button->Caption="Button";
7 K+ z4 {* s9 L, T8 O n N4 q}
9 y1 S* T, l, Y, x- g @ |