|
* H4 q: I0 }. v0 a: q" Q: s一.% U; v) m' C( R
AnsiString nameString("TButton");5 f# ?, Z0 N8 E$ W0 ^" @
TButton * button;1 X0 C6 N3 p$ V6 I- R
for(int i=0; i < ComponentCount; i++)
8 U# w* ^+ S* n" Z4 J5 A# m{, H/ u; E" `7 C+ q+ I
//Check to see if the component is a TButton
" _, G! b" K% g8 B8 V- Kif (Components->ClassNameIs(nameString))& G- Q0 Q j7 \, I6 x' i1 {* K( _
{
. S# R Z! E7 q1 \: m( ]; e* a, ?//cast the component to a TButton *
# g! q& {! i. Y7 K- O3 Ybutton = (TButton *)Components;4 J& D U) _5 D; p* c
button->Font->Name = "Courier";
, l& Q# f, {9 j, p3 X ......
0 I- E8 s5 g2 {$ p4 |
) x) |2 O( W% [+ i/ q二.
2 x+ x% Y7 J2 \$ |7 r0 K2 u我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
: A4 x- b# Y. q用一个需循环0 @( W$ Y0 {! H
TButton* button;: G8 b& @6 B$ C) c3 W- u% m
for(int i=0;i<MainForm->ComponentCount;i++){5 m9 ~9 f& z$ q; [3 c
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
2 d; ?! U- x" t9 `' w( { button->Caption="Button";" ^ p5 t' D1 w; M' b
}
3 @8 m; M, Q" A |