|
) w% \( X8 @( G; \1 H% j/ M一.
; s; l9 y v9 ]1 x1 }AnsiString nameString("TButton");; L/ ~; o" g V
TButton * button;
! [- Z3 X# v8 n1 o8 P6 ofor(int i=0; i < ComponentCount; i++)4 d. T, y" D' S8 s+ C1 a: ^" E
{6 p) }" {! Z3 {' R' W6 c
//Check to see if the component is a TButton
% C5 ]1 }7 {, y* s7 t$ h0 w0 nif (Components->ClassNameIs(nameString))
% c* h4 u$ k. R. {" w{
3 U/ t$ S* l# I: {, M//cast the component to a TButton *
( C8 G* ^( |" K) xbutton = (TButton *)Components;
. g8 O l R3 Q' I6 ibutton->Font->Name = "Courier";! h8 ?! o( ? J6 \
......
$ b" j' k6 R' @* w" x+ ?* Z; g: u5 k" v' d4 Y3 T% V& p
二. t, u* O1 |* m6 _4 |7 o( n- G
我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).7 f7 S, j5 J! e e; C7 X' |
用一个需循环
/ X; a1 N" U: @; g8 s& u/ {# cTButton* button;
9 p2 j( X- ~% w" `" B( Cfor(int i=0;i<MainForm->ComponentCount;i++){
2 K* |# L4 Z: S1 F. J! R! E% O8 gif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )$ s2 ~" ? S( E5 s' Q" M
button->Caption="Button";
) f7 @9 y# E4 W, x+ ?9 A}5 u. o) T9 Q6 d; v5 j% s: L* l* L& f
|