type
TMyNotifyEvent=procedure (Sender:TObject;FileNames:TStringList) of object; private FDropFile:TMyNotifyEvent; //onDropFiles事件的指针
procedure DropFiles(var msg:TMessage);message WM_DROPFILES;
//将DropFiles函数接收的系统消息(WM_DROPFILES)转换成OnDropFile事件;
published
property OnDropFiles:TMyNotifyEvent read FDropFile write FDropFile;
procedure TDropFilesListBox.DropFiles(var msg: TMessage);
begin
.............具体实现代码............
end;
注释里面说 DropFiles函数接收到的系统消息自动转换成onDropFile 事件,是怎么转换的呢??? 我百思不得其解```
TMyNotifyEvent=procedure (Sender:TObject;FileNames:TStringList) of object; private FDropFile:TMyNotifyEvent; //onDropFiles事件的指针
procedure DropFiles(var msg:TMessage);message WM_DROPFILES;
//将DropFiles函数接收的系统消息(WM_DROPFILES)转换成OnDropFile事件;
published
property OnDropFiles:TMyNotifyEvent read FDropFile write FDropFile;
procedure TDropFilesListBox.DropFiles(var msg: TMessage);
begin
.............具体实现代码............
end;
注释里面说 DropFiles函数接收到的系统消息自动转换成onDropFile 事件,是怎么转换的呢??? 我百思不得其解```
var
FileNames:TStringList;
FileName:array[0..MAX_PATH-1] OF Char;
i,nCount:Integer;
begin
FileNames := TStringList.Create;
nCount := DragQueryFile(msg.WParam,$FFFFFFFF,@FileName,MAX_PATH);
//将所有文件添加到Filenames中
for i:=0 to nCount-1 do
begin
DragQueryFile(msg.WParam,i,FileName,MAX_PATH);
FileNames.Add(FileName);
end;
DragFinish(msg.WParam);
if Assigned(FDropFile) then
begin
FDropFile(Self,FileNames);
FileNames.Free;
end;
end;
这里是DropFiles 的代码
if Assigned(FDropFile) then // 如果FDropFile已经被赋值
begin
FDropFile(Self,FileNames); // 调用FDropFile
FileNames.Free; // 释放对象,这里有问题,应该把这句放在end之后,否则可能资源泄漏
end;