Skip to content

Commit f0667d4

Browse files
committed
Larger string support fix
1 parent cbea5bb commit f0667d4

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

libsrc/ActiveXServer/uMain.pas

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface
88

99
const
1010
MAX_EVENT_COUNT = 1000;
11+
BLOCK_SIZE = 255;
1112
dolog = false;
1213

1314
type
@@ -135,7 +136,11 @@ TPipeThread = class(TThread)
135136

136137
end;
137138

138-
TBuf = array of byte;
139+
140+
141+
TBuf = array[0..BLOCK_SIZE-1] of byte;
142+
143+
139144

140145
var
141146
frmMain: TfrmMain;
@@ -217,24 +222,34 @@ function TPipeThread.ReadString():WideString;
217222
var buf:TBuf;
218223
var len:integer;
219224
var us:UTF8String;
225+
var pos:integer;
226+
blklen:integer;
220227
begin
221228
len := ReadUI32();
222229
if len = 0 then
223230
begin
224231
Result:='';
225232
exit;
226233
end;
227-
SetLength(buf,len);
228-
ReadPipe(pipe,buf,len);
234+
pos := 0;
229235
SetLength(us,len);
230-
CopyMemory(@us[1], @buf[0], len);
236+
237+
while pos < len do
238+
begin
239+
if pos + BLOCK_SIZE <= len then
240+
blklen := BLOCK_SIZE
241+
else
242+
blklen := len - pos;
243+
ReadPipe(pipe,buf,blklen);
244+
CopyMemory(@us[1+pos], @buf[0], blklen);
245+
pos := pos + blklen;
246+
end;
231247
Result:=UTF8Decode(us);
232248
end;
233249

234250
function TPipeThread.ReadUI8():byte;
235251
var buf:TBuf;
236252
begin
237-
SetLength(buf,1);
238253
ReadPipe(self.pipe,buf,1);
239254
Result:=buf[0];
240255
end;
@@ -268,7 +283,6 @@ function TPipeThread.ReadValue(var ref:Boolean;var baseguid:TGUID;var guid:TGUID
268283
function TPipeThread.ReadUI16():word;
269284
var buf:TBuf;
270285
begin
271-
SetLength(buf,2);
272286
ReadPipe(self.pipe,buf,2);
273287
Result:=(buf[0] shl 8) + buf[1];
274288
end;
@@ -281,7 +295,6 @@ function TPipeThread.ReadSI16(): SmallInt;
281295
function TPipeThread.ReadUI32():cardinal;
282296
var buf:TBuf;
283297
begin
284-
SetLength(buf,4);
285298
ReadPipe(pipe,buf,4);
286299
Result:=(buf[0] shl 24)+(buf[1] shl 16)+(buf[2] shl 8) + buf[3];
287300
end;
@@ -301,15 +314,13 @@ function TPipeThread.ReadSI64():Int64;
301314
procedure TPipeThread.WriteUI8(val:byte);
302315
var buf:TBuf;
303316
begin
304-
SetLength(buf,1);
305317
buf[0] := val;
306318
WritePipe(self.pipe,buf,1);
307319
end;
308320

309321
procedure TPipeThread.WriteUI16(val:word);
310322
var buf:TBuf;
311323
begin
312-
SetLength(buf,2);
313324
buf[0] := (val shr 8) mod 256;
314325
buf[1] := val mod 256;
315326
WritePipe(self.pipe,buf,2);
@@ -318,7 +329,6 @@ procedure TPipeThread.WriteUI16(val:word);
318329
procedure TPipeThread.WriteUI32(val:cardinal);
319330
var buf:TBuf;
320331
begin
321-
SetLength(buf,4);
322332
buf[0] := (val shr 24) mod 256;
323333
buf[1] := (val shr 16) mod 256;
324334
buf[2] := (val shr 8) mod 256;
@@ -331,14 +341,23 @@ procedure TPipeThread.WriteString(val: widestring);
331341
var a:TBuf;
332342
len:integer;
333343
s: UTF8String;
334-
i:integer;
344+
blklen : integer;
345+
pos :integer;
335346
begin
336347
s := UTF8Encode(val);
337348
len := Length(s);
338349
WriteUI32(len);
339-
SetLength(a,len);
340-
CopyMemory(@a[0], @s[1], len);
341-
WritePipe(self.pipe,a,len);
350+
pos := 0;
351+
while pos < len do
352+
begin
353+
if pos + BLOCK_SIZE <= len then
354+
blklen := BLOCK_SIZE
355+
else
356+
blklen := len - pos;
357+
CopyMemory(@a[0], @s[1+pos], blklen);
358+
WritePipe(self.pipe,a,blklen);
359+
pos := pos + blklen;
360+
end;
342361
end;
343362

344363
procedure TPipeThread.WriteStrings(val: TStrings);

0 commit comments

Comments
 (0)