summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/webtbs/tw10482.pp
blob: 790ac850e51cbeb33c5b3abb24101961ed36f919 (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
program fpctest4;
{$ifdef fpc}
{$mode delphi}
{$endif fpc}
uses
{$ifdef unix}
  cwstring,
{$endif}
  Classes,sysutils,variants,typinfo;

type
   TTestClass=class(TComponent)
   private
     fV1,fV2,fV3:variant;
     procedure SetV2(const v:variant);
   published
     property V1:Variant read fV1 write fV1;
     property V2:Variant read fV2 write SetV2;
     property V3:Variant read fV3 write fV3;
   end;
	
const
   {$ifdef fpc}
   ws:WideString=#$43f#$440#$438#$432#$435#$442', '#$43f#$440#$44B#$432#$456#$442#$430#$43d#$44c#$43d#$435' - pr'#$fc'fung spa'#$df' gut';
   {$else}
   ws:WideString='ÔË‚ÂÚ, Ô˚‚≥ڇ̸Ì - prufung spa'#$df' gut';
   {$endif}

procedure TTestClass.SetV2(const v:variant);
begin
  fV2:=v;
  writeln('Set V2');
end;

var tc:TTestClass;
    f:TStream;
    vv:variant;
    ff : TFileStream;
begin

   RegisterClasses([TTestClass]);


   tc:=TTestClass.Create(nil);
   tc.v1:=123.45;
   tc.v2:='Hello world';
   tc.v3:=ws;

   vv:=GetVariantProp(tc,'V2');
   if vv<>Null then
     begin
       if (vv<>'Hello world') then
         halt(1);
       writeln('got=',vv);
     end
   else
     halt(2);


   SetVariantProp(tc,'V1',333.333);

   vv:=GetVariantProp(tc,'V1');
   if vv<>Null then
     begin
       if (vv<>333.333) then
         halt(3);
       writeln('got=',vv);
     end
   else
     halt(4);

   f:=TMemoryStream.Create;
   f.WriteComponent(tc); // store it

   ff:=TFileStream.Create('tw19482.str',fmCreate);
   ff.WriteComponent(tc); // store it
   ff.Free;

   tc.Free; // kill it

   f.free;

   f:=TFileStream.Create('tw19482.str',fmOpenRead);

   tc:=TTestClass(f.ReadComponent(nil));

   writeln('v1=',tc.v1);
   writeln('v2=',tc.v2);
   writeln('v3=',tc.v3);
   if (tc.v1<>333.333) then
     halt(5);
   if (tc.v2<>'Hello world') then
     halt(6);
   if (tc.v3<>ws) then
     halt(7);

   f.Free;

   DeleteFile('tw19482.str')
end.