|
5 P4 {# T: e% R0 O
一.
) o+ F/ x* j5 r/ w/ b& e I$ V2 jAnsiString nameString("TButton");; E" s6 z, t1 Q; O
TButton * button;# P7 v) N4 F) E3 i Q, G
for(int i=0; i < ComponentCount; i++)
- l. a: H7 ^# Q6 Z R{$ @- N+ }8 D. h& l! R+ B Y- O
//Check to see if the component is a TButton F! F' {' p) c9 ]$ A, S0 Y
if (Components->ClassNameIs(nameString))
+ p+ g# G' t/ c Z{% i) ?( {, ~3 w- E
//cast the component to a TButton *
3 f" R# i; x* {- Vbutton = (TButton *)Components;3 H, O, a0 ~1 A9 a* h- t
button->Font->Name = "Courier"; O, o0 D& h% |+ y% A; N& G7 {5 `
......
8 b$ ?1 y, |7 b. N
3 ^0 w7 G- B/ h, w1 Q( F二.
$ {+ Z/ U8 l2 c% o4 ~* G我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
$ P$ C( d+ Q- ?- k' X! m用一个需循环
4 g# Q- J* {4 `2 W6 x8 e" |' TTButton* button;
" f4 b$ O4 Q# z* pfor(int i=0;i<MainForm->ComponentCount;i++){
+ p( J+ T- ~+ O. Dif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )2 p) p; s* q$ _: R B! Y" k' i
button->Caption="Button";) Y" `5 Y1 V# t
}
1 e) s* i- W; S, {7 M |