如题,
创建属性编辑器时,它的创建参数不知道怎么填!TPropertyEditor.Create(ADesigner: IDesigner; PropCount: Integer);这个 IDesigner 设计者怎么半, 还有属性个数怎么办?
创建属性编辑器时,它的创建参数不知道怎么填!TPropertyEditor.Create(ADesigner: IDesigner; PropCount: Integer);这个 IDesigner 设计者怎么半, 还有属性个数怎么办?
而且不同版本的 Delphi 对它实现都不一样,正因为如此你也不会在 Delphi 帮助文档中找到相关资料,所以建议你去看看其它组件是如何实现组件编辑器的。
随便创建一个,比如:TPicturePropEditor (不知道拼写有没有错误)。
var
P:TPicture;
pEditor:TPictureEditor;
begin
pEditor:=TPictureEditor.Create(nil);
try
if Execute() then
begin
P:=TPicture.Create;
try
P.Assign(pEditor.Picture);
finally
P.Free;
end;
end;
finally
pEditor.Free;
end;
end;
//别忘了把 DesignIDE.dcp 加入到工程选项的 Build with runtime packages
//DesingIDE.dcp 在 Borland\Delphi7\Lib 目录下。
//我已测试成功。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, PicEdit;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
P:TPicture;
pEditor:TPictureEditor;
begin
pEditor:=TPictureEditor.Create(nil);
try
if pEditor.Execute() then
begin
P:=TPicture.Create;
try
P.Assign(pEditor.Picture);
P.SaveToFile('c:\aa.bmp');
finally
P.Free;
end;
end;
finally
pEditor.Free;
end;
end;end.
private
FGraphicClass: TGraphicClass;
FPicture: TPicture;
FPicDlg: TPictureEditorDlg; //图片选择窗体
procedure SetPicture(Value: TPicture);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Exexcute: Boolean; //显示图片选择窗体
property GraphicClass: TGraphicClass read FGraphicClass write FGraphicClass;
property Picture: TPicture read FPicture write SetPicture; //保存选择的图片
end;
这个类是为了方便真正的属性编辑器 TPictureProperty 编辑图片而设计的类
在它里面包含了一个变量:FPicDlg: TPictureEditorDlg;这个变量就是那个可见的
弹出来的选择图片的窗口。在这个类的成员函数:function Exexcute: Boolean; 中
显示 FPicDlg 窗体供选择图片. TPictureProperty = class(TPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
end;而在这个真正的属性编辑器的 Edit 过程中声明并创建了一个 TPictureEditor 变量
让用户在点击了对象监视器的某个图片属性行上的 ... 按钮后弹出这个窗口供选择图片。procedure TPictureProperty.Edit;
var
PictureEditor: TPictureEditor;
begin
PictureEditor := TPictureEditor.Create(nil);
try
PictureEditor.Picture := TPicture(Pointer(GetOrdValue));
if PictureEditor.Execute then
SetOrdValue(Longint(PictureEditor.Picture));
finally
PictureEditor.Free;
end;
end;cnmaxu(Max) 老兄,你只看到了 Picture、Editor 这两个单词,就相当然的认为它就是个
“图片”(而且还不是属性)、“编辑器”。你还不知道属性编辑器是怎么回事!就来质问我没有搞清概念!真是好笑!
当然你的热心是值得肯定的!
http://www.anylib.com
TPropertyEditor.Create(ADesigner: IDesigner; PropCount: Integer);
这个创建方法如何在代码中使用。
楼主,属性编辑器和属性是两码事,你一直都说属性编辑器,那难道认为 TPictureEditor 不是属性编辑器么?呵呵。Editor 和 Property 这两个单词各是什么意思,楼主,你还是自己解决吧,下次发贴之前最好自己先搞清楚概念再发。