1{%target=java android} 2program tthreadvar; 3 4{$mode delphi} 5{$modeswitch unicodestrings} 6 7uses 8 {$ifdef java}jdk15{$else}androidr14{$endif}; 9 10type 11 tc = class 12 end; 13 14 tmythread = class(JLThread) 15 procedure run; override; 16 end; 17 18 19type 20 tthreadvarkind = (fboolean,fbyte,fsmallint,fcardinal,fint64,fchar,fwidechar,fsingle,fdouble,fsetint,fsetenum,frec,fshortstring,funicodestring,farrbyte,farrset); 21 22 tsetint = set of 30..40; 23 tsetenum = set of tthreadvarkind; 24 tarrbyte = array[4..6] of byte; 25 tarrset = array[1..2] of tsetint; 26 trec = record 27 a: longint; 28 b: array[3..4] of ansistring; 29 end; 30 31 32const 33 cenumin: tthreadvarkind = fcardinal; 34 cbooleanin: boolean = true; 35 cbytein: byte = 35; 36 csmallintin: smallint = 1234; 37 ccardinalin: cardinal = $1234567; 38 cint64in: int64 = $deadcafebabe; 39 ccharin: ansichar = 'S'; 40 cwidecharin: widechar = 'U'; 41 csinglein: single = 1234.5; 42 cdoublein: double = 1239643.75; 43 csetintin: tsetint = [36..39]; 44 csetenumin: tsetenum = [fsmallint,fint64,funicodestring]; 45 crecin: trec = (a:98765; b:('abc','def')); 46 cshortstringin: shortstring = 'greaT'; 47 cunicodestringin: unicodestring = 'a bit longer!'; 48 carrbytein: tarrbyte = (4,2,5); 49 carrsetin: tarrset = ([31,33,37],[]); 50 51 cenumout: tthreadvarkind = farrbyte; 52 cbooleanout: boolean = false; 53 cbyteout: byte = 128; 54 csmallintout: smallint = 4321; 55 ccardinalout: cardinal = $7654321; 56 cint64out: int64 = $B4B3154713; 57 ccharout: ansichar = 's'; 58 cwidecharout: widechar = 'u'; 59 csingleout: single = 4321.5; 60 cdoubleout: double = 9876543.75; 61 csetintout: tsetint = [31..36]; 62 csetenumout: tsetenum = [fbyte]; 63 crecout: trec = (a:4365246; b:('cbax','iiiiii')); 64 cshortstringout: shortstring = 'tiny'; 65 cunicodestringout: unicodestring = 'yet another bit longer!'; 66 carrbyteout: tarrbyte = (6,6,6); 67 carrsetout: tarrset = ([30,31],[33..38]); 68 69 threadvar 70 venum: tthreadvarkind; 71 vboolean: boolean; 72 vbyte: byte; 73 vsmallint: smallint; 74 vcardinal: cardinal; 75 vint64: int64; 76 vchar: ansichar; 77 vwidechar: widechar; 78 vsingle: single; 79 vdouble: double; 80 vsetint: tsetint; 81 vsetenum: tsetenum; 82 vrec: trec; 83 vshortstring: shortstring; 84 vunicodestring: unicodestring; 85 varrbyte: tarrbyte; 86 varrset: tarrset; 87 i: longint; 88 89 90procedure checkmainthreadvarsinit; 91 var 92 i: longint; 93 begin 94 if venum<>fboolean then 95 raise jlexception.create('enum in'); 96 venum:=cenumout; 97 if venum<>cenumout then 98 raise jlexception.create('enum out'); 99 if vboolean<>false then 100 raise jlexception.create('boolean in'); 101 vboolean:=cbooleanout; 102 if vboolean<>cbooleanout then 103 raise jlexception.create('boolean out'); 104 if vbyte<>0 then 105 raise jlexception.create('byte in'); 106 vbyte:=cbyteout; 107 if vbyte<>cbyteout then 108 raise jlexception.create('byte out'); 109 if vsmallint<>0 then 110 raise jlexception.create('smallint in'); 111 vsmallint:=csmallintout; 112 if vsmallint<>csmallintout then 113 raise jlexception.create('smallint out'); 114 if vcardinal<>0 then 115 raise jlexception.create('cardinal in'); 116 vcardinal:=ccardinalout; 117 if vcardinal<>ccardinalout then 118 raise jlexception.create('cardinal out'); 119 if vint64<>0 then 120 raise jlexception.create('int64 in'); 121 vint64:=cint64out; 122 if vint64<>cint64out then 123 raise jlexception.create('int64 out'); 124 if vchar<>#0 then 125 raise jlexception.create('char in'); 126 vchar:=ccharout; 127 if vchar<>ccharout then 128 raise jlexception.create('char out'); 129 if vwidechar<>#0 then 130 raise jlexception.create('widechar in'); 131 vwidechar:=cwidecharout; 132 if vwidechar<>cwidecharout then 133 raise jlexception.create('widechar out'); 134 if vsingle<>0 then 135 raise jlexception.create('single in'); 136 vsingle:=csingleout; 137 if vsingle<>csingleout then 138 raise jlexception.create('single out'); 139 if vdouble<>0 then 140 raise jlexception.create('double in'); 141 vdouble:=cdoubleout; 142 if vdouble<>cdoubleout then 143 raise jlexception.create('double out'); 144 if vsetint<>[] then 145 raise jlexception.create('setint in'); 146 vsetint:=csetintout; 147 if vsetint<>csetintout then 148 raise jlexception.create('setint out'); 149 if vsetenum<>[] then 150 raise jlexception.create('setenum in'); 151 vsetenum:=csetenumout; 152 if vsetenum<>csetenumout then 153 raise jlexception.create('setenum out'); 154 if vrec.a<>0 then 155 raise jlexception.create('rec.a in'); 156 if vrec.b[3]<>'' then 157 raise jlexception.create('rec.b[3] in'); 158 if vrec.b[4]<>'' then 159 raise jlexception.create('rec.b[4] in'); 160 vrec:=crecout; 161 if crecout.a<>vrec.a then 162 raise jlexception.create('rec.a out'); 163 if crecout.b[3]<>vrec.b[3] then 164 raise jlexception.create('rec.b[3] out'); 165 if crecout.b[4]<>vrec.b[4] then 166 raise jlexception.create('rec.b[4] out'); 167 if vshortstring<>'' then 168 raise jlexception.create('shortstring in'); 169 vshortstring:=cshortstringout; 170 if vshortstring<>cshortstringout then 171 raise jlexception.create('shortstring out'); 172 if vunicodestring<>'' then 173 raise jlexception.create('unicodestring in'); 174 vunicodestring:=cunicodestringout; 175 if vunicodestring<>cunicodestringout then 176 raise jlexception.create('unicodestring out'); 177 for i:=low(varrbyte) to high(varrbyte) do 178 if varrbyte[i]<>0 then 179 raise jlexception.create('arrbyte in'); 180 varrbyte:=carrbyteout; 181 for i:=low(carrbyteout) to high(carrbyteout) do 182 if carrbyteout[i]<>varrbyte[i] then 183 raise jlexception.create('arrbyte out'); 184 for i:=low(varrset) to high(varrset) do 185 if varrset[i]<>[] then 186 raise jlexception.create('arrset in'); 187 varrset:=carrsetout; 188 for i:=low(carrsetout) to high(carrsetout) do 189 if varrset[i]<>carrsetout[i] then 190 raise jlexception.create('arrset out'); 191 end; 192 193 194procedure testmainthreadvarsafterwards; 195 var 196 i: longint; 197 begin 198 if venum<>cenumout then 199 raise jlexception.create('venum out2'); 200 if vboolean<>cbooleanout then 201 raise jlexception.create('boolean out2'); 202 if vbyte<>cbyteout then 203 raise jlexception.create('byte out2'); 204 if vsmallint<>csmallintout then 205 raise jlexception.create('smallint out2'); 206 if vcardinal<>ccardinalout then 207 raise jlexception.create('cardinal out2'); 208 if vint64<>cint64out then 209 raise jlexception.create('int64 out2'); 210 if vchar<>ccharout then 211 raise jlexception.create('char out2'); 212 if vwidechar<>cwidecharout then 213 raise jlexception.create('widechar out2'); 214 if vsingle<>csingleout then 215 raise jlexception.create('single out2'); 216 if vdouble<>cdoubleout then 217 raise jlexception.create('double out2'); 218 if vsetint<>csetintout then 219 raise jlexception.create('setint out2'); 220 if vsetenum<>csetenumout then 221 raise jlexception.create('setenum out2'); 222 if crecout.a<>vrec.a then 223 raise jlexception.create('rec.a out2'); 224 if crecout.b[3]<>vrec.b[3] then 225 raise jlexception.create('rec.b[3] out2'); 226 if crecout.b[4]<>vrec.b[4] then 227 raise jlexception.create('rec.b[4] out2'); 228 if vshortstring<>cshortstringout then 229 raise jlexception.create('shortstring out2'); 230 if vunicodestring<>cunicodestringout then 231 raise jlexception.create('unicodestring out2'); 232 for i:=low(carrbyteout) to high(carrbyteout) do 233 if carrbyteout[i]<>varrbyte[i] then 234 raise jlexception.create('arrbyte out2'); 235 for i:=low(carrsetout) to high(carrsetout) do 236 if varrset[i]<>carrsetout[i] then 237 raise jlexception.create('arrset out2'); 238 end; 239 240 241procedure tmythread.run; 242 var 243 i: longint; 244 begin 245 if venum<>fboolean then 246 raise jlexception.create('enum in'); 247 venum:=cenumin; 248 if venum<>cenumin then 249 raise jlexception.create('enum out'); 250 if vboolean<>false then 251 raise jlexception.create('boolean in'); 252 vboolean:=cbooleanin; 253 if vboolean<>cbooleanin then 254 raise jlexception.create('boolean out'); 255 if vbyte<>0 then 256 raise jlexception.create('byte in'); 257 vbyte:=cbytein; 258 if vbyte<>cbytein then 259 raise jlexception.create('byte out'); 260 if vsmallint<>0 then 261 raise jlexception.create('smallint in'); 262 vsmallint:=csmallintin; 263 if vsmallint<>csmallintin then 264 raise jlexception.create('smallint out'); 265 if vcardinal<>0 then 266 raise jlexception.create('cardinal in'); 267 vcardinal:=ccardinalin; 268 if vcardinal<>ccardinalin then 269 raise jlexception.create('cardinal out'); 270 if vint64<>0 then 271 raise jlexception.create('int64 in'); 272 vint64:=cint64in; 273 if vint64<>cint64in then 274 raise jlexception.create('int64 out'); 275 if vchar<>#0 then 276 raise jlexception.create('char in'); 277 vchar:=ccharin; 278 if vchar<>ccharin then 279 raise jlexception.create('char out'); 280 if vwidechar<>#0 then 281 raise jlexception.create('widechar in'); 282 vwidechar:=cwidecharin; 283 if vwidechar<>cwidecharin then 284 raise jlexception.create('widechar out'); 285 if vsingle<>0 then 286 raise jlexception.create('single in'); 287 vsingle:=csinglein; 288 if vsingle<>csinglein then 289 raise jlexception.create('single out'); 290 if vdouble<>0 then 291 raise jlexception.create('double in'); 292 vdouble:=cdoublein; 293 if vdouble<>cdoublein then 294 raise jlexception.create('double out'); 295 if vsetint<>[] then 296 raise jlexception.create('setint in'); 297 vsetint:=csetintin; 298 if vsetint<>csetintin then 299 raise jlexception.create('setint out'); 300 if vsetenum<>[] then 301 raise jlexception.create('setenum in'); 302 vsetenum:=csetenumin; 303 if vsetenum<>csetenumin then 304 raise jlexception.create('setenum out'); 305 if vrec.a<>0 then 306 raise jlexception.create('rec.a in'); 307 if vrec.b[3]<>'' then 308 raise jlexception.create('rec.b[3] in'); 309 if vrec.b[4]<>'' then 310 raise jlexception.create('rec.b[4] in'); 311 vrec:=crecin; 312 if crecin.a<>vrec.a then 313 raise jlexception.create('rec.a out'); 314 if crecin.b[3]<>vrec.b[3] then 315 raise jlexception.create('rec.b[3] out'); 316 if crecin.b[4]<>vrec.b[4] then 317 raise jlexception.create('rec.b[4] out'); 318 if vshortstring<>'' then 319 raise jlexception.create('shortstring in'); 320 vshortstring:=cshortstringin; 321 if vshortstring<>cshortstringin then 322 raise jlexception.create('shortstring out'); 323 if vunicodestring<>'' then 324 raise jlexception.create('unicodestring in'); 325 vunicodestring:=cunicodestringin; 326 if vunicodestring<>cunicodestringin then 327 raise jlexception.create('unicodestring out'); 328 for i:=low(varrbyte) to high(varrbyte) do 329 if varrbyte[i]<>0 then 330 raise jlexception.create('arrbyte in'); 331 varrbyte:=carrbytein; 332 for i:=low(carrbytein) to high(carrbytein) do 333 if carrbytein[i]<>varrbyte[i] then 334 raise jlexception.create('arrbyte out'); 335 for i:=low(varrset) to high(varrset) do 336 if varrset[i]<>[] then 337 raise jlexception.create('arrset in'); 338 varrset:=carrsetin; 339 for i:=low(carrsetin) to high(carrsetin) do 340 if varrset[i]<>carrsetin[i] then 341 raise jlexception.create('arrset out'); 342 end; 343 344 345procedure test; 346var 347 t1, t2: tmythread; 348begin 349 checkmainthreadvarsinit; 350 t1:=tmythread.create; 351 t1.start; 352 t2:=tmythread.create; 353 t2.start; 354 t1.join; 355 t2.join; 356 testmainthreadvarsafterwards; 357end; 358 359begin 360 test; 361end. 362