1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
{ %FILES=tw13015-utf8.bin }
program test;
{$ifdef FPC}
{$mode delphi}
{$endif}
{$ifdef windows}
{$apptype console}
{$endif}
uses
{$ifdef unix}
cwstring,
{$endif}
Classes,SysUtils,uw13015;
procedure writefile(const fn: string);
var
f:TStream;
tc:TTestClass;
begin
writeln('Write component with widestring property to stream');
tc:=TTestClass.Create(nil);
writeln('tc.Wstr=',tc.Wstr);
write('tc.DumpAndCheck()');
tc.DumpAndCheck;
f:=TFileStream.Create(fn,fmCreate);
try
f.WriteComponent(tc);
finally
f.Free;
end;
tc.free;
end;
procedure readfile(const fn: string);
var
f:TStream;
tc:TTestClass;
begin
writeln('Reading component with widestring property');
f:=TFileStream.Create(fn,fmOpenRead);
try
tc:=TTestClass(f.ReadComponent(nil));
if Assigned(tc) then
begin
writeln('tc.Wstr=',tc.Wstr);
write('tc.DumpAndCheck()');
tc.DumpAndCheck;
end;
finally
f.Free;
end;
tc.free;
end;
const utf8str : array[0..84] of char=(
'T','P','F','0',#010,'T','T','e','s','t','C','l','a','s','s',
#000,#004,'W','s','t','r',#020,'9',#000,#000,#000,#208,#191,#209,#128,
#208,#184,#208,#178,#208,#181,#209,#130,',',' ',#208,#191,#209,#128,#209,
#139,#208,#178,#209,#150,#209,#130,#208,#176,#208,#189,#209,#140,#208,#189,
#208,#181,' ','-',' ','p','r',#195,#188,'f','u','n','g',' ','s',
'p','a',#195,#159,' ','g','u','t',#000,#000);
var
f: file;
begin
RegisterClasses([TTestClass]);
WriteFile('test.bin');
ReadFile('test.bin');
DeleteFile('test.bin');
assign(f,'tw13015-utf8.bin');
rewrite(f,1);
blockwrite(f,utf8str,sizeof(utf8str));
close(f);
ReadFile('tw13015-utf8.bin');
DeleteFile('tw13015-utf8.bin');
end.
|