Delphi 使用TcxRTTIInspector(RTTI)
效果图如下:

本程序使用了DEV组件的(TcxRTTIInspector控件),和SC组件的几个基本控件,SC控件为非必须,只是为了方便演示.
设计图:

核心代码:
var Form5: TForm5; arr: array of Integer; implementation {$R *.dfm} //遍历窗体中所有控件,把它们加入到组合框里.同时用arr记录这个控件的序号,一会儿用到. procedure TForm5.FormCreate(Sender: TObject); var i, j: Integer; begin j := 0; SetLength(arr, 100); for i := 0 to ComponentCount - 1 do begin if Components[i].Name <> '' then begin scGPComboBox1.Items.Add; scGPComboBox1.Items[i].Caption := Components[i].Name; arr[j] := i; //arr里记录并对应着组合框里每个控件的序号 j := j + 1; end; end; SetLength(arr, j); end;
procedure TForm5.scGPComboBox1Change(Sender: TObject);
begin
//设置RTTI监测对象为组合框里选择的对象
cxRTTIInspector1.InspectedObject := Components[arr[scGPComboBox1.ItemIndex]];
cxRTTIInspector1.SetFocus;
Self.Caption :=scGPComboBox1.Items[scGPComboBox1.ItemIndex].Caption
//Self.Caption :=Components[arr[scGPComboBox1.ItemIndex]].name;
end;
使用技巧:
1.生成Release单独文件,然后再IDE外运行,可以避免IDE频繁的使用 F9 来查看调试结果. 可以先在程序里调到满意之后,再把设置抄到IDE里
2.如果面版空间有限,可以做成一个外挂式的子窗口,也是可以的
                    
                
                
            
        
浙公网安备 33010602011771号