怎样在关闭窗口之前加入确认对话框
1.在Form的OnCloseQuery 事件里加入以下代码:
if Application.MessageBox('Close it now?','Ask',MB_YESNO )=IDYES then
CanClose:=True
else
CanClose:=False;
怎样在运行时刻动态生成控件[可视的和不可视的]
㈠、可视控件:[以下以 TEdit 控件为例]
1.在Form的Public 中定义TEdit控件
Edit1:TEdit;
2.在需要生成的地方加入以下代码:
Edit1:=TEdit.Create(Self);
Edit1.Parent:=Form1; ?// Set parent to paint the Edit1
Edit1.Left ?:=20; ?// Set postion
Edit1.Top :=20;
Edit1.Text :='Edit1 Text'; // Set values
.... ? // Set other property
3.使用完毕后,释放分配的资源
if? Assigned(Edit1) then
Edit1.Free; ?
㈡、非可视控件:[以下以 TTimer 控件为例]
1.在Form的Public 中定义TTimert控件
Timer1:TTimber;
2.在需要生成的地方加入以下代码:
Timer1:=TTimer.Create(Self);
Timer1.OnTimer:=YourAction; //定义自己的OnTimer事件
//procedure TForm1.YourAction(Sender:TObject);
//是已经定义的响应过程
3.使用完毕后,释放分配的资源
if? Assigned(Timer1) then
Timer1.Free; ?
如何获得命令行参数?
有关 Delphi 传入应用程式的命令列参数, 请参考以下的说明??
1. 取得命令列参数的个数: ParamCount 函数
2. 呼叫 ParamStr(0), 传回执行档的档名(含路径)
3. 呼叫 ParamStr(n), 传回第n个参数的内容
例子:
procedure TForm1.FormCreate(Sender: TObject);
var
ix: integer;
begin
Memo1.Lines.Clear;
if ParamCount = 0 then
Memo1.Lines.Add('??统??.')
else
begin
Memo1.Lines.Add('档名:' + ParamStr(0));
for ix := 1 to ParamCount do
Memo1.Lines.Add(ParamStr(ix));
end;
end;
查阅所有可视窗口标题
下面只是举出一个例子提供参考:
运用API函数 GetWindow() 配合 GetWindowText() 逐一查出各视窗的标题
1. File | New Project 开始一个新的工程
2. 在 Form1 中安排 Button 与 Memo 各一
3. 在 Button1 的 OnClick 事件中撰写程式如下:
procedure TForm1.Button1Click(Sender: TObject);
var
hCurrentWindow: HWnd;
szText: array[0..254] of char;
begin
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
if GetWindowText(hCurrentWindow, @szText, 255) > 0 then
Memo1.Lines.Add(StrPas(@szText));
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
end;
在程序中使用自定义的鼠标
自订鼠标的部分, 在 OnLine Help 中的说明?没有提到一些细节
以下的例子请您参考看看:
一. 建立工程与一个资源
档
1. File | New Project
2. File | Save Project, 将 unit1 与 project1 存起来
假定是 c:\temp 目录
3. Tools | Image Editor, 利用 Image Editor 新开一个
资源档( Fild | New | Resource File
)
4. 在这个资源档中新建一个 CURSOR_1 的 CURSOR, 设定
好它的 Hot Spot( Image | Hot Spot )
5. 将资源档存起来, 存档时注意要和上述的 Project 存在
同一个目录,且不要与 project 的原资源档档名重覆,
在本例我们先假定为 MyCursor.res
二. 程序部分
6. 定义一个常数, 这个常数您必须设成大於零的任何整数
7. 以 LoadCursor() 函数将自订的鼠标资源 load 进来
以下为源代码
// unit.pas
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics, Controls, Forms, Dialogs;
const
crMyCursor = 1; (* 宣告一个常数 *)
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
{$R mycursor.res} // 这行 $R 不可少, 否则自订的鼠游标就出不来了
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
//将鼠标资源 load 进来
Screen.Cursors[crMyCursor] := LoadCur