V
visual_cjiajia
Unregistered / Unconfirmed
GUEST, unregistred user!
拖放文件<br>以下代码只能保存一个拖动文件到<br>MEMO1控件,如何同时保存多个文件?<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls,Types,ShlObj,ShellApi;<br><br>type<br> Tfrmdropfile = class(TForm)<br> Memo1: TMemo;<br> Edit1: TEdit;<br> Memo2: TMemo;<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> procedure DropFile(var Msg :TWMDropFiles );message WM_DROPFILES;<br> end;<br><br>var<br> frmdropfile: Tfrmdropfile;<br><br>implementation<br><br>{$R *.dfm}<br>procedure Tfrmdropfile.DropFile(var Msg :TWMDropFiles );<br>var<br> FileName,<br> Extension:string;<br> AcceptStr:TStringList;<br> i,j,DropCount:Integer;<br>begin<br>SetLength(FileName,256);<br><br>AcceptStr:= TStringList.Create ;<br> Memo1.Clear() ;<br> Memo2.Clear() ;<br>DropCount:=DragQueryFile(HDROP(Msg.Drop),$FFFFFFFF,nil,0 );<br>for i:=0 to DropCount-1 do<br>begin file://1<br> DragQueryFile(HDROP(Msg.Drop),0,PChar(FileName),Length(FileName) );<br> Memo2.Lines.Add(FileName);<br> Extension:=ExtractFileExt(FileName);<br> Extension:=UpperCase(Extension) ;<br> SetLength(Extension,4);<br> if(Extension='.TXT') then<br> begin//2<br> AcceptStr.LoadFromFile(FileName);<br> for j:=0 to AcceptStr.Count-1 do<br> begin//3<br> Memo1.Lines.Add(AcceptStr.Strings[j]);<br> end;//3<br> end;//2<br>end;//1<br> Edit1.Text :=IntToStr(DropCount);<br> DragFinish(HDROP(Msg.Drop));<br>end;<br>procedure Tfrmdropfile.FormCreate(Sender: TObject);<br>begin<br>DragAcceptFiles(frmdropfile.Handle ,true);<br>end;<br><br>end.<br><br>