自己写控件为何出错--白送100分(100分)

  • 主题发起人 主题发起人 DUDU
  • 开始时间 开始时间
D

DUDU

Unregistered / Unconfirmed
GUEST, unregistred user!
第一次写控件,需要从TCustomControl继承,我就自己写乐一个unit,内容如下
//没写完,还不知道怎么写
然后自己在程序里面动态创建,出错,是不是我类里面还应该写写什么,请教高人
不要笑我
unit kh_XYPlot;

interface

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

type
TKH_XYPlot = class;
TKH_XYPlot = class(TCustomControl)
private
FBorderStyle: TBorderStyle;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation

{ TKH_XYPlot }

constructor TKH_XYPlot.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
csSetCaption, csOpaque, csDoubleClicks, csReplicatable];

width:=100;
height:=100;

end;

procedure TKH_XYPlot.CreateParams(var Params: TCreateParams);
const
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or BorderStyles[FBorderStyle];
if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
begin
Style := Style and not WS_BORDER;
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
end;
WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
end;
end;

destructor TKH_XYPlot.Destroy;
begin

inherited;
end;

end.
 
出错的提示是什么?
 
访问代码如下.说我访问地址000000了,冤枉啊
var
Form1: TForm1;
varx:TKH_XYPlot;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
varx.Create(form1);
varx.Parent:=form1;
end;
 
试一试:
begin
varx:=TKH_XYPlot.Create(form1); //
varx.Parent:=form1;
end;
 
同意creation-zy,
varx.Create(form1);
varx.Parent:=form1;
不对
varx还没有分配内存,所以不能调用varx.create过程
 
高人啊,谢谢你
 
I agree creation-yy!
 

Similar threads

后退
顶部