Question about Records

I am using Virtual Pascal 2.1

I am curious as to 2 things:

1. Is it possible to append records to a file instead of using a set array to store them? What I mean by append is as in how you append text to a text file

2. Is it possible to store a linked list of records in a file? What I am asking is if its possible to store the linked list records the same way you would normally store records into a file..

The main reason is I am pretty sure that pascal does not allow you to change the size of an array once it is declared and I would rather not limit my program to a set number of records, instead I would like the records to be added on to the file as they are created. Thanks

Comments

  • : 1. Is it possible to append records to a file instead of using a set array to store them? What I mean by append is as in how you append text to a text file

    Seek(FileSize(F)); will seek to the end of the file, then Write(F, ARecord); will append ARecord to the end of it.

    : 2. Is it possible to store a linked list of records in a file? What I am asking is if its possible to store the linked list records the same way you would normally store records into a file..

    It's possible, but not really a good idea. If you read all the records into memory and rewrite the file each time thats more disk I/O than necessary. And it means your program can only have 1 instance running at any given time. Imagine:

    Instance 1) Reads file into memory, changes record 1.
    Instance 2) Reads file into memory, changes record 2.
    Instance 1) Writes records from memory to file.
    Instance 2) Writes records from memory to file. Now you just lost the change Instance 1 made to record 1.

    So basically, you should only read and modify 1 record at a time. There are times where you may need to read more at a time, but definitely dont do it unless you absolutely have to.

    : The main reason is I am pretty sure that pascal does not allow you to change the size of an array once it is declared and I would rather not limit my program to a set number of records, instead I would like the records to be added on to the file as they are created.

    Depends on what compiler you use. More advanced ones like Delphi and FPC can, but I dont think VPascal can.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion