|
+ _- S& k1 Y2 w" E- k
一.
8 F; z9 ]5 b- _4 u, M" A4 b3 vAnsiString nameString("TButton");, E: k! a) w/ ?2 A m4 B
TButton * button;
" p6 v7 b9 y8 t# H3 v& b8 o- Efor(int i=0; i < ComponentCount; i++)
- V& q; m5 i! ~$ b{8 K* a8 A) r- O7 a b# V4 S% y& \2 s% ]
//Check to see if the component is a TButton; Y- K6 r0 q$ q
if (Components->ClassNameIs(nameString))+ Q3 a& l1 m6 m9 Q8 f- W& l- [$ z
{# v+ S+ a9 `' v8 j$ Y
//cast the component to a TButton *
5 x5 ~% d) l3 d: W4 h% ~button = (TButton *)Components;
) }. Y3 u0 }; p3 p: a$ {2 Tbutton->Font->Name = "Courier";* {! o8 o* M5 T5 l E1 e' r! J
......
* N. r( {5 g: ]$ b2 C( J8 t' K' R% J8 {9 X; T
二.5 [3 b! S3 ]1 m) R* J0 x, B
我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
9 f& u" @( c4 ^% V4 ]用一个需循环
3 ]6 [, N' }0 Y9 TTButton* button;- a+ b$ @7 N/ F9 m! a
for(int i=0;i<MainForm->ComponentCount;i++){
2 C+ w4 b2 d; ~/ s3 m$ iif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL ) s* R, H @+ a
button->Caption="Button";
3 {/ @- w( p5 b- A, v& o}8 b9 T0 N8 w, @& G
|