花了一个上午学习控件,怎么属性全不出来:((100分)

  • 主题发起人 主题发起人 CoCo_
  • 开始时间 开始时间
C

CoCo_

Unregistered / Unconfirmed
GUEST, unregistred user!
控件可以安装,但是Size,Text属性全没有出来,为什么?
----------------
unit Coolabel;

interface

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

type
TCoolabel = class(TCustomControl)
private
FUplabel:Tlabel;
FDwlabel:Tlabel;
procedure SetLabelSize(const Size:integer);
procedure SetUpColor(const Color:TColor);
procedure SetDwColor(const Color:TColor);
procedure SetLabelText(const Text:string);
function GetLabelText:String;
//Procedure SetLabelCaption(const Value:string);
//function GetLabelCaption:string;
{ Private declarations }
protected

{ Protected declarations }
public
constructor Create(Aowner:TComponent);override;
{ Public declarations }
published
property Text:string read GetLabelText write SetLabelText;
property Size:integer write SetLabelSize;
property UpLabelColor:TColor write SetUpColor;
property DwLabelColor:TColor write SetDwColor;
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Study', [TCoolabel]);
end;

{ TCoolabel }

constructor TCoolabel.Create(Aowner: TComponent);
begin
inherited Create(Aowner);
width:=200;
height:=50;
FUplabel:=TLabel.Create(self);
FUplabel.parent:=Self;
Fuplabel.width:=55;
Fuplabel.Height:=15;
FUplabel.Font.color:=ClBlack;

FDwLabel:=TLabel.Create(self);
FDwLabel.parent:=Self;
FDwlabel.top:=FUplabel.top+1;
FDwlabel.left:=FUpLabel.Left+1;
FDwLabel.Width:=55;
FdwLabel.Height:=15;
FDwlabel.Font.color:=ClYellow;



end;

function TCoolabel.GetLabelText: String;
begin
result:=FUplabel.Caption ;
end;

procedure TCoolabel.SetDwColor(const Color: TColor);
begin
FDwLabel.Font.color:=Color;
end;

procedure TCoolabel.SetLabelSize(const Size: integer);
begin
FDwlabel.Font.Size:=Size;
FUplabel.Font.Size:=Size;
end;

procedure TCoolabel.SetLabelText(const Text: string);
begin
FUpLabel.Caption :=Text;
FDwLabel.Caption :=Text;
end;

procedure TCoolabel.SetUpColor(const Color: TColor);
begin
FUpLabel.Font.color:=Color;
end;

end.
 
你的属性必须read 和write方法都声明才能显示出来呀
 
我不是都声明了么?
 
你的声明
property Text:string read GetLabelText write SetLabelText;
property Size:integer write SetLabelSize;//只声明了write,没声明read
property UpLabelColor:TColor write SetUpColor;//只声明了write,没声明read
property DwLabelColor:TColor write SetDwColor;//只声明了write,没声明read

 
在 过程后 加上 override 试试
 
谢谢,我已经成功了:)
 
多人接受答案了。
 
后退
顶部