|
- x9 K8 P4 N# K1 l r. o1 D. C, x一.' t; Z" ^0 q* a, k
AnsiString nameString("TButton");
" [0 F/ D! S' ]9 K0 f* ?* rTButton * button;3 o1 V$ P4 _" [! r
for(int i=0; i < ComponentCount; i++). S3 e& \. X! J$ y7 v; X" I
{. a4 G3 t* f& H) B* w$ ?
//Check to see if the component is a TButton
0 y) x* m8 g; [$ Fif (Components->ClassNameIs(nameString))
t6 ] I9 e! t" t7 _7 }{
& l' k- M- f. K8 V/ G; }//cast the component to a TButton *
" D5 r' S) {/ Y5 {8 e( W% V6 ybutton = (TButton *)Components;
% z C# p, y% D" ]* Hbutton->Font->Name = "Courier";
; _, R8 P( H4 Z' ^+ P ......
* k2 M# k G. x2 s# ^) `' n) ?
: v/ W: v4 W9 K q# |二.
7 t! n% A2 P! \, l6 O: |* ]+ L: Q我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).. B3 d. z6 w9 v+ t
用一个需循环7 [9 B( ]% L" S- g# n0 j
TButton* button;
; C2 S. t/ D; X% [) lfor(int i=0;i<MainForm->ComponentCount;i++){
$ H1 x$ w; N) t- Z& }7 _# Aif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )0 S+ t2 D8 g k
button->Caption="Button";& Z+ o/ L U1 f3 ^
}0 R6 l% x+ E" ^5 U
|