Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-02

Bug with a record type?

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

I'm getting a strange error message from the win32 compiler (ver 1.0.4, 2000/12/30) in a spot that seems like it should be fine. Here's a code snippet, which is just a couple of the more pertinent lines from the source file:

const
  MAX_LINES    = 1000000;
type
  DataRecord   = packed record
                   Data    : string;
                   Display : boolean;
                   Actual  : longint;
                 end;
var
  CurrentLine : longint;
  TotalLines : longint;
  DataFromFile : array [1..MAX_LINES] of ^DataRecord;
for CurrentLine := 1 to TotalLines do
  if DataFromFile [CurrentLine].Display then
  begin
    {$I-}
      writeln (PrinterPort,DataFromFile [CurrentLine].Data);
    {$I+}
    if ioresult  0 then Error (201,FALSE,Port);
  end;

Note that the program in question is, counting units, over 150K of source so I didn't attach it. :-) Also, all memory is assigned properly and the elements of the records have already been filled by the time the program gets to the above bit of code.

I'm getting two errors on the "if DataFromFile [CurrentLine].Display then" line; "Error: illegal qualifier" and "Fatal: Syntax error, THEN expected but identifier DISPLAY found".

Basically the line in question is just checking to see if the boolean from the record (DataFromFile.Display) is TRUE or FALSE. If it's TRUE the line is sent to the printer, otherwise it's ignored. To me that code looks okay, but to FPC is doesn't. Oddly enough, if I try and compile it using VP it compiles and runs fine.

So, did I find an FPC bug or am I doing something totally wrong here? :-)

TIA...

Jim

Johann Glaser
to Unknown author

Hi!

DataFromFile : array [1..MAX_LINES] of ^DataRecord; if DataFromFile [CurrentLine].Display then

You declared DataFromFile as a record of Pointers (^DataRecord), but you try to access it as it was an array of record. Write the above line as:

  if DataFromFile [CurrentLine]^.Display then

so i should work.

Bye
Hansi

Johann Glaser Vienna University of Technology Electrical Engineering http://stud3.tuwien.ac.at/~e9825761/index.html
Unknown author
Hansi, Johan;
Show quoted text 10 lines
You declared DataFromFile as a record of Pointers (^DataRecord), but you try to access it as it was an array of record. Write the above line as: if DataFromFile [CurrentLine]^.Display then so i should work. I don't know anything about VP, so I dont' understand why it compiles this except if you made a typemistake in the code above, but you are declaring an array of POINTERS to DataRecord, not of the records themself. So you have to use DataFromFile[CurrentLine]^.Display;

You're both correct -- I was looking right past that. It's even more amazing that VP compiled and ran the program just fine using the exact same source (and no, there wasn't any typing mistake -- I used cut and paste to take the code directly from the source file itself). Perhaps I should be sending an email to Allan at VP now... :-)

Jim

Peter Vreman
Show quoted text 19 lines
Hansi, Johan; > You declared DataFromFile as a record of Pointers (^DataRecord), > but you try to access it as it was an array of record. Write the > above line as: if DataFromFile [CurrentLine]^.Display then so i > should work. > I don't know anything about VP, so I dont' understand why it > compiles this except if you made a typemistake in the code above, > but you are declaring an array of POINTERS to DataRecord, not of > the records themself. So you have to use > DataFromFile[CurrentLine]^.Display; You're both correct -- I was looking right past that. It's even more amazing that VP compiled and ran the program just fine using the exact same source (and no, there wasn't any typing mistake -- I used cut and paste to take the code directly from the source file itself). Perhaps I should be sending an email to Allan at VP now... :-)

VP is delphi like and has automatic pointer dereferencing so you don't need the ^ anymore. This is against the strict pascal rules so we don't support it in the fpc modes. Try the to compile with -Sd that is more Delphi/VP compatible.

Johan Blok
to Unknown author: I'm getting a strange error message from the win32 compiler (ver 1.0.4, 2000/12/30) in a…
Show quoted text 21 lines
type DataRecord = packed record Data : string; Display : boolean; Actual : longint; end; var CurrentLine : longint; TotalLines : longint; DataFromFile : array [1..MAX_LINES] of ^DataRecord; for CurrentLine := 1 to TotalLines do if DataFromFile [CurrentLine].Display then begin {$I-} writeln (PrinterPort,DataFromFile [CurrentLine].Data); {$I+} if ioresult 0 then Error (201,FALSE,Port); end;

I don't know anything about VP, so I dont' understand why it compiles this except if you made a typemistake in the code above, but you are declaring an array of POINTERS to DataRecord, not of the records themself.
So you have to use DataFromFile[CurrentLine]^.Display;

Johan Blok