Recent

Author Topic: boolean evaluation error  (Read 6527 times)

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
boolean evaluation error
« on: November 05, 2007, 11:19:34 pm »
I’ve ported a delphi app (without the gui) to wince and it runs ok on the emulator. However, I get strange boolean evaluation, always getting ‘false’. Is this known issue or a compiler switch?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2514
RE: boolean evaluation error
« Reply #1 on: November 06, 2007, 12:37:58 pm »
Do you have sample code ?
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
boolean evaluation error
« Reply #2 on: November 06, 2007, 03:26:26 pm »
This is a sample of a record:

TSRec=record
   ID:integer;
   Name:string[150];
   Tp:shortint
   kat:byte
   rem:string[10];
   Admin,IsFromUser:boolean;
   Place:string[100];
   ....
 end;        

And this is how the file is loaded:

  assignfile(f,Fname);
  {$I-} reset(f); {$I+}
  if IOResult<>0 then exit;
  seek(f,HeadJump-1050+HJ2-545);
  MultiList.SetCapacity(filesize(f) div sizeof(SymptRec));
 
  while not eof(f) do
  begin
    read(f,SymptRec);
    //if SymptRec.Admin then
    MultiList.Add([SymptRec.Name],SymptRec.ID,SymptRec.kat],[SymptRec.Admin,SymptRec.IsFromUser]);
  end;
 
  closefile(f);    
                     

When the file is loaded in lazarus/win32 everything works fine, but when I use the wince all records show “Admin=0” although the file contain records with various values. All other parts seem to function correctly.

Bart

  • Hero Member
  • *****
  • Posts: 4045
    • Bart en Mariska's Webstek
boolean evaluation error
« Reply #3 on: November 06, 2007, 04:21:01 pm »
A wild guess.
Could it have anything to do with the alignment of the data in your records?

If you store it like this, and change platform, alignement may differ. I'm not even sure that SizeOf(Integer) is always the same under different OS's.

Try to use a packed record (first write the file with packed records under win32) and see what you get?

Bart

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
boolean evaluation error
« Reply #4 on: November 06, 2007, 04:33:16 pm »
I had the same thought and change the delphi compiler alignment but it didn't work out. I will try your idea with the packed record option.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2514
boolean evaluation error
« Reply #5 on: November 06, 2007, 04:33:55 pm »
since other values are OK, I don't think it has something to do with aligning (and iirc aling rules for fpc are the same for every platform)
Who is writing the booleans and what (integer) value do they have ?

There is a difference between a C boolean and a pascal boolean. In C anything <> 0 is equal to true, where in pascal it depends on implementation what the value of true is.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
boolean evaluation error
« Reply #6 on: November 06, 2007, 05:07:07 pm »
The files originated from D2007 and they have a value of -1 or 0. When reading the file on wince I get 0 for all records.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2514
boolean evaluation error
« Reply #7 on: November 07, 2007, 11:27:32 am »
didn't notice before, but are the values in the Place member OK ? since you're not using them in your example
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Jo

  • Jr. Member
  • **
  • Posts: 63
    • http://www.taomedic.com
boolean evaluation error
« Reply #8 on: November 07, 2007, 12:16:33 pm »
As you've suggested this post will continue in the pda forum. Thanks.

 

TinyPortal © 2005-2018