由于刚刚接触DELPH ,看了下DELPHI 下深入WINDOWS编程,要交选修课的论文。想做个监视目录里面的程序。但是不能编译运行。一点都不懂DELPH。
unit FileSysThread;interfaceuses
Windows, SysUtils, Classes, comctrls;type
TFileSysNotifyThread = class(TThread)
private
ErrCode: Integer;
KillAddress: PInteger;
NotifyHandle: THandle;
WatchPath: String;
WatchMask: Integer;
procedure SignalFileNotification;
protected
procedure Execute; override;
public
constructor Create (const AWatchPath: String; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
destructor Destroy; override;
end;implementationuses Dialogs;constructor TFileSysNotifyThread.Create (const AWatchPath: String; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
begin
Inherited Create (True);
WatchPath := AWatchPath;
WatchMask := AWatchMask;
KillAddress := Addr (Myself);
Priority := tpLower;
FreeOnTerminate := True;
Suspended := False;
end;destructor TFileSysNotifyThread.Destroy;
begin
if NotifyHandle <> THandle (-1) then
FindCloseChangeNotification (NotifyHandle);
Inherited Destroy;
KillAddress^ := 0;
end;procedure TFileSysNotifyThread.Execute;
begin
NotifyHandle := FindFirstChangeNotification (PChar (WatchPath), False, WatchMask);
if NotifyHandle <> THandle (-1) then while not Terminated do begin
ErrCode := WaitForSingleObject (NotifyHandle, 250);
case ErrCode of
Wait_Timeout:
;
Wait_Object_0:
begin
Synchronize (SignalFileNotification);
FindNextChangeNotification (NotifyHandle);
end;
else ;
end;
end;
end;procedure TFileSysNotifyThread.SignalFileNotification;
begin
ShowMessage ('文件已改变!');
end;end.
往哪位高手帮忙改下,最好能生成一个.EXE文件。帮我传过来。[[email protected]][/email]
unit FileSysThread;interfaceuses
Windows, SysUtils, Classes, comctrls;type
TFileSysNotifyThread = class(TThread)
private
ErrCode: Integer;
KillAddress: PInteger;
NotifyHandle: THandle;
WatchPath: String;
WatchMask: Integer;
procedure SignalFileNotification;
protected
procedure Execute; override;
public
constructor Create (const AWatchPath: String; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
destructor Destroy; override;
end;implementationuses Dialogs;constructor TFileSysNotifyThread.Create (const AWatchPath: String; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
begin
Inherited Create (True);
WatchPath := AWatchPath;
WatchMask := AWatchMask;
KillAddress := Addr (Myself);
Priority := tpLower;
FreeOnTerminate := True;
Suspended := False;
end;destructor TFileSysNotifyThread.Destroy;
begin
if NotifyHandle <> THandle (-1) then
FindCloseChangeNotification (NotifyHandle);
Inherited Destroy;
KillAddress^ := 0;
end;procedure TFileSysNotifyThread.Execute;
begin
NotifyHandle := FindFirstChangeNotification (PChar (WatchPath), False, WatchMask);
if NotifyHandle <> THandle (-1) then while not Terminated do begin
ErrCode := WaitForSingleObject (NotifyHandle, 250);
case ErrCode of
Wait_Timeout:
;
Wait_Object_0:
begin
Synchronize (SignalFileNotification);
FindNextChangeNotification (NotifyHandle);
end;
else ;
end;
end;
end;procedure TFileSysNotifyThread.SignalFileNotification;
begin
ShowMessage ('文件已改变!');
end;end.
往哪位高手帮忙改下,最好能生成一个.EXE文件。帮我传过来。[[email protected]][/email]
解决方案 »
- 老题新问(成绩排名问题)
- 请问delphi7的dbexpress支持access吗?默认好像不行,怎么才能让他支持?
- 急救!!!!小问题,答对都有分,!!!
- 那位朋友能帮忙解释一下TFindDialog和TReplaceDialog这两个类是作什么用的?(在线)
- 请问数据库脚本,怎么通过写程序自动在SQLSEVER生成数据库
- ***急:如何将MIDAS程序扩展为两台机子???***
- TABLE来过滤产生了一些数据记录
- "record/key deleted"异常是什么原因
- ADoTable问题!!!!!
- 请问如何把WIN2000启动时的选择去掉。具体情况如下:
- 有人用delphi写过条码打印吗? 打印机是godex ez1100
- pagecontrol中关闭创建的tabsheet问题
如果报错XXX.dcu错误就把那个dcu删掉,估计因为是别人编译过的,所以会报错
Windows, SysUtils, Classes, comctrls;type
TFileSysNotifyThread = class(TThread)
private
ErrCode: Integer;
KillAddress: PInteger;
NotifyHandle: THandle;
WatchPath: String;
WatchMask: Integer;
procedure SignalFileNotification;
protected
procedure Execute; override;
public
constructor Create (const AWatchPath: String; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
destructor Destroy; override;
end;implementationuses Dialogs;constructor TFileSysNotifyThread.Create (const AWatchPath: String; AWatchMask: Integer; var Myself: TFileSysNotifyThread);
begin
Inherited Create (True);
WatchPath := AWatchPath;
WatchMask := AWatchMask;
KillAddress := Addr (Myself);
Priority := tpLower;
FreeOnTerminate := True;
Suspended := False;
end;destructor TFileSysNotifyThread.Destroy;
begin
if NotifyHandle <> THandle (-1) then
FindCloseChangeNotification (NotifyHandle);
Inherited Destroy;
KillAddress^ := 0;
end;procedure TFileSysNotifyThread.Execute;
begin
NotifyHandle := FindFirstChangeNotification (PChar (WatchPath), False, WatchMask);
if NotifyHandle <> THandle (-1) then while not Terminated do begin
ErrCode := WaitForSingleObject (NotifyHandle, 250);
case ErrCode of
Wait_Timeout:
;
Wait_Object_0:
begin
Synchronize (SignalFileNotification);
FindNextChangeNotification (NotifyHandle);
end;
else ;
end;
end;
end;procedure TFileSysNotifyThread.SignalFileNotification;
begin
ShowMessage ('文件已改变!');
end;end.
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, FileSysThread;type
TForm1 = class(TForm)
Button1: TButton;
Button3: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
MyThread1 : TFileSysNotifyThread;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click (Sender: TObject);
begin
if MyThread1 = Nil then
MyThread1 := TFileSysNotifyThread.Create (edit1.text, File_Notify_Change_File_Name or File_Notify_Change_Dir_Name, MyThread1)
else ShowMessage ('线程正在运行');
end;procedure TForm1.Button3Click (Sender: TObject);
begin
if MyThread1 <> nil then
MyThread1.Terminate
else ShowMessage ('线程未运行');
end;procedure TForm1.FormCreate(Sender: TObject);
beginend;procedure TForm1.FormDestroy (Sender: TObject);
begin
if MyThread1 <> Nil then
begin
MyThread1.Terminate;
MyThread1.WaitFor;
end;
end;end.
其内有一个简易DEMO