当前位置: 首页 > news >正文

lazarus实现拖放文件

lazarus编写的程序通过procedure FormDropFiles(Sender: TObject; const FileNames: array of string)可以实现拖放文件,以下是简单的demo,这个demo在linux也没问题。
unit Unit1;{$mode objfpc}{$H+}interfaceusesClasses, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;type{ TForm1 }TForm1 = class(TForm)Memo1: TMemo;procedure FormDropFiles(Sender: TObject; const FileNames: array of string);privatepublicend;varForm1: TForm1;implementation{$R *.lfm}{ TForm1 }procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
varSName: string;i: integer;
begin//MS WordPad, Notepad++ - they get focus on drag-drop from Explorer
  Application.BringToFront;for i:= 0 to Length(FileNames)-1 dobeginif Application.Terminated then exit;SName:= FileNames[i];    if FileExists(SName) thenMemo1.Lines.LoadFromFile(SName);Application.ProcessMessages;end;end;end.

image