为尊重各位的热情回答,特另开此帖,接原帖:
http://expert.csdn.net/Expert/topic/1658/1658933.xml?temp=.1598017
我做了2个包,pack.dpk,dclpack.dpk,第二个包专门注册控件、参数编辑的设
计时包,我在控件的设计时的右键添加了一功能,打开某编辑窗体进
行编辑,请问如何调用这个窗体?
---------------------------------
type
TPopEdit = class(TComponentEditor)
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
---------------------------------
procedure TPopEdit.ExecuteVerb(Index: Integer);
begin
inherited;
case Index of
0: ;//这里怎么调用EditFrm
end;
end;
---------------------------------
另外,EditFrm应该放在哪个包里? pack.dpk?dclpack.dpk?
控件单元在pack.dpk包里,这个单元要获得EditFrm编辑的参数。
例如:我在comp.pas定义了public变量vStr,
这个变量需要在EditFrm中编辑并获得,如何做?
就是取它的Component就行了
如下:
unit MyTestComponent;
interface
uses
Windows, Messages, SysUtils, Classes;
type
TMyTestComponent = class(TComponent)
private
{ Private declarations }
FFileName: string;
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property FileName: string read FFileName write FFileName;
end;
implementation
end.
这个在MyTestComponentPack
unit MyTestComponentReg;
interface
uses Controls, Classes, DesignIntf, DesignEditors;
type
TMyTestComponentEditor = class(TComponentEditor)
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
procedure Register;
implementation
uses MyTestComponent, EditFormUnit;
{ TMyTestComponentEditor }
procedure Register;
begin
RegisterComponents(GybCtrl, [TMyTestComponent]);
RegisterComponentEditor(TMyTestComponent, TMyTestComponentEditor);
end;
procedure TMyTestComponentEditor.ExecuteVerb(Index: Integer);
begin
if Index = 0 then
with TEditForm.Create(nil) do
try
Edit1.Text := TMyTestComponent(Component).FileName;
if ShowModal = mrOk then
TMyTestComponent(Component).FileName := Edit1.Text;
finally
Free;
end;
end;
function TMyTestComponentEditor.GetVerb(Index: Integer): string;
begin
if Index = 0 then
Result := 设置FileName属性...;
end;
function TMyTestComponentEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
end.
这个和窗体在dclMyTestComponentPack里
property FileNames: Tstrings read FFileNames write FFileNames stored true;
试试