DELPHI TPanel 控件KEYDOWN事件中删除自己报错 5
代码如下:unit1.pas代码:unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Gr...
代码如下:
unit1.pas代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
pnl1: TPanel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
pnl:TCtrlBase;
begin
pnl:=TCtrlBase.createA(nil);
pnl.Parent:= pnl1;
end;
end.
unit Unit2;
interface
uses SysUtils,Controls, Windows,Classes,ExtCtrls,Messages,RzPanel,Dialogs;
type
TCtrlBase=class(TPanel)
protected
。。。字数限制,请见谅
procedure TCtrlBase.SelfKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=46 then
begin
try
Self.Parent:=nil;
FreeAndNil(self);
Exit;
except
end;
end;
end;
释放自己的时候报内存错误。。 展开
unit1.pas代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
pnl1: TPanel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
pnl:TCtrlBase;
begin
pnl:=TCtrlBase.createA(nil);
pnl.Parent:= pnl1;
end;
end.
unit Unit2;
interface
uses SysUtils,Controls, Windows,Classes,ExtCtrls,Messages,RzPanel,Dialogs;
type
TCtrlBase=class(TPanel)
protected
。。。字数限制,请见谅
procedure TCtrlBase.SelfKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=46 then
begin
try
Self.Parent:=nil;
FreeAndNil(self);
Exit;
except
end;
end;
end;
释放自己的时候报内存错误。。 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏5(财富值+成长值)
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询