function GetNextLineData(var Ptr: PChar; var Size; Integer; var S: string): Boolean;<br><br> procedure IncPtr;<br> begin<br> Inc(Ptr);<br> Dec(Size);<br> end;<br><br>var<br> Src: PChar; <br>begin<br> // 忽略空行<br> while Ptr^ in [#13, #10] do IncPtr; <br> Result := Size > 0;<br> // 起始<br> Src := Ptr;<br> // 扫描到行尾<br> while not (Ptr^ in [#13, #10, #0]) do IncPtr;<br> // 长度 = 行尾-起始<br> SetString(S, Src, Ptr - Src);<br> Result := Ptr - Src > 0;<br> // 当前行的crlf字符,忽略掉<br> if Ptr^ = #13 then IncPtr;<br> if Ptr^ = #10 then IncPtr;<br>end;<br><br>var<br> SourceData, LineData: string;<br> SrcPtr: PChar;<br> SrcLen: Integer;<br>begin<br> SourceData := 'your long string data';<br> SrcPtr := PChar(SourceData);<br> SrcLen := Length(SourceData);<br> while GetNextLineData(SrcPtr, SrcLen, LineData) do<br> begin<br> // do your code...<br> end;<br>end;