|
) N: R' X$ S/ Q8 ^+ J! j N8 N8 ]一.% D8 U; K$ g( z- t- {3 w! d
AnsiString nameString("TButton");
, Q' a; g- N2 ITButton * button;
8 |& Y4 V1 ]% S; L6 ?* Z0 p: ^for(int i=0; i < ComponentCount; i++)0 S2 L; _, k B V) Z
{ K! z- d$ Y( \; j5 K
//Check to see if the component is a TButton
- R) t! C9 \0 q9 Q& Yif (Components->ClassNameIs(nameString))
2 R. a' s- ?8 v s) Y' @; W* m{
5 L' Z2 N' |) {: ?2 I' V/ L//cast the component to a TButton *
' G, g! s6 E8 _9 abutton = (TButton *)Components;$ x' P$ V2 B% j1 {7 {
button->Font->Name = "Courier";& L$ r5 X1 m, U: m
......
1 a5 F- h4 x5 q
; a6 Y/ o& X3 T6 D, `二.
0 ^' O% ~+ V5 ]我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).5 W: T- G+ C- c, L' u
用一个需循环3 V# e" |# \- @
TButton* button;4 W# L0 C0 R- I
for(int i=0;i<MainForm->ComponentCount;i++){. `9 k# Y9 N m& A" O
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
) n/ v* D( ^! m button->Caption="Button";: ]0 k: c. g& u1 |$ [
}
2 H) G4 f: t2 r, c# ] |