[fpc-pascal] I think I must be the first person to ever use tmemds for anything serious...

David Mears david.mears at cox.net
Thu Oct 26 02:20:43 CEST 2006


I think I've just found my 3rd bug in the unit.

for me, it always says true when booleans are returned with .asBoolean,
and as empty strings when returned with .asString with the latest svn
compiler, is this also true of the release compiler?

-------------- next part --------------
{
    This file is part of the Free Component Library (FCL)
    Copyright (c) 1999-2000 by the Free Pascal development team

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
{$mode objfpc}
{$h+}

program testpop;

uses db,memds,classes,sysutils;

Procedure DoTest;

var
  I,ACount : integer;
  D   : TDateTime;

begin
  with TMemDataset.Create(Nil) do
    Try
      With FieldDefs do
        begin
        Clear;
        Add('Boolean', ftBoolean, 0, False);
        Add('Integer', ftInteger, 0, False);
        Add('SmallInt', ftSmallInt, 0, False);
        Add('Float', ftFloat, 0, False);
        Add('String', ftString, 30, False);
        Add('Time', ftTime, 0, False);
        Add('Date', ftDate, 0, False);
        end;
      CreateTable;
      Open;
      D:=3Dnow;
      ACount:=3D1000;
      for I:=3D1 to ACount do
        begin
        Append;
        FieldByName('Boolean').AsBoolean:=3Di mod 2 =3D 1;
        FieldByName('Integer').AsInteger:=3DI;
        FieldByName('SmallInt').AsInteger:=3DI;
        FieldByName('Float').AsFloat:=3DI/10;
        FieldByName('String').AsString:=3D'Test-Data '+IntToStr(I);
        FieldByName('Time').AsDateTime:=3DD;
        FieldByName('Date').AsDateTime:=3DD;
        Post;
        end;
      First;
      ACount:=3D0;
      While Not EOF do
        begin
        Inc(ACount);
        Writeln('Record ',ACount,' : ');
        Writeln('------------------------');
        For I:=3D0 to Fields.Count-1 do
          case fields[i].DataType of
	  ftBoolean:
	  begin
	    writeln('should say "TRUE" and "FALSE" alternately');
	    if fields[i].asboolean then Writeln(Fields[I].FieldName,' : TRUE') els=
e Writeln(Fields[I].FieldName,' : FALSE');
	    Writeln(Fields[i].FieldName,' :',fields[i].asString);
	  end;
	  ftInteger:Writeln(Fields[I].FieldName,' : ',Fields[I].AsInteger);
	  ftSmallInt:Writeln(Fields[i].FieldName,' : ',Fields[i].AsInteger);
	  ftFloat:Writeln(Fields[i].FieldName,' : ',Fields[i].AsFloat); //CRASH
	  ftString:Writeln(Fields[i].FieldName,' : ',Fields[i].AsString);
	  ftTime:Writeln(Fields[i].FieldName,' : ',Fields[i].AsDateTime);
	  ftDate:Writeln(Fields[i].FieldName,' : ',Fields[i].AsDateTime);
	  end;
        Writeln;
        Next;
        end;
      Writeln('Total data size : ',DataSize);
      If (ParamCount>0) then
        FileName:=3DParamStr(1);
      Close;
  finally
    Free;
  end;
end;

begin
  DoTest;
end.


More information about the fpc-pascal mailing list