怎麼樣取得Form上所有帶Caption屬性的控件並取得它們的Caption屬性?

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        pnl1: TPanel;
        Label1: TLabel;
        Button2: TButton;
        RadioButton1: TRadioButton;
        CheckBox1: TCheckBox;
        ListBox1: TListBox;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        procedure CrnGetCtrlCaptions(pList: TStrings);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
                      
    { TForm1 }
    uses TypInfo;procedure TForm1.CrnGetCtrlCaptions(pList: TStrings);
    var
        i: Integer;
    begin
        for i := 0 to ComponentCount - 1 do
        begin
            if IsPublishedProp(Components[i], 'Caption') then
                pList.Add(
                GetPropValue(Components[I], 'Name')
                + ' --> ' +
                GetPropValue(Components[I], 'Caption'));
        end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
        CrnGetCtrlCaptions(ListBox1.Items);
    end;end.
      

  2.   

    在Delphi版蹭点分实在是难哦。