Hi all, I never playing around with variant using FPC before, until last night. :D Currently I'm using FPC 2.0.0 (downloaded from SF) on Pentium III with WinXP SP 2.
I found a strange behavior of string in FPC variant array. Unfortunately, I hardly can find good enough informations about variant in FPC docs. There's no chapter about it in the RTL doc, though the Variants unit does exist. So, I assume FPC variant is just like Delphi variant. :) Here is the code... --------- 1: program VarTest; 2: 3: {$APPTYPE CONSOLE} 4: 5: uses 6: Variants; 7: 8: var 9: v: Variant; 10: 11: begin 12: // this works fine 13: v := 'abcdefghijklmnopqrstuvwxyz'; 14: Writeln(v); 15: 16: // this variant array works but all 17: // the strings content are cropped 18: v := VarArrayCreate([0,6], varVariant); 19: v[0] := 1; 20: v[1] := 123.4; 21: v[2] := 'abcdefghijklmnopqrstuvwxyz'; 22: v[3] := true; 23: v[4] := vararrayof([1,2,3,4]); 24: v[5] := 'abcdefghijklmnopqrstuvwxyz'; 25: v[6] := 'abcdefghijklmnopqrstuvwxyz'; 26: writeln(v[0]); 27: writeln(v[1]); 28: writeln(v[2]); 29: writeln(v[3]); 30: writeln(v[4][2]); 31: writeln(v[5]); 32: writeln(v[6]); 33: end. --------- And the program output is... --------- ¦ Free Pascal IDE Version 1.0.4 [2005/05/08] ¦ Compiler Version 2.0.0 ¦ GBD Version GDB 6.2.1 ¦ Cygwin "C:\Programs\FreePascal\bin\i386-win32\cygwin1.dll" version 1005.12.0.0 Running "c:\trash\vartest.exe " 1: abcdefghijklmnopqrstuvwxyz 2: 1 3: 123,40000000000001 4: abcdefghijklm 5: True 6: 3 7: abcdefghijklm 8: abcdefghijklm --------- while the same code compiled using Delphi 7 generates output like this... --------- C:\Trash>vartest.exe 1: abcdefghijklmnopqrstuvwxyz 2: 1 3: 123,4 4: abcdefghijklmnopqrstuvwxyz 5: True 6: 3 7: abcdefghijklmnopqrstuvwxyz 8: abcdefghijklmnopqrstuvwxyz --------- See what I meant? They're on output line number 4, 7, and 8. And also on number 3 (floating number). While the code is compiled using FPC, switching compilation mode to FPC, or OBJFPC, or Delphi, will have same output result. So... is there any explanation about this? Thanks. -Bee- has Bee.ography at: http://beeography.modblog.com _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal