类的事件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyEvent = procedure of object; //不带参数的过程
TMyEventExt = procedure(AName: string) of object; //带参数的过程
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyBase = class
private
FName : string;
FAge : Integer;
FOnEvent: TMyEvent; //定义 TMyEvent 类型事件
FOnEventExt: TMyEventExt;
procedure SetAge(const AValue: Integer);
public
//创建类时进行相应的一些初始化工作
constructor Create;
procedure SetEvent1;
procedure SetEvent2;
procedure SetEventExt1(ATmp: string);
//Name属性 不可更改
property Name: string read FName write FName;
//Age属性 可以更改
......
1、先用Const 定义一个常量,例如 const WM_MyMessage=WM_USER+$200;
2、在要实现的unit中定义一个私有方法
procedure doMyMessage(var msg:TMessage);message WM_MyMessage;
3、实现这个私有方法
procedure TForm1.doMyMessage(var msg:TMessage);
begin
//
if msg.Msg= WM_MyMessage then
showmessage('好啊')
else
showmessage('不好');
end;
4、最重要 把这个消息广播出去 Form1.Perform(WM_MyMessage,0,0);
下面是实现的代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const WM_MyMessage=WM_USER+$200;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure doMyMessage(var msg:TMessage);message WM_MyMessage;
&nbs ......
设置字体的过程
Procedure TForm1.FontDlgApply(Sender:Tobject);
begin
Button1.Font:= FontDialog1.Font;
end;
该程序只有当用户按动About框的按钮或被About窗控制图标关闭窗口后,才会回到主窗体中,而不能与第一个窗体发生交互行为。这就是方法Show和ShowModal的主要不同之处
集合类型是一群相同类型元素的组合,这些类型必须是有限类型如整形、布尔型、字符型、枚举型和子界型。在检查一个值是否属于一个特定集合时,集合类型非常有用。下面的例程可以说明集合类型的用法:
type
Tvowels=set of Char;
var
Vowels:TVowels;
表达式Edit1.Text[1] in Vowels的结果是布尔型的,in是运算符,用来判断字母是否存在于集合中。
记录类型
记录是您的程序可以成组访问的一群数据的集合
type
TEmployee=record
Name : string[20];
YearHired:1990..2000;
Salsry: Double;
Position: string[20];
end;
使用with开域语句,其形式为
with 记录变量名 do 语句
在with语句中,引用记录变量名不再冠以记录变量名,以简化对记录中域的引用写法。
with PromotedEmployee do
begin
Name :='';
YearHired := 1993;
Salary := 2000.00
Position := 'editor ......
查找另外一个窗口的句柄: handle := FindWindow(nil,PChar('窗口的标题'));//查到窗体句柄
查找子窗体:childHandle := FindWindowEx(handle,0,'子窗体类','子窗体标题');
另外有个枚举子窗体的API,EnumChildWindows(主创体句柄,@回调函数,用户参数);
用这个函数需要自己写一个回调的函数,比如:
function EnumChildProc(ahWND:HWND; param:LPARAM):boolean; stdcall;
sendmessage(handle,message,wl,rl)
unit Unit1;
interface
uses Windows, Messages,Tlhelp32, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 & ......
技术交流,DH讲解. 这个工具是好早好早以前写的,我这个喜欢在家边看电影边写写代码或者看电子书,所以经常会将网页移到屏幕的左上角或者右上角,而且要置顶.所以就写了这样一个工具,这个工具主要是对句柄的操作,还有就是窗体样式以及几个API的例子,比较基础. 整个文件在 here(Can't Input Chinese:() 下面把代码贴出来,希望有什么不懂的,结合MSDN,OK? Var
Form2: TForm2;
H: Cardinal = 0;
Implementation
{$R *.dfm}
//------------------------------------------------------------------------------
// 取得鼠标所在处窗体的句柄
//------------------------------------------------------------------------------
Procedure TForm2.BtnGetHandleClick(Sender: TObject);
Var
Pt: TPoint;
Begin
If GetCursorPos(Pt) Then
H := WindowfromPoint(Pt)
Else
H := 0;
End;
//------------------------------------------------------------------------------
// 将窗体置顶
//------------------------------------------------------------------------------
Procedure TForm2.BtnTopMostClick(Sender: TObject);
Var
Rc: T ......
type
TTurboRecord = record
strict private
fNameValue : integer;
function GetName: string;
public
NamePrefix : string;
constructor Create(const initNameValue : integer) ;
property Name : string read GetName;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor TTurboRecord.Create(const initNameValue : integer) ;
begin
fNameValue := initNameValue;
NamePrefix := '"record constructor"';
end;
function TTurboRecord.GetName: string;
begin
Inc(fNameValue) ;
result := Format('%s %d',[NamePrefix, fNameValue]) ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
turboRecord : TTurboRecord;
anotherTurboRecord : TTurboRecord;
begin
//no Constructor needed - fNameValue = 0 by default
turboRecord.NamePrefix := 'turboRecord';
Memo1.Lines.Add(turboRecord.Name) ;
Memo1.Lines.Add(turboRecord.Name) ;
//constructor used
turboRecord := TTurboRecord.Create(2006) ;
Memo1.Lines.Add(turboRecord.Name) ;
M ......