X
xtdragon
Unregistered / Unconfirmed
GUEST, unregistred user!
我有一段代码:
unit WPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls,Menus;
type
TWPanel = class(TPanel)
private
{ Private declarations }
FTPanel:TPanel;
FAPanel:TPanel;
protected
{ Protected declarations }
public
{ Public declarations }
Constructor Create(AOwner:TComponent);override;
Destructor Destroy;override;
procedure FTPanelClick(Sender:TObject);
procedure Change(Sender:TObject);
class procedure mnuPPClear(mnuPP:TPopupMenu);
procedure onPopup(mnuPP:TPopupMenu);
procedure PanelMouseDown(Sender:TObject;Button:TMouseButton;
Shift:TShiftState;X,Y:Integer);
class procedure DeleteAllShapes(ParentControl : TWinControl);
published
{ Published declarations }
end;
Var
mnuPP:TPopupMenu;
implementation
Constructor TWpanel.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
BevelInner:=bvLowered;
BevelWidth:=2;
Height:=235;
Width:=94;
FTPanel:=TPanel.Create(Self);
FTPanel.Parent:=TWpanel(Self);
FTPanel.Height:=25;
FTPanel.Align:=altop;
FTPanel.onClick:=FTPanelClick;
TPanel(Self).onMouseDown:=PanelMouseDown;
end;
Destructor TWPanel.Destroy;
begin
inherited Destroy;
end;
class procedure TWPanel.DeleteAllShapes(ParentControl : TWinControl);
var
i : Integer;
begin {DeleteAllShapes}
// Delete controls from ParentControl
i := 0;
while i < ParentControl.ControlCount do begin
if ParentControl.Controls is TWPanel then begin
ParentControl.Controls.Free;
// Note that there is no need to increment the counter, because the
// next component (if any) will now be at the same position in Controls[]
end else begin
Inc(i);
end;
end;
end; {DeleteAllShapes}
class procedure TWPanel.mnuPPClear(mnuPP:TPopupMenu);
var
i:integer;
begin
for i:=mnuPP.Items.Count-1 DownTo 0 do
mnuPP.Items.Free;
end;
procedure TWPanel.PanelMouseDown(Sender:TObject;Button:TMouseButton;
Shift:TShiftState;X,Y:Integer);
var
p,q:TPoint;
begin
{Selected:=True;}
{ReleaseCapture;
perform(WM_SysCommand,$F012,0);}
if (Button in [mbRight]) then
begin
mnuPPClear(mnuPP);
onPopup(mnuPP);
P.x:=x;
p.y:=y;
q:=ClientToScreen(P);
mnuPP.Popup(q.x,q.y);
exit;
end;
end;
procedure TWPanel.FTPanelClick(Sender:TObject);
var
s:string;
begin
if inputQuery('机架名输入','请输入机架名',s) then
FTPanel.Caption:=s;
end;
procedure TWPanel.onPopup(mnuPP:TPopupMenu);
var
mp:TMenuItem;
begin
mp:=TMenuItem.Create(Self);
mp.Caption:='增加机框';
mp.onClick:=Change;
mnuPP.Items.Add(mp);
end;
procedure TWPanel.Change(Sender:TObject);
begin
{if tmenuitem(sender).Caption='增加机框' then
begin }
FAPanel:=TPanel.Create(self);
FAPanel.Align:=alBottom;
FAPanel.Caption:='仙桃';
FAPanel.Height:=70;
FAPanel.Parent:=TWPanel(self);
{end;}
end;
procedure RegisterStorageClasses;
begin {RegisterStorageClasses}
RegisterClasses([TWPanel]);
end; {RegisterStorageClasses}
initialization
RegisterStorageClasses;
mnuPP:=TPopupMenu.Create(Application);
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
PopupMenu1: TPopupMenu;
add1: TMenuItem;
ScrollBox1: TScrollBox;
Panel1: TPanel;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses wpanel;
{$R *.DFM}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
with twpanel.Create(self) do
begin
left:=x;
top:=y;
parent:=form1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=inttostr(form1.componentcount);
end;
end.
在FORM1中动态建立一个TWPANEL后,窗体的控件数增加一个,但是用弹出菜单建立一个
TPANEL后,TPANEL。PARENT:=TWPANEL(SELF),窗体的控件数并不增加。请问这个问题
应该如何解决。
unit WPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls,Menus;
type
TWPanel = class(TPanel)
private
{ Private declarations }
FTPanel:TPanel;
FAPanel:TPanel;
protected
{ Protected declarations }
public
{ Public declarations }
Constructor Create(AOwner:TComponent);override;
Destructor Destroy;override;
procedure FTPanelClick(Sender:TObject);
procedure Change(Sender:TObject);
class procedure mnuPPClear(mnuPP:TPopupMenu);
procedure onPopup(mnuPP:TPopupMenu);
procedure PanelMouseDown(Sender:TObject;Button:TMouseButton;
Shift:TShiftState;X,Y:Integer);
class procedure DeleteAllShapes(ParentControl : TWinControl);
published
{ Published declarations }
end;
Var
mnuPP:TPopupMenu;
implementation
Constructor TWpanel.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
BevelInner:=bvLowered;
BevelWidth:=2;
Height:=235;
Width:=94;
FTPanel:=TPanel.Create(Self);
FTPanel.Parent:=TWpanel(Self);
FTPanel.Height:=25;
FTPanel.Align:=altop;
FTPanel.onClick:=FTPanelClick;
TPanel(Self).onMouseDown:=PanelMouseDown;
end;
Destructor TWPanel.Destroy;
begin
inherited Destroy;
end;
class procedure TWPanel.DeleteAllShapes(ParentControl : TWinControl);
var
i : Integer;
begin {DeleteAllShapes}
// Delete controls from ParentControl
i := 0;
while i < ParentControl.ControlCount do begin
if ParentControl.Controls is TWPanel then begin
ParentControl.Controls.Free;
// Note that there is no need to increment the counter, because the
// next component (if any) will now be at the same position in Controls[]
end else begin
Inc(i);
end;
end;
end; {DeleteAllShapes}
class procedure TWPanel.mnuPPClear(mnuPP:TPopupMenu);
var
i:integer;
begin
for i:=mnuPP.Items.Count-1 DownTo 0 do
mnuPP.Items.Free;
end;
procedure TWPanel.PanelMouseDown(Sender:TObject;Button:TMouseButton;
Shift:TShiftState;X,Y:Integer);
var
p,q:TPoint;
begin
{Selected:=True;}
{ReleaseCapture;
perform(WM_SysCommand,$F012,0);}
if (Button in [mbRight]) then
begin
mnuPPClear(mnuPP);
onPopup(mnuPP);
P.x:=x;
p.y:=y;
q:=ClientToScreen(P);
mnuPP.Popup(q.x,q.y);
exit;
end;
end;
procedure TWPanel.FTPanelClick(Sender:TObject);
var
s:string;
begin
if inputQuery('机架名输入','请输入机架名',s) then
FTPanel.Caption:=s;
end;
procedure TWPanel.onPopup(mnuPP:TPopupMenu);
var
mp:TMenuItem;
begin
mp:=TMenuItem.Create(Self);
mp.Caption:='增加机框';
mp.onClick:=Change;
mnuPP.Items.Add(mp);
end;
procedure TWPanel.Change(Sender:TObject);
begin
{if tmenuitem(sender).Caption='增加机框' then
begin }
FAPanel:=TPanel.Create(self);
FAPanel.Align:=alBottom;
FAPanel.Caption:='仙桃';
FAPanel.Height:=70;
FAPanel.Parent:=TWPanel(self);
{end;}
end;
procedure RegisterStorageClasses;
begin {RegisterStorageClasses}
RegisterClasses([TWPanel]);
end; {RegisterStorageClasses}
initialization
RegisterStorageClasses;
mnuPP:=TPopupMenu.Create(Application);
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
PopupMenu1: TPopupMenu;
add1: TMenuItem;
ScrollBox1: TScrollBox;
Panel1: TPanel;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses wpanel;
{$R *.DFM}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
with twpanel.Create(self) do
begin
left:=x;
top:=y;
parent:=form1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=inttostr(form1.componentcount);
end;
end.
在FORM1中动态建立一个TWPANEL后,窗体的控件数增加一个,但是用弹出菜单建立一个
TPANEL后,TPANEL。PARENT:=TWPANEL(SELF),窗体的控件数并不增加。请问这个问题
应该如何解决。