Board index » delphi » Bug in AdoExpress for WideString fields

Bug in AdoExpress for WideString fields

TWideStringField.Value will return unexpected results if the underlying
field is NULL.

Example:

var
    F: TWideStringField;
    w: WideString
begin
    ....
    w := F.Value;  // correctly returns value of F, ie.  "First record"
    DataSet.Next;
    w := F.Value;  // if underlying value is NULL, displays "FirstRecord"
end;

Solution:
    w := '';             // initialize return value to empty string
    w := F.Value;  // correctly returns empty string if underlying value is
NULL

BetterSolution (Attention Borland Developers):
  function TWideStringField.GetAsWideString: WideString;
  begin
    Result := '';  // initialize return value to empty string
   GetData(@Result, False);
  end;

 

Re:Bug in AdoExpress for WideString fields


Better Solution yet:

function TWideStringField.GetAsWideString: WideString;
begin
  if not GetData(@Result, False) then
    Result := '';
end;

Quote
>   function TWideStringField.GetAsWideString: WideString;
>   begin
>     Result := '';  // initialize return value to empty string
>    GetData(@Result, False);
>   end;

Re:Bug in AdoExpress for WideString fields


I did a little digging in the DB.PAS unit and found that in general, the the
return value of GetData (boolean) is checked and a default is provided when
GetData returns false.  TWideStringField.GetAsWideString is the ONLY
exception (thank goodness!).  Because this is not related to ADO, my
apologies.  I'm going to post this under the database.desktop newsgroup.

Quote
"Troy Wolbrink" <wolbr...@ccci.org> wrote in message

news:3c2382fc_2@dnews...
Quote
> Better Solution yet:

> function TWideStringField.GetAsWideString: WideString;
> begin
>   if not GetData(@Result, False) then
>     Result := '';
> end;

> >   function TWideStringField.GetAsWideString: WideString;
> >   begin
> >     Result := '';  // initialize return value to empty string
> >    GetData(@Result, False);
> >   end;

Other Threads