Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Random Access Files

Author
Message
Mickyfyn
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: UK
Posted: 27th Nov 2003 12:54
Hi

I am a darkbasic newbee but have some experience of Delphi, I would lie to create a random access file, but apart from a brief mention in 'The Beginners Guide to Dark Basic' I can find no way of structuring the file. Any advice would be welcome.

Mickyfyn
Toothpick
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location:
Posted: 27th Nov 2003 15:41 Edited at: 27th Nov 2003 15:43
You can only acess a file in sequential order. forwards.
You can get aroud this by making a memblock of the file, then use
a int to point to a position in the file.





basicly the code writes a string in to a memblock.
To insert data you will need to resize the memblock since the size of the memblock will change.
also copy the data that is after the insert point to preserve it.


The code was ripped from one of my progs dont try to use it as it is, it wont work.

RAF are complex things to do (and debug) just delete the old file and write a new one, save yourself the bother.
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 27th Nov 2003 15:49 Edited at: 27th Nov 2003 15:51
Darkbasic only provides sequential access to files.
You could perhaps fake random access by writing some functions.
There is a problem with that, Darkbasic has a method to move forward in an open file (skip bytes), but no way to move backwards in a file, not even to the start. If you want to read the begining of the file again you have to close the file and open it again. I think this would be pretty slow on big files or if you where accessing it a lot. Also when you write to a file it has to be written in one go, there isn't even an append method.

Or you can sequentialy load the whole file into and array and access the data in the array randomly. Then when save it back into a file sequentialy when you have finished with it. This is proberly the best way unless you or someone else writes a dll.

dbpro : p166mmx @ 233 : 256mb : sb 128pci : sis onboard
Mickyfyn
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: UK
Posted: 28th Nov 2003 13:08
Toothpick & the_winch

Thanks for your time and the information.

I'll get by using a sequential file.

Mickyfyn
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 3rd Dec 2003 00:19
If you've got DBPro, I've added a File I/O set of commands for random access, which you may find useful.


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...

Login to post a reply

Server time is: 2024-09-21 11:40:54
Your offset time is: 2024-09-21 11:40:54