diff --git a/UEnhancedMemoryStream.pas b/UEnhancedMemoryStream.pas index 399ba9a..2237ddc 100644 --- a/UEnhancedMemoryStream.pas +++ b/UEnhancedMemoryStream.pas @@ -268,10 +268,14 @@ end; procedure TEnhancedMemoryStream.WriteStringFixed(AValue: string; ALength: Integer); var - i: Integer; + oldLength: Integer; begin - for i := Length(AValue) to ALength do - AValue := AValue + #0; + oldLength := Length(AValue); + if oldLength < ALength then + begin + SetLength(AValue, ALength); + FillChar((PChar(AValue) + oldLength)^, ALength - oldLength, 0); + end; Write(PChar(AValue)^, ALength); end;