如何实现像Delphi一样,当拖某一控件在主窗体上比如Label,就有相对应的在Object Inspector上进行属性修改? 如何实现像Delphi一样,当拖某一控件在主窗体上比如Label,就有相对应的在Object Inspector上进行属性修改。我做的是画图程序,当画一个正方形时,希望可以修改它的颜色、高等和其它自己定义的属性,属性值已经出入数据库。正方形是自己定义的一个类,继承TGraphics。在一个主窗体上修改就行了。能不能给个简单的例子或者思路,先谢谢了!分不够再加。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 补充:我的图形有多个,因此属性值也不同,修改属性的对话框也不同。就像Delphi中Label和Button的Object Inspector对话框不一样。 你可以从Delphi的TShape组件去继承,如果它的不够你用的话,那你就只能从TGraphic类来继承了,然后加上你需要的属性就行了,要出现在Object Inspector,就必须把它在Published里发布,例如: Published property DatabaseName:String read FDatabaseName write FDatabaseName; to geyobing(银翼天使) 你可能误解我的意思了,你说的是不是在Delphi中的Object Inspector中有DatabaseName属值?我的意思是图形有自己的可视化编辑器,并不和Delphi中的Object Inspector有关系。晚上在线吗? 可以使用第三方组件:DevExpress Inspector v2.02 下载:www.51delphi.com也可以从DELPHI的VCL的一个Object Inspector类继承一个新的属性编辑器,类名我忘了。这几天正在写两篇关于用RTTI实现Object Inspector的文章,晚些时候会发表给大家看看。 还有一点是你继承类所要修改的属性一定要放在Published里面。 to :cg1120(代码最优化-§惟坚韧者始能遂其志§)多谢!等你的文章! 自己创建组件,然后从基类中Published即可 DevExpress Inspector v2.01中有一个例子是关于TdxRTTIInspector的使用方法,我看好象只能和VCL Control的属性相关,读取的是各种VCL的属性,能不能和自己定义的类的属性相关,其它两个倒还可以,不知道我的问题对不对? to:noallTdxRTTIInspector的使用方法我还是不熟悉。 呵呵,有一定的难度的,我以前也做过这东东玩过,不过不理想!:(我的属性窗体是自己做的,不同的组件有不同的属性窗体,运行时,点击某一个物件,先判断该物件 IS TLable则显示其对应的属性窗体记得有一套控件可以在运行期对其移动,调整大小的,当时也懒了,没研究下去!:( TdxRTTIInspector是可以实现在程序运行时得到点击控件的属性并设置属性的,有兴趣的可以在网上下载一个来使用,里面的例子可以说明问题,用法是用。还有关于我写的关RTTI的文章,由于时间很紧,现在只完成程序实现部份,可能不会继续写了。看看来面的程序,点击TGroupBox(gbComponents)里的控件,就可以设置或显示控件属性,不管对动态或静态生成的控件都可以实现:unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, dxCntner, dxInspct, dxOI, ExtCtrls, StdCtrls, Grids, Mask, dxInspRw, ComCtrls, dxExEdtr;type TForm1 = class(TForm) gbComponents: TGroupBox; Image1: TImage; Shape1: TShape; lblStandard: TLabel; Edit1: TEdit; MaskEdit1: TMaskEdit; Button1: TButton; ListBox1: TListBox; CheckBox1: TCheckBox; StringGrid1: TStringGrid; pnlInspector: TPanel; pnlLeftTop: TPanel; cmbComponents: TComboBox; pnlTop: TPanel; pnlRight: TPanel; pnlBottom: TPanel; Splitter: TSplitter; Label1: TLabel; RadioButton1: TRadioButton; ComboBox1: TComboBox; lblAdditional: TLabel; Shape2: TShape; RTTIInspector: TdxRTTIInspector; Shape3: TShape; lblWin32: TLabel; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; TabSheet3: TTabSheet; TreeView1: TTreeView; ProgressBar1: TProgressBar; RadioButton2: TRadioButton; procedure pnlLeftTopResize(Sender: TObject); procedure FormCreate(Sender: TObject); procedure pnlMainEnter(Sender: TObject); procedure cmbComponentsChange(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.pnlLeftTopResize(Sender: TObject);begin with pnlLeftTop do cmbComponents.SetBounds(Left, Top, Width, Height);end;procedure TForm1.FormCreate(Sender: TObject); procedure LoadComponents(AItems: TStrings); var I: Integer; begin with AItems do begin BeginUpdate; try Clear; for I := 0 to gbComponents.ControlCount - 1 do AItems.Add(gbComponents.Controls[I].Name); finally EndUpdate; end; end; end;begin LoadComponents(cmbComponents.Items); cmbComponents.ItemIndex := 0;end;procedure TForm1.pnlMainEnter(Sender: TObject);begin if cmbComponents.Items.IndexOf(TComponent(Sender).Name) > -1 then begin cmbComponents.ItemIndex := cmbComponents.Items.IndexOf(TComponent(Sender).Name); RTTIInspector.BeginUpdate; RTTIInspector.InspectedObject := nil; RTTIInspector.InspectedObject := FindComponent(cmbComponents.Text); RTTIInspector.EndUpdate; end;end;procedure TForm1.cmbComponentsChange(Sender: TObject);begin RTTIInspector.InspectedObject := FindComponent(cmbComponents.Text);end;end. 就是实现 mrtxc(阿春) 和 shuixin13(犬犬(心帆)) 所说的那样。to:cg1120(代码最优化-§惟坚韧者始能遂其志§) 我先试试你的方法,先谢谢你! to:cg1120(代码最优化-§惟坚韧者始能遂其志§) 就是这种效果,如果能够把Button,Image,Label换成我做的各种图形就行了。 实现模糊匹配的问题 我有表中有一个字段fColor是想保存颜色的值,请问用TColorDialog调出来的颜色怎么保存在后台数据库呢? 上吊跳楼也要问的问题!!! 怎么动态的给DBGrid加标题? 接分帖之二(xzhbaggio) delphi richedit编辑文本问题 如何在系统托盘添加自己程序的图标,多谢各位大哥不吝赐教! 闲人莫入,给一些朋友一些分,不是作弊是承诺!借宝地一用!班主莫删 邦特思泰会员管理软件 高手帮忙,怎么将大量的数据同时人库! shape3为什么不动? 对不起,好久没上CSDN了。关于MU的窗口化程序和其他一些事情!
Published
property DatabaseName:String read FDatabaseName write FDatabaseName;
你可能误解我的意思了,你说的是不是在Delphi中的Object Inspector中有DatabaseName属值?
我的意思是图形有自己的可视化编辑器,并不和Delphi中的Object Inspector有关系。
晚上在线吗?
也可以从DELPHI的VCL的一个Object Inspector类继承一个新的属性编辑器,类名我忘了。这几天正在写两篇关于用RTTI实现Object Inspector的文章,晚些时候会发表给大家看看。
多谢!等你的文章!
TdxRTTIInspector的使用方法我还是不熟悉。
有一定的难度的,
我以前也做过这东东玩过,
不过不理想!:(
我的属性窗体是自己做的,
不同的组件有不同的属性窗体,
运行时,点击某一个物件,先判断该物件 IS TLable
则显示其对应的属性窗体
记得有一套控件可以在运行期对其移动,调整大小的,
当时也懒了,没研究下去!:(
看看来面的程序,点击TGroupBox(gbComponents)里的控件,就可以设置或显示控件属性,不管对动态或静态生成的控件都可以实现:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
dxCntner, dxInspct, dxOI, ExtCtrls, StdCtrls, Grids, Mask, dxInspRw,
ComCtrls, dxExEdtr;type
TForm1 = class(TForm)
gbComponents: TGroupBox;
Image1: TImage;
Shape1: TShape;
lblStandard: TLabel;
Edit1: TEdit;
MaskEdit1: TMaskEdit;
Button1: TButton;
ListBox1: TListBox;
CheckBox1: TCheckBox;
StringGrid1: TStringGrid;
pnlInspector: TPanel;
pnlLeftTop: TPanel;
cmbComponents: TComboBox;
pnlTop: TPanel;
pnlRight: TPanel;
pnlBottom: TPanel;
Splitter: TSplitter;
Label1: TLabel;
RadioButton1: TRadioButton;
ComboBox1: TComboBox;
lblAdditional: TLabel;
Shape2: TShape;
RTTIInspector: TdxRTTIInspector;
Shape3: TShape;
lblWin32: TLabel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TreeView1: TTreeView;
ProgressBar1: TProgressBar;
RadioButton2: TRadioButton;
procedure pnlLeftTopResize(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure pnlMainEnter(Sender: TObject);
procedure cmbComponentsChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.pnlLeftTopResize(Sender: TObject);
begin
with pnlLeftTop do
cmbComponents.SetBounds(Left, Top, Width, Height);
end;procedure TForm1.FormCreate(Sender: TObject);
procedure LoadComponents(AItems: TStrings);
var
I: Integer;
begin
with AItems do
begin
BeginUpdate;
try
Clear;
for I := 0 to gbComponents.ControlCount - 1 do
AItems.Add(gbComponents.Controls[I].Name);
finally
EndUpdate;
end;
end;
end;
begin
LoadComponents(cmbComponents.Items);
cmbComponents.ItemIndex := 0;
end;procedure TForm1.pnlMainEnter(Sender: TObject);
begin
if cmbComponents.Items.IndexOf(TComponent(Sender).Name) > -1 then
begin
cmbComponents.ItemIndex := cmbComponents.Items.IndexOf(TComponent(Sender).Name);
RTTIInspector.BeginUpdate;
RTTIInspector.InspectedObject := nil;
RTTIInspector.InspectedObject := FindComponent(cmbComponents.Text);
RTTIInspector.EndUpdate;
end;
end;procedure TForm1.cmbComponentsChange(Sender: TObject);
begin
RTTIInspector.InspectedObject := FindComponent(cmbComponents.Text);
end;end.
就是这种效果,如果能够把Button,Image,Label换成我做的各种图形就行了。