秋·风

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

lazarus实现拖放文件

lazarus编写的程序通过procedure FormDropFiles(Sender: TObject; const FileNames: array of string)可以实现拖放文件,以下是简单的demo,这个demo在linux也没问题。
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string
  );
var
  SName: string;
  i: integer;
begin
  //MS WordPad, Notepad++ - they get focus on drag-drop from Explorer
  Application.BringToFront;

  for i:= 0 to Length(FileNames)-1 do
  begin
    if Application.Terminated then exit;
    SName:= FileNames[i];

    if FileExists(SName) then
      Memo1.Lines.LoadFromFile(SName);
    Application.ProcessMessages;
  end;

end;

end.

image

 

posted on 2026-02-10 15:31  秋·风  阅读(134)  评论(0)    收藏  举报