请教:在DELPHI7下如何用IDHTTP实现文件的上传?急急急!(100分)

  • 主题发起人 主题发起人 wxf_wxf
  • 开始时间 开始时间
W

wxf_wxf

Unregistered / Unconfirmed
GUEST, unregistred user!
用IDHTTP。POST方法时报HTTP/1.1 404错误!
 
有哪位高人用过的,指教一下沙!
 
大家发一下言沙!
 
没有人用过吗?
 
那个就不是在ONREAD和ONWRITE读写数据了。<br><br>在ServerSocket1GetThread时,自己来创建线程与client通信的。<br><br>如以下示例(转)<br>-------------------------<br>TCP/IP 多线程传文件<br>---------------------<br><br>//===========================================================<br>//服务器端<br><br>unit svSocketThread;<br><br>interface<br><br>uses<br> &nbsp; SysUtils, Classes, ComCtrls, ScktComp, ExtCtrls, StdCtrls;<br><br>type<br> &nbsp;TServerThread=class(TServerClientThread)<br> &nbsp;private<br> &nbsp; &nbsp;WriteSize: integer; //发送数据缓冲区大小,以字节为单位<br> &nbsp; &nbsp;FilesName: string; &nbsp;//文件名<br> &nbsp; &nbsp;FilesStrm : TFileStream; //文件流<br> &nbsp; &nbsp;FilesLength: integer; //文件大小<br> &nbsp; &nbsp;FileCurrLength: integer; //当前传送多少个字节<br> &nbsp; &nbsp;ListItem: TListItem;<br> &nbsp; &nbsp;ErrorRaise : Boolean;<br> &nbsp; &nbsp;procedure ThreadCountDec;<br> &nbsp; &nbsp;procedure ListItemAdd;<br> &nbsp; &nbsp;procedure ListItemEnd;<br> &nbsp; &nbsp;procedure ListItemErr;<br> &nbsp;protected<br> &nbsp; &nbsp;procedure ClientExecute; override;<br> &nbsp;public<br> &nbsp; constructor Create(CreateSuspended: Boolean;<br> &nbsp; &nbsp; &nbsp;ASocket: TServerClientWinSocket; AFileName: string;<br> &nbsp; &nbsp; &nbsp;AWriteSize: integer); overload;<br> &nbsp; destructor &nbsp;Destroy; override; <br> &nbsp;end;<br><br><br><br>implementation<br>uses svMain,utCommon;<br><br><br>//==============================================================================<br><br>{=== ServerThread ===}<br><br>constructor TServerThread.Create(CreateSuspended: Boolean; ASocket: TServerClientWinSocket;<br> &nbsp; &nbsp; &nbsp;AFileName: string; AWriteSize: Integer);<br>begin<br> &nbsp;inherited Create(CreateSuspended, ASocket);<br><br> &nbsp;FilesName := AFileName; //传送的文件名<br> &nbsp;WriteSize := AWriteSize*1024;<br> &nbsp;FilesLength:=0;<br> &nbsp;FileCurrLength := 0;<br><br> &nbsp;FilesStrm := TFileStream.Create(FilesName, fmOpenRead or fmShareDenyNone);<br> &nbsp;FilesLength:= FilesStrm.Size;<br><br> &nbsp;ErrorRaise := False;<br>end;<br><br>destructor TServerThread.Destroy;<br>begin<br> &nbsp;FreeAndNil(FilesStrm);<br> &nbsp;FilesName:='';<br> &nbsp;if ErrorRaise then<br> &nbsp; &nbsp;Synchronize(ListItemErr)<br> &nbsp;else<br> &nbsp; &nbsp;Synchronize(ListItemEnd);<br> &nbsp;Synchronize(ThreadCountDec);<br> &nbsp;<br> &nbsp;inherited;<br>end;<br><br><br>procedure TServerThread.ClientExecute;<br>const<br> &nbsp;ReadLen = 1024;<br>var<br> &nbsp;pStream: TWinSocketStream;<br> &nbsp;Buffer: Pointer;<br> &nbsp;ReadText, SendText: String;<br>begin<br> &nbsp;//创建连接流对像,与客户通信<br> &nbsp;pStream := TWinSocketStream.Create(ClientSocket, 60000);<br><br> &nbsp;try &nbsp; &nbsp;//try 1<br> &nbsp; &nbsp;//--------------------------------------------------------------------------<br> &nbsp; &nbsp;while (not Terminated) and ClientSocket.Connected do begin<br> &nbsp; &nbsp; &nbsp;try &nbsp;//try 2<br> &nbsp; &nbsp; &nbsp; &nbsp;//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> &nbsp; &nbsp; &nbsp; &nbsp;//分配读数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;Buffer := AllocMem(ReadLen);<br><br> &nbsp; &nbsp; &nbsp; &nbsp;if pStream.WaitForData(6000) then begin //if 1<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pStream.Read(Buffer^, ReadLen);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReadText := PChar(Buffer);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FreeMem(Buffer);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ReadText = KEY_Clt[1] then begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//客户请求文件名<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //在ListView上增加用户信息<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Synchronize(ListItemAdd);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //返回待下载地文件名<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendText := KEY_Srv[1]+ FilesNameSepStr+ ExtractFileName(FilesName);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pStream.Write(SendText[1], Length(SendText)+1);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if ReadText = KEY_Clt[2] &nbsp;then begin &nbsp; &nbsp; &nbsp; &nbsp;//客户请求文件长度<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //返回对应文件大小<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendText := KEY_Srv[2]+ FilesLengthSepStr+ IntToStr(FilesStrm.Size);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pStream.Write(SendText[1], Length(SendText)+1);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if ReadText = KEY_Clt[3] then begin &nbsp; &nbsp; &nbsp; &nbsp; //请求开始发送文件<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Buffer := AllocMem(WriteSize);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Inc(FileCurrLength, pStream.Write(Buffer^, FilesStrm.Read(Buffer^, WriteSize)));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FreeMem(Buffer);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if ReadText = KEY_Clt[4] then begin &nbsp; &nbsp; &nbsp; &nbsp; //下载文件完毕通知<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//结束线程<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Terminate;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end; //end if 1<br> &nbsp; &nbsp; &nbsp; &nbsp;//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> &nbsp; &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp; &nbsp;ErrorRaise := True;<br> &nbsp; &nbsp; &nbsp; &nbsp;Terminate;<br> &nbsp; &nbsp; &nbsp;end; //end try 2<br><br> &nbsp; &nbsp;end; &nbsp;//end while<br> &nbsp; &nbsp;//--------------------------------------------------------------------------<br> &nbsp;finally<br> &nbsp; &nbsp;ClientSocket.Close;<br> &nbsp; &nbsp;pStream.Free;<br> &nbsp;end; //end try 1<br>end;<br><br>procedure TServerThread.ListItemAdd;<br>begin<br> &nbsp;ListItem := frmMainServer.LView_UserInfo.Items.Add;<br> &nbsp;ListItem.Caption := DateTimeToStr(Now);<br> &nbsp;with ListItem.SubItems do begin<br> &nbsp; &nbsp;Add(ClientSocket.RemoteHost);<br> &nbsp; &nbsp;Add(ClientSocket.RemoteAddress);<br> &nbsp; &nbsp;Add(IntToStr(ClientSocket.RemotePort));<br> &nbsp; &nbsp;Add(FilesName);<br> &nbsp; &nbsp;Add('传送文件');<br> &nbsp; &nbsp;end;<br>end;<br><br>procedure TServerThread.ListItemEnd;<br>begin<br> &nbsp;if ListItem &lt;&gt; nil then with ListItem.SubItems do<br> &nbsp; &nbsp;Strings[Count-1] := '传送完毕';<br>end;<br><br>procedure TServerThread.ListItemErr;<br>begin &nbsp; &nbsp;<br> &nbsp;if ListItem &lt;&gt; nil then with ListItem.SubItems do<br> &nbsp; &nbsp;Strings[Count-1] := '传送错误';<br>end;<br><br><br>procedure TServerThread.ThreadCountDec;<br>begin<br> &nbsp;with frmMainServer do<br> &nbsp;begin <br> &nbsp; &nbsp;//线程计数减一<br> &nbsp; &nbsp;Dec(FActiveThreadCount);<br> &nbsp; &nbsp;SBar1.Panels.Items[0].Text := '当前线程数:' + IntToStr(FActiveThreadCount);<br> &nbsp;end;<br>end;<br><br>end.<br>//-----------------------------------------------------<br>procedure TfrmMainServer.ServerSocket2GetThread(Sender: TObject;<br> &nbsp;ClientSocket: TServerClientWinSocket;<br> &nbsp;var SocketThread: TServerClientThread);<br>begin<br> &nbsp;SocketThread := TServerThread.Create(True,ClientSocket, FFileName, FBuffSize);<br> &nbsp;SocketThread.FreeOnTerminate := True;<br> &nbsp;SocketThread.Resume;<br> &nbsp;Inc(FActiveThreadCount);<br> &nbsp;SBar1.Panels.Items[0].Text := '当前线程数:' + IntToStr(FActiveThreadCount);<br>end;<br><br><br>//=========================================================================================<br><br>//客户端<br><br>unit ctClientThread;<br><br>interface<br><br>uses<br> &nbsp; SysUtils, Classes, ComCtrls, ScktComp, ExtCtrls, StdCtrls;<br><br>type<br> &nbsp;TClientThread = class(TThread)<br> &nbsp;private<br> &nbsp; &nbsp;CltSocket: TClientSocket;<br> &nbsp; &nbsp;FilesName: string;<br> &nbsp; &nbsp;FilesStrm: TFileStream;<br> &nbsp; &nbsp;FilesLength: Integer;<br> &nbsp; &nbsp;FileCurrLength, CurrReadSize: Integer; //以字节为单位<br> &nbsp; &nbsp;ReadLen: integer; &nbsp;//每次读取数据的缓冲区大小<br> &nbsp; &nbsp;ParentDir: String;<br> &nbsp; &nbsp;procedure Init(LengthText: String);<br> &nbsp; &nbsp;procedure StepProgressToEnd;<br> &nbsp; &nbsp;procedure StepProgress;<br> &nbsp;protected<br> &nbsp; &nbsp;procedure Execute; override;<br> &nbsp;public<br> &nbsp; &nbsp;constructor Create(CreateSuspended: Boolean; ClientSocket: TClientSocket; AParentDir: String);overload;<br> &nbsp; &nbsp;destructor Destroy; override;<br> &nbsp;end;<br><br>implementation<br>uses utCommon,ctMain;<br><br>//==============================================================================<br><br>{=== TClientThread ===}<br><br>constructor TClientThread.Create(CreateSuspended: Boolean; ClientSocket: TClientSocket; AParentDir: String);<br>begin<br> &nbsp;ParentDir := AParentDir;<br> &nbsp;inherited Create(CreateSuspended);<br> &nbsp;CltSocket := ClientSocket;<br> &nbsp;ReadLen &nbsp; :=4*1024;<br>end;<br><br>destructor TClientThread.Destroy;<br>begin<br> &nbsp;CltSocket.Close;<br> &nbsp;FreeAndNil(FilesStrm);<br> &nbsp;FilesName:='';<br> &nbsp;inherited;<br>end;<br><br>procedure TClientThread.Execute;<br>var<br> &nbsp;pStream: TWinSocketStream;<br> &nbsp;ReadBuffer: Pointer;<br> &nbsp;ReadText, TaskName, SendText: String;<br> &nbsp;Start, FileReading: Boolean;<br>begin &nbsp; &nbsp;<br> &nbsp;Start := False;<br> &nbsp;FileReading := False;<br><br> &nbsp;pStream := TWinSocketStream.Create(CltSocket.Socket, 60000);<br> &nbsp;try<br> &nbsp; &nbsp;//--------------------------------------------------------------------------<br> &nbsp; &nbsp;while (not Terminated) and CltSocket.Active do begin<br> &nbsp; &nbsp; &nbsp;if not Start then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; SendText := KEY_Clt[1];<br> &nbsp; &nbsp; &nbsp; &nbsp; pStream.Write(SendText[1], Length(SendText));<br> &nbsp; &nbsp; &nbsp; &nbsp; Start := True;<br> &nbsp; &nbsp; &nbsp; &nbsp; end;<br><br> &nbsp; &nbsp; &nbsp;ReadBuffer := AllocMem(ReadLen);<br><br> &nbsp; &nbsp; &nbsp;if pStream.WaitForData(6000) then begin //if 1<br> &nbsp; &nbsp; &nbsp; &nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> &nbsp; &nbsp; &nbsp; &nbsp; CurrReadSize := pStream.Read(ReadBuffer^, ReadLen);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; if FileReading then begin &nbsp; //if 2<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//**************************<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Inc(FileCurrLength, FilesStrm.Write(ReadBuffer^, CurrReadSize));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Synchronize(StepProgress);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FileCurrLength &gt;= FilesLength then &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendText := KEY_Clt[4];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pStream.Write(SendText[1], Length(SendText));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Synchronize(StepProgressToEnd);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileCurrLength := 0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Terminate;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendText := KEY_Clt[3];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pStream.Write(SendText[1], Length(SendText));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp; &nbsp; //**************************<br> &nbsp; &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; &nbsp;else begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReadText := PChar(ReadBuffer);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TaskName := Copy(ReadText, 1, Length(KEY_Srv[1]));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if TaskName = KEY_Srv[1] then begin &nbsp;//文件名<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Delete(ReadText, 1, Length(KEY_Srv[1])+1);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FilesName := ReadText;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendText := KEY_Clt[2];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pStream.Write(SendText[1], Length(SendText));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if TaskName = KEY_Srv[2] then begin //文件长度<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Delete(ReadText, 1, Length(KEY_Srv[1])+1);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Init(ReadText);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendText := KEY_Clt[3];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pStream.Write(SendText[1], Length(SendText));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileReading := True;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br> &nbsp; &nbsp; &nbsp; &nbsp;end; &nbsp;//end if 2<br> &nbsp; &nbsp; &nbsp;//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> &nbsp; &nbsp; &nbsp;end; //end if 1<br><br> &nbsp; &nbsp; &nbsp;FreeMem(ReadBuffer);<br> &nbsp; &nbsp;end; //end while<br> &nbsp; &nbsp;//--------------------------------------------------------------------------<br> &nbsp;finally<br> &nbsp; &nbsp;pStream.Free;<br> &nbsp; &nbsp;CltSocket.Close;<br> &nbsp;end;<br>end;<br><br><br>procedure TClientThread.Init(LengthText: String);<br>begin<br> &nbsp;FileCurrLength := 0;<br> &nbsp;FilesName := ParentDir +'copy_'+FilesName;<br><br> &nbsp;if FileExists(FilesName) then<br> &nbsp; &nbsp; DeleteFile(FilesName);<br><br> &nbsp;FilesStrm := TFileStream.Create(FilesName, fmCreate);<br> &nbsp;FilesLength :=strtointdef(LengthText,0);<br><br> &nbsp;if FilesLength&lt;&gt;0 then begin<br> &nbsp; &nbsp; frmMainClient.PBar1.Max :=FilesLength div ReadLen;<br> &nbsp; &nbsp; if (FilesLength mod ReadLen)&lt;&gt;0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;frmMainClient.PBar1.Max:=frmMainClient.PBar1.Max+1;<br> &nbsp; &nbsp; end ;<br>end;<br><br>procedure TClientThread.StepProgress;<br>begin<br> &nbsp; frmMainClient.PBar1.Position:=frmMainClient.PBar1.Position +1; <br>end;<br><br>procedure TClientThread.StepProgressToEnd;<br>begin<br> &nbsp;frmMainClient.InitUI(2);<br>end; &nbsp; <br><br>end.<br>//-------------------------------------------------<br>procedure TfrmMainClient.btnDownClick(Sender: TObject);<br>begin<br> &nbsp;case TComponent(Sender).Tag of<br> &nbsp; &nbsp;0:<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;InitUI(1);<br> &nbsp; &nbsp; &nbsp;//创建读写线程<br> &nbsp; &nbsp; &nbsp;ClientThread := TClientThread.Create(True, ClientSocket2, ExtractFilePath(ParamStr(0)));<br> &nbsp; &nbsp; &nbsp;ClientThread.FreeOnTerminate := True;<br><br> &nbsp; &nbsp; &nbsp; //建立连接<br> &nbsp; &nbsp; &nbsp;ClientSocket2.Open;<br><br> &nbsp; &nbsp; &nbsp;//线程开始运行<br> &nbsp; &nbsp; &nbsp;ClientThread.Resume;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;1:<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;ClientThread.Terminate;<br> &nbsp; &nbsp; &nbsp;Close;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;2:<br> &nbsp; &nbsp; &nbsp;Close;<br> &nbsp;end;<br>end;<br><br>//=========================================================================<br><br>//公用文件<br><br>unit utCommon;<br><br>interface<br><br>uses<br> &nbsp;Classes,SysUtils;<br><br>const<br> &nbsp;Key_Clt: array[1..4] of string=<br> &nbsp; &nbsp;('AskForFilesName',<br> &nbsp; &nbsp; 'AskForFilesLength',<br> &nbsp; &nbsp; 'AskForFilesData',<br> &nbsp; &nbsp; 'WantToDiscount');<br><br> &nbsp;Key_Srv: array[1..2] of string=<br> &nbsp; &nbsp;('Return1',<br> &nbsp; &nbsp; 'Return2') ;<br><br> &nbsp;FilesNameSepStr='|';<br> &nbsp;FilesLengthSepStr=',';<br><br>type<br> &nbsp;TTestRec=record<br> &nbsp; &nbsp;No: string[8];<br> &nbsp; &nbsp;Name: string[16];<br> &nbsp;end;<br><br>function StringToStrings(SepStr: string; s: string): TStrings;<br>function StringsToString(SepStr: string; Strs: TStrings; GetFileName: Boolean=False): string;<br><br>implementation<br><br>//==============================================================================<br><br>function StringToStrings(SepStr: string; s: string): TStrings;<br>var P: integer;<br>begin<br> &nbsp;Result:=TStringList.Create ;<br> &nbsp;P:=Pos(SepStr,s);<br> &nbsp;while p&lt;&gt;0 do begin<br> &nbsp; &nbsp;Result.Add(Copy(s,1,p-1));<br> &nbsp; &nbsp;Delete(s,1,p-1+length(SepStr));<br> &nbsp; &nbsp;P:=Pos(SepStr,s);<br> &nbsp; &nbsp;end;<br> &nbsp;Result.Add(s);<br>end;<br><br>function StringsToString(SepStr: string; Strs: TStrings; GetFileName: Boolean=False): string;<br>var i: integer;<br>begin<br> &nbsp;Result:='';<br> &nbsp;for i:=0 to Strs.Count-1 do<br> &nbsp; if not GetFileName then<br> &nbsp; &nbsp; Result:=Result+SepStr+Strs<br> &nbsp; else<br> &nbsp; &nbsp; Result:=Result+SepStr+ExtractFileName(Strs);<br><br> &nbsp;Delete(Result,1,length(SepStr));<br>end;<br><br><br><br>end.<br>//-----------------------------------------------------------------------------------------------
 
后退
顶部