Editing files

I've got a file of the following type:

TYPE Glostyp = RECORD
  SveOrd : String[25];
  UtlOrd : String[25];
  Korrekt : Boolean;
END;

glosfil : FILE OF Glostyp;

When my program starts it reads in all the words from the file in an array of glostyp:
glosor : ARRAY[1..200] OF Glostyp;

The user is then prompted to specify a search word and glosor[i] that matches the searchword shows on screen.
If the users chooses to delete glosor[i] the word should also be deleted from the file, how do I accomplish this?
The order in the file can't be messed up, it has to be the same as it was in the beginning, except for the deleted word.
PsychoFoxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HypoCommented:
Can't you just rewrite the file at shutdown whenever a change to the "glosor list" has been made?
e.g. If you remove an item in the array remake the list so that all valid items (glosor) follow eachother in the correct order... Then, before you close the program, just overwrite the whole file with the altered array.

(Is there any reason for the Korrekt variable within the Glosor Type to be in the file???)
0
BatalfCommented:
Hei

I agree with Hypo. You should remove the entry from the glosor array and then rewrite the glosfil.

To delete the word from the array you should use a for-structure

ex : the word you want to delete is number 'n' in the array.

for i:=n to 199 do
glosr[i]:=glosr[i+1];

then, you should rewrite the file :

assignfile(glosfil,<path>);
rewrite(glosfil);
write(glosfil, glosr);
close(glosfil);


the structure would then be like it was, except from the deleted word.

It could also be useful to have a total-integer which tell you how many words you have in your array. When you add a word, the total would increase by one, and when you delete on, it would be decreased by one. Then you don't have to search through empty entries.

Hope my answer would help you.

Batalf
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PsychoFoxAuthor Commented:
Thanks to both of you, I'll check this out.

I have already have a total word-count :)

(The korrekt variable is should be there, it keeps record of which words were correct and which were not (this is a part of a word-knowledge program))
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

PsychoFoxAuthor Commented:
Thanks to both of you, I'll check this out.

I have already have a total word-count :)

(The korrekt variable is should be there, it keeps record of which words were correct and which were not (this is a part of a word-knowledge program))
0
scrapdogCommented:
assign some arbitrary value, such as "xxxx", to the SveOrd of the glosor you want to delete (or some value you are sure that will never occur otherwise).

Then when you rewrite the file, simply skip over (don't write) the records that contain a SveOrd of "xxxx" (or whatever value you choose)
0
BatalfCommented:
Have you tried some of our tip?
0
geteCommented:
An addition to scrapdog, to prevent losing changes caused by e.g. power blackout (or somehow the computer got hang in the middle of the running program), make change to the record in the file too, so if something happened, you don't lose the deletion made in previous session. At the end of the session, you could recreate the file skipping the "marked" record. It wouldn't take too much time to perform the rewriting (unless the size is really huge), or if size doesn't matter to you, just leave the deleted record, in the next sessions when you open and read it, skip the "marked" record. You can optionally make a function similar as "PACK" in old x-Base apps to physically delete all the "marked" records.

Regards, Gt
0
PsychoFoxAuthor Commented:
Thank you!
I was on holiday for some time and I didn't have any time to look at you answers.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.