|
% o6 f8 S: X" K) W' y: R
一.
3 M# I5 j& U# h+ X2 f# ]AnsiString nameString("TButton");1 Z! G/ Y$ r" H5 V5 r9 L3 _ U
TButton * button;
7 K/ Z" ~% ]* H+ Ufor(int i=0; i < ComponentCount; i++)
3 h$ R; b8 p2 g{3 B+ ` I9 N) W7 K/ H
//Check to see if the component is a TButton1 y) x0 L6 v8 w$ }
if (Components->ClassNameIs(nameString))- o" q3 u; W% Z# Y; B: o; I0 U, o
{
+ n5 R' J+ t8 \) E//cast the component to a TButton *: D( l( j Z# z5 @. v+ `. e
button = (TButton *)Components;
: r- H9 R. i; e: ubutton->Font->Name = "Courier";' I" |( `) b$ L/ g7 a
......
, l* L% x. f4 s" K" S" f
1 S% k2 e9 H0 {5 {$ `) n% ]% j二.* D3 E9 p( Y0 r1 u
我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
$ Z+ ?' `; k. I4 ]" h+ H2 j用一个需循环" R1 a% E( i& z1 K9 u8 t+ u
TButton* button;6 a" j1 `% l p. i
for(int i=0;i<MainForm->ComponentCount;i++){$ w1 r3 I# P9 Y7 L% \8 p6 t g/ w
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
6 ~% D# L. D/ @1 O+ w, O button->Caption="Button";6 h0 N- X3 W& L' e
}" p" T9 s3 Y/ W7 E4 }' A
|