Delphi U盘插入拨出检测
Delphi U盘插入拨出检测:
1、新建工程;
2、在form1上放一个Label;
3、定义一个私有过程
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
完整代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMDeviceChange (var Msg: TMessage);
var
myMsg : String;
begin
Case Msg.WParam of
32768:
begin
myMsg :='U盘插入';
Label1.Caption:=myMsg
end;
32772:
begin
myMsg :='U盘拔出';
Label1.Caption:=myMsg;
end;
end;
end;
end.
相关文档:
Delphi 关键字详解[整理于 "橙子" 的帖子]
absolute
//它使得你能够创建一个新变量, 并且该变量的起始地址与另一个变量相同.
var
Str: string[32];
StrLen: Byte absolute Str;
//这个声明指定了变量StrLen起始地址与Str相同.
//由于字符串的第0个位置保存了字符串的长度, 所以StrLen的值即字符串长度.
begin ......
关于书签(BookMark)操作;
书签操作主要用于在表中快速地定位记录指针,在应用程序中常常要保存记录指针所在的位置,在进行其他处理之后,希望能快速地返回到先前指针所在的位置,此时,使用书签将显得特别有用。有关书签操作,Delphi提供了三个方法,它们是:
●&n ......
最近在调试代码,发现一个问题.应该算是bug吧. 呵,如果不算bug,那就是我对其实现原理的误解.
如果把返回参数Result作为另一函数的输入参数,result的初值是不确定...
function fun(str:string):string;
begin
fun2(result);
end; ......
procedure TForm1.Button2Click(Sender: TObject);
var
name:String ;
begin
name := edit2.Text ;
name := '%' + name ;
query1.Close ;
query1.SQL.Clear ;
query1.SQL.Add('select * from gjh_t where name like '''+name+'''') ;
&nb ......