Selaa lähdekoodia

* Fix filewriter.WriteBytes

Michaël Van Canneyt 1 vuosi sitten
vanhempi
commit
56f8976c3d
1 muutettua tiedostoa jossa 8 lisäystä ja 9 poistoa
  1. 8 9
      packages/fcl-base/src/streamex.pp

+ 8 - 9
packages/fcl-base/src/streamex.pp

@@ -372,23 +372,22 @@ end;
 
 procedure TStreamWriter.WriteBytes(Bytes: TBytes);
 var
-  ByteLen,Count,WritePos,ToWrite: Integer;
+  BufLen,Count,ToWrite: Integer;
   P : PByte;
 begin
-  ByteLen:=Length(Bytes);
-  ToWrite:=ByteLen;
-  WritePos:=0;
+  BufLen:=Length(FBuffer);
+  ToWrite:=Length(Bytes);
   P:=PByte(Bytes);
   while ToWrite>0 do
     begin
     Count:=ToWrite;
-    if Count>ByteLen-WritePos then
-      Count:=ByteLen-WritePos;
-    Move(P^, FBuffer[FBufferIndex], Count);
-    Inc(WritePos,Count);
+    if Count>BufLen-FBufferIndex then
+      Count:=BufLen-FBufferIndex;
+    Move(P^,FBuffer[FBufferIndex],Count);
     Inc(P,Count);
     Dec(ToWrite,Count);
-    if FBufferIndex >= Length(FBuffer) then
+    Inc(FBufferIndex,Count);
+    if FBufferIndex>=BufLen  then
       Flush;
     end;
   if FAutoFlush then