这个组件有什么问题,请解答?没多少积分了,我愿意全部抛出来(24分)

Z

zraul

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Dragpanel;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, DB, DBTables, ExtCtrls;

type
TDragpanel = class(TComponent)
Panel1:TPanel;
Label1:TLabel;
Dragbutton:TButton;
private
FPanelText: string;
//FCardIndex:integer;
{ Private declarations }
protected

{ Protected declarations }
public
{ Public declarations }
procedure SetPanelText(value: string);
//procedure SetCardIndex(value: integer);
published
{ Published declarations }
property PanelText: string read FPanelText write SetPanelText;
//property CardIndex: integer read FCardIndex write SetCardIndex;
constructor Create( AOwner : TComponent ); override;
end;

procedure Register;

implementation

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

constructor TDragpanel.Create( AOwner : TComponent );
begin
Panel1.Height:=80;
Panel1.Width:=30;
Label1.WordWrap:= True;
Label1.font.Size:= 8;
Label1.width:= 12;
Label1.WordWrap:= True;
Label1.AutoSize:= False;
Label1.left :=(Panel1.Width-Label1.Width) div 2+Panel1.Left;
Label1.top :=(Panel1.Height-Label1.Height) div 2+Panel1.top;
end;

procedure TDragpanel.SetPanelText(value: string);
begin
Label1.Caption := value;
end;

{procedure TDrag_panel.SetCardIndex(value:integer);
begin

end;
}


end.
 
我要实现的就是自定义组件,由一个panel和一个label的组合,我一使用就出现系统错误,什么access ** 0000F550。。。。。。。。。
根本都放不进去,
这是为什么啊,我实在是不懂
 
晕倒!你的Panel1,Label1都没有Create就用?!你还是找些Delphi的基础资料看看吧。
 
是呀,
constructor TDragpanel.Create( AOwner : TComponent );
begin
//先create吧,再说别的
panel1 := Tpanel.create(self);
Label1 := TLabel.create(self);
........
end;
 
恩,惭愧!
这次加上了,不出刚才那个问题了,但是出来新问题了,就是它不能和正常控件一样,放到form里头(没反应)。
 
Panel1.Parent := self;
Label1.Parent := Panel1;
 
不行啊,它说类型不匹配,怎么办??
Panel1.Parent := self;
[Error] Dragpanel.pas(45): Incompatible types: 'TWinControl' and 'TDragpanel'
 
把 TDragpanel = class(TWinControl)改下,

还有 constructor Create( AOwner : TWinControl);
 
Access violation at address 000000.read of address 0000000,
还是有问题啊》
 
据说,这个问题主要是访问了未被创建的组件,但我这个组件都创建了啊,我把
Dragbutton:TButton;也给注释掉了,但还是同样的问题,没办法解决啊。
 
试试,
TDragpanel = class(TWinControl)
Panel1:TPanel;
Label1:TLabel;
Dragbutton:TButton;
private
FPanelText: string;
//FCardIndex:integer;
{ Private declarations }
protected

{ Protected declarations }
public
{ Public declarations }
procedure SetPanelText(value: string);
//procedure SetCardIndex(value: integer);
published
{ Published declarations }
property PanelText: string read FPanelText write SetPanelText;
//property CardIndex: integer read FCardIndex write SetCardIndex;
constructor Create( AOwner : TWinControl);
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

...................
constructor TDragpanel.Create(AOwner: TWinControl);
begin
panel1 := Tpanel.create(self);
panel1.Parent := AOwner;
Label1 := TLabel.create(Panel1);

Panel1.Left := 80;
Panel1.Height:=200;
Panel1.Width:=300;
Panel1.Align := alClient;

Panel1.Caption := 'p';
Label1.WordWrap:= True;
Label1.font.Size:= 12;
Label1.font.Color := ClRed;
Label1.width:= 12;
Label1.WordWrap:= True;

Label1.left :=(Panel1.Width-Label1.Width) div 2+Panel1.Left;
Label1.top :=(Panel1.Height-Label1.Height) div 2+Panel1.top;
Label1.Parent := Panel1;
Label1.Width := 20;
Label1.Caption := 'test'

end;
 
建议你的控件从Tpanel或者TCustomPanel继承,然后在里面增加一个TLabel,然后设置一下Label的Parent就行了。
 
楼主连一点基础都没有,怎么就来搞这个,真是难为你了,TComponent是非可视化组件,TWinControl是可视化组件,其实这是个小儿科的组件,同楼上从TCustomPanel继承即可,请找点关于基础的书看看,先把最基础的东西学到手,在论坛只能帮一下,帮不了什么。
 
多人接受答案了。
 
顶部