Table.Fieldvalues returns empty string

Here are three code snippets, two of them are working, one not

1. Working
   tbl.First;
   while not tbl.EOF do begin
      s := '';
      for i := 0 to tbl.Fields.Count-1 do begin
         if i > 0 then
            s := s + ';';
         s := s + tbl.Fields.Fields.AsString;
      end;
      tbl.Next;
      sl.Add(s);
   end;

2. Working
   tbl.First;
   while not tbl.EOF do begin
      s := '';
      for i := 0 to tbl.Fields.Count-1 do begin
         if i > 0 then
            s := s + ';';
         sn := tbl.Fields.Fields.Fieldname;
         s := s + tbl.FieldByName(sn).AsString;
      end;
      tbl.Next;
      sl.Add(s);
   end;
3. Not working, s is an empty string
   tbl.First;
   while not tbl.EOF do begin
      s := '';
      for i := 0 to tbl.Fields.Count-1 do begin
         if i > 0 then
            s := s + ';';
         sn := tbl.Fields.Fields.Fieldname;
         s := s + tbl.FieldValues[sn];
      end;
      tbl.Next;
      sl.Add(s);
   end;

I forgot to mention that all fields in the table are string fields.
No conversion is necessary.

It works here. Can you please provide a project that reproduces the issue?

Now I have the requested demoproject ready.
When the script is run it creates a full table, but a mostly empty memo.
Comment out the lines 528/529 in the script and uncomment line 531, now the memo is filled with the same data as the table.
I send the project to the email wagner@tmssoftware.com.

Hello Gerhard,

Thank you for the project.
Use this:


         s := s + VarToStr(tbl.FieldValues[sn]);


FieldValues return a NULL variant if the field in database is null, thus nullifying the whole "s" variable.
Hello Wagner,

the basic problem is known, assigning a NULL value to a string is not possible.
But what if a non NULL fieldvalue follows a NULL value.
The table returns a valid string, but scripter does not accept it anymore.
If the string does no longer exist, probably because it was set to NULL, assigning a valid string to it should produce anything else than an empty string.
Doing that in Delphi I throws an exception and that was what I expected.

However, this is a rather academic discussion.
Doing it the way you proposed or using FieldbyName('fieldname').AsString both give correct results.