我初学,自己照书上写了个组件,可是在组件面板上没有显示!源码如下(100分)

  • 主题发起人 主题发起人 qingfei
  • 开始时间 开始时间
Q

qingfei

Unregistered / Unconfirmed
GUEST, unregistred user!
unit UnitClndar;

interface
uses
classes,SysUtils;

type
TClndar=Class(TComponent)
private
FDate:TDateTime;
FOnchange:TNotifyEvent;
function GetDateElement(Index:Integer):integer;
Function GetText:String;
procedure SetDateElement(index:integer;Value:integer);
procedure DoChange;
function DaysPerMonth(Y,M:integer):Integer;
function DaysThisMonth:integer;
Public
constructor Create(AOwner:TComponent);overload;override;
constructor Create(y,m,d:integer);reintroduce;overload;
Procedure SetValue(y,m,d:integer);overload;
Procedure SetValue(newdate:TDateTime);overload;
Function Leapyear(AYear:integer):Boolean;
Procedure Increase(NumberofDays:integer=1);
procedure Decrease(NumberofDays:Integer=1);
published
property Day:integer index 1 read GetDateElement write SetDateElement;
property Month:integer index 2 read GetDateElement write SetDateElement;
property Year:integer index 3 read GetDateElement write SetDateElement;
property Text:string read GetText;
property OnChange:TNotifyEvent read FOnChange write FonChange;
end;

procedure register;
implementation

constructor TClndar.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FDate:=Date;
end;

constructor TClndar.Create(y,m,d:integer);
begin
Fdate:=Encodedate(y,m,d);
end;

procedure Tclndar.SetValue(y,m,d:integer);
begin
fdate:=encodedate(y,m,d);
end;



procedure Tclndar.SetValue(newdate:tdatetime);
begin
fdate:=newdate;
end;

procedure Tclndar.Increase(numberofdays:integer);
begin
Fdate:=fdate+numberofdays;
DoChange;
end;

function Tclndar.leapyear(Ayear:integer):boolean;
begin
if(Ayear mod 4 <>0) then
leapyear:=false
else if(Ayear mod 100 <>0) then
leapyear:=true
else if(ayear mod 400 <>0) then
leapyear:=false
else
leapyear:=true;
end;

{属性text的读方法}
function Tclndar.GetText:string;
begin
gettext:=formatdatetime('dddddd',Fdate);
end;

procedure Tclndar.Decrease(numberofdays:integer);
begin
Fdate:=fdate-numberofdays;
Dochange;
end;

{属性year,month,day的写方法}
procedure Tclndar.SetDateElement(index:integer;value:integer);
var
y,m,d:word;
begin
if value>0 then
begin
decodedate(Fdate,y,m,d);
case index of
3:if y<>value then y:=value else exit;
2:if(value<=12)and(value<>m) then m:=value else exit;
1:if(value<=daysthismonth)and(value<>d) then D:=value else exit;
else exit;
end;
setvalue(y,m,d);
end;
end;


function Tclndar.GetDateElement(index:integer):integer;
var
y,m,d:word;
begin
decodedate(Fdate,y,m,d);
case index of
3:result:=y;
2:result:=m;
1:result:=d;
else
result:=-1
end;
end;


function Tclndar.DaysPerMonth(Y,M:Integer):integer;
const
daysinmonth:array[1..12]of integer=(31,28,31,30,31,30,31,31,30,31,30,31);
//该数组常数用来表示每个月的天数
begin
result:=daysinmonth[M];
if (M=2) and leapyear(Y) then inc(result);
end;

function Tclndar.DaysThisMonth:integer;
begin
result:=dayspermonth(Year,Month);//根据属性year和month的值返回该月的天数
end;

procedure register;
begin
RegisterComponents('samples',[TClndar]);
end;

procedure TClndar.DoChange;
begin
if assigned(FOnChange) then
FOnChange(Self);
end;

end.
 
先Compile,再Install,在“Samples”页上。试过了吗?
 
Component->install Component
Unit file name选择UnitClndar
Ok,compile
 
我是按照以上两位大虾的方法安装的(安装在dclusr.dpk这个包里了)
先是提示"Packge dclusr.bpl will be rebuilt,Continue?"
我点了"yes"按钮,然后再没有什么提示了.并且"Packge--dclusr.dpk"窗口下的
install按钮是灰的
我点了Compile也没什么反应
但是Packge--dclusr.dpk"窗口里已经包含UnitClndar.pas了

 
真的找不到我安装的组件了(还不知安装上去没有)
Samples页里没有
我在组件面板上点右键,看属性 也找不到我的组件
 
procedure Register; //注意Register的R要大写。
 
我倒!
真是这个原因
这也太……!
谢谢
 

Similar threads

I
回复
0
查看
693
import
I
I
回复
0
查看
771
import
I
I
回复
0
查看
831
import
I
I
回复
0
查看
475
import
I
后退
顶部