一个例子
unit HyperLabel;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Shellapi, StdCtrls;type
THyperLabel = class(TLabel)
private
{ Private declarations }
FHoverFont: TFont;
FHoverColor: TColor;
FHoverCursor: TCursor;
FOldCursor: TCursor;
FOldFont: TFont;
FOldColor: TColor;
FOldScreenCursor: TCursor;
FOnMouseEnter: TNotifyEvent;
FonMouseLeave: TNotifyEvent;
FURL: string;
FHCursor: HCURSOR;
procedure FSetHoverFont(value: TFont);
procedure FSetHoverColor(value: TColor);
procedure FSetOnMouseLeave(value: TNotifyEvent);
procedure FSetOnMouseEnter(value: TNotifyEvent);
procedure FSetHoverCursor(value: TCursor);
procedure FSetURL(value: string);
protected
{ Protected declarations }
procedure cmmouseenter(var Msg: TMessage); message CM_MOUSEENTER;
procedure cmmouseleave(var msg: TMessage); message CM_MOUSELEAVE;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Click; override;
published
{ Published declarations }
property URL: string read FURL write FSetURL;
property HoverFont: TFont read FHoverFont write FSetHoverFont;
property HoverColor: TColor read FHoverColor write FSetHoverColor stored true default clBtnFace;
property HoverCursor: TCursor read FHoverCursor write FSetHoverCursor stored true default crHandPoint;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FSetOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FonMouseLeave write FSetOnMouseLeave;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('LZJ', [THyperLabel]);
end;{ THyperLabel }procedure THyperLabel.Click;
var
Temp: string;
begin
inherited;
Temp := Copy(FURL, 1, 5);
if UpperCase(Temp) = 'HTTP:' then
ShellExecute(Parent.Handle, 'open', 'explorer.exe', pchar(FURL), nil, SW_SHOW)
else
ShellExecute(Parent.Handle, 'open', pchar(FURL), nil, nil, SW_SHOW);
end;procedure THyperLabel.cmmouseenter(var Msg: TMessage);
begin
FOldFont.Assign(Font);
Font.Assign(FHoverFont); FOldColor := Color;
Color := FHoverColor; FOldCursor := Cursor;
FHCursor := LoadCursor(0, IDC_HAND);
FOldScreenCursor := Screen.Cursors[crHandPoint];
Screen.Cursors[crHandPoint] := FHCursor;
Cursor := crHandPoint; if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;procedure THyperLabel.cmmouseleave(var Msg: TMessage);
begin
Font.Assign(FOldFont);
Color := FOldColor;
DestroyCursor(FHCursor);
Screen.Cursors[crHandPoint] := FOldScreenCursor;
Cursor := FOldCursor;
if Assigned(FonMouseLeave) then
FOnMouseLeave(Self);
end;constructor THyperLabel.Create(AOwner: TComponent);
begin
inherited;
URL := 'mailto:[email protected]';
FHoverFont := TFont.Create;
FOldFont := TFont.Create;
FHoverFont.Assign(Font);
FHoverFont.Color := clBlue;
FHoverFont.Style := FHoverFont.Style + [fsUnderLine];
FHoverColor := clBtnFace;
FHoverCursor := crHandPoint;
end;destructor THyperLabel.Destroy;
begin
FHoverFont.Free;
FOldFont.Free;
inherited;
end;procedure THyperLabel.FSetHoverColor(value: TColor);
begin
if FHoverColor <> value then
FHoverColor := value;
end;procedure THyperLabel.FSetHoverCursor(value: TCursor);
begin
if value <> FHoverCursor then
FHoverCursor := value;
end;procedure THyperLabel.FSetHoverFont(value: TFont);
begin
FHoverFont.Assign(value);
end;procedure THyperLabel.FSetOnMouseEnter(value: TNotifyEvent);
begin
if @FOnMouseEnter <> @value then
FOnMouseEnter := Value;
end;procedure THyperLabel.FSetOnMouseLeave(value: TNotifyEvent);
begin
if @FonMouseLeave <> @value then
FonMouseLeave := value;
end;procedure THyperLabel.FSetURL(value: string);
begin
if Uppercase(value) <> Uppercase(FURL) then
FURL := value;
end;end.
unit HyperLabel;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Shellapi, StdCtrls;type
THyperLabel = class(TLabel)
private
{ Private declarations }
FHoverFont: TFont;
FHoverColor: TColor;
FHoverCursor: TCursor;
FOldCursor: TCursor;
FOldFont: TFont;
FOldColor: TColor;
FOldScreenCursor: TCursor;
FOnMouseEnter: TNotifyEvent;
FonMouseLeave: TNotifyEvent;
FURL: string;
FHCursor: HCURSOR;
procedure FSetHoverFont(value: TFont);
procedure FSetHoverColor(value: TColor);
procedure FSetOnMouseLeave(value: TNotifyEvent);
procedure FSetOnMouseEnter(value: TNotifyEvent);
procedure FSetHoverCursor(value: TCursor);
procedure FSetURL(value: string);
protected
{ Protected declarations }
procedure cmmouseenter(var Msg: TMessage); message CM_MOUSEENTER;
procedure cmmouseleave(var msg: TMessage); message CM_MOUSELEAVE;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Click; override;
published
{ Published declarations }
property URL: string read FURL write FSetURL;
property HoverFont: TFont read FHoverFont write FSetHoverFont;
property HoverColor: TColor read FHoverColor write FSetHoverColor stored true default clBtnFace;
property HoverCursor: TCursor read FHoverCursor write FSetHoverCursor stored true default crHandPoint;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FSetOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FonMouseLeave write FSetOnMouseLeave;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('LZJ', [THyperLabel]);
end;{ THyperLabel }procedure THyperLabel.Click;
var
Temp: string;
begin
inherited;
Temp := Copy(FURL, 1, 5);
if UpperCase(Temp) = 'HTTP:' then
ShellExecute(Parent.Handle, 'open', 'explorer.exe', pchar(FURL), nil, SW_SHOW)
else
ShellExecute(Parent.Handle, 'open', pchar(FURL), nil, nil, SW_SHOW);
end;procedure THyperLabel.cmmouseenter(var Msg: TMessage);
begin
FOldFont.Assign(Font);
Font.Assign(FHoverFont); FOldColor := Color;
Color := FHoverColor; FOldCursor := Cursor;
FHCursor := LoadCursor(0, IDC_HAND);
FOldScreenCursor := Screen.Cursors[crHandPoint];
Screen.Cursors[crHandPoint] := FHCursor;
Cursor := crHandPoint; if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;procedure THyperLabel.cmmouseleave(var Msg: TMessage);
begin
Font.Assign(FOldFont);
Color := FOldColor;
DestroyCursor(FHCursor);
Screen.Cursors[crHandPoint] := FOldScreenCursor;
Cursor := FOldCursor;
if Assigned(FonMouseLeave) then
FOnMouseLeave(Self);
end;constructor THyperLabel.Create(AOwner: TComponent);
begin
inherited;
URL := 'mailto:[email protected]';
FHoverFont := TFont.Create;
FOldFont := TFont.Create;
FHoverFont.Assign(Font);
FHoverFont.Color := clBlue;
FHoverFont.Style := FHoverFont.Style + [fsUnderLine];
FHoverColor := clBtnFace;
FHoverCursor := crHandPoint;
end;destructor THyperLabel.Destroy;
begin
FHoverFont.Free;
FOldFont.Free;
inherited;
end;procedure THyperLabel.FSetHoverColor(value: TColor);
begin
if FHoverColor <> value then
FHoverColor := value;
end;procedure THyperLabel.FSetHoverCursor(value: TCursor);
begin
if value <> FHoverCursor then
FHoverCursor := value;
end;procedure THyperLabel.FSetHoverFont(value: TFont);
begin
FHoverFont.Assign(value);
end;procedure THyperLabel.FSetOnMouseEnter(value: TNotifyEvent);
begin
if @FOnMouseEnter <> @value then
FOnMouseEnter := Value;
end;procedure THyperLabel.FSetOnMouseLeave(value: TNotifyEvent);
begin
if @FonMouseLeave <> @value then
FonMouseLeave := value;
end;procedure THyperLabel.FSetURL(value: string);
begin
if Uppercase(value) <> Uppercase(FURL) then
FURL := value;
end;end.
解决方案 »
- 如何在Form创建时,Show之前就将窗体隐藏?
- 散分
- 如何让rave报表里的表格 只能预览,不能打印
- 哪位能否发份fastreport给我及中文使用说明给我,大分回赠..
- 我用了themeengine这个组件,TeDBEdit在显示文字的时候光标总在文字的一半停留,急待解决??
- 怎样写查询语句,将SQL里面的表table1导入到Access表tempTable里面。两表所有字段都相同。
- 关于窗体显示的问题
- 有谁知道gexpert for Delphi 7 的程序
- 请问哪里有Delphi 6.0中国版可以下载?
- 求托盘程序,控件!
- 有搞头吗?DLL+ADO的问题
- TImage的打印问题,非常着急啊!高分相送!!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
T1 = class
private
member1 : integer;
public
function func1 : Integer; virtual;
function func2 : Integer; virtual;
function func3 : Integer; virtual;
end;
T2 = class(T1)
private
member2 : integer;
public
function func1 : Integer; override;
function func2 : Integer; override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function T1.func1:integer;
begin
showmessage('T1.func1');
result:=0;
end;
function T1.func2:integer;
begin
showmessage('T1.func2');
result:=0;
end;
function T1.func3:integer;
begin
showmessage('T1.func3');
result:=0;
end;
function T2.func1:integer;
begin
showmessage('T2.func1');
result:=0;
end;
function T2.func2:integer;
begin
showmessage('T2.func2');
result:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var O : T1;
begin
O := T2.Create;
O.func1;
O.func3;
O.Free;
end;
end.
首先声明类型
type 类名= class(基础类类型)
类的成员;
声明类的实例
var 类的实例的名:类名;
对实例赋值
类的实例.类的成员:=值;
MyClass = class
a: mytype;
... //变量 function myfun1( ... ): mytype1;
...
//函数
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
protected
procedure DoSome; virtual; abstract;
public
{ Public declarations }
end; TMyForm1 = class(TForm1)
protected
procedure DoSome; override;
end; TMyForm2 = class(TForm1)
protected
procedure DoSome; override;
end;
procedure TMyForm1.DoSome;
begin
ShowMessage('TMyForm1');
end;
procedure TMyForm2.DoSome;
begin
ShowMessage('TMyForm2');
end;
看一看,有好处的
把private,public,protect,published,dynamic,virtual,abstract
property ,event....那些搞明白了,找几个API风装一个类,
应该就差不多会了:).