关于控件开发问题,急急急!!!!!!(100分)

  • 主题发起人 主题发起人 YaoChangLi
  • 开始时间 开始时间
Y

YaoChangLi

Unregistered / Unconfirmed
GUEST, unregistred user!
我进行控件开发时,遇到了一个问题,
例如下面的程序,注册一个新控件TMyEdit,
其中增加了一个属性Control,能选定窗体中的TComponent类的控件

程序如下:

unit MyEdit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TMyEdit = class(TEdit)
private
{ Private declarations }
FC: TComponent;
procedure SetFC(Value: TComponent);
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property Control: TComponent read FC write SetFC default nil;
end;

procedure Register;

implementation

procedure TMyEdit.SetFC(Value: TComponent);
begin
if Value = nil then
FC:= nil
else
if FC <> Value then
FC:= Value;
end;

procedure Register;
begin
RegisterComponents('Samples', [TMyEdit]);
end;

end.

控件注册成功,无错误。

在窗体上放置一个TMyEdit, 再随便放置一个Delphi自带的控件,如( TMainMenu; TImageList等...)
将TMyEdit的Control属性指向(TMainMenu; TImageList等...)
然后用Delete键删除窗体中的(TMainMenu; TImageList等...),没有问题。

可是如果换成其他第三方面的控件,如 QReport, QRPLabel或自己注册的控件等,
然后重复以上操作,就出现错误 "Read Address xxxx FFFFFF ...."的错误,
TMyEdit.Control属性中出现一行怪字符,之后,出现其它一些读指针错误的对话框,有时造成Delphi无法退出。

不知为何?请各位多多指教。

 
你的问题我无法回答,但提个小小建议。一定要删除吗?隐藏可不可以?反正用户看到
的效果是一样的。
 
與MAT觀點一樣
 
谁说没有问题,删除掉什么样的控件都有问题,不管是delphi内置的还是第三方的
unit MyEdit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TMyEdit = class(TEdit)
private
{ Private declarations }
FFocusControl: TWinControl;
procedure SetFC(Value: TWinControl);
protected
{ Protected declarations }
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
public
{ Public declarations }
published
{ Published declarations }
property Control: TWinControl read FFocusControl write SetFC;
end;


procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TMyEdit]);
end;

procedure TMyEdit.SetFC(Value: TWinControl);
begin
FFocusControl := Value;
if Value <> nil then Value.FreeNotification(Self);
end;

procedure TMyEdit.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FFocusControl) then
FFocusControl := nil;
end;

end.
 
the error like this is very normal!
pointer operation error usual be caused such as install compnent and so on!
 
hua8hua说得没错!
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
728
import
I
后退
顶部