BBC BASIC for Windows
« Transfering PTR to procs »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:15pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Transfering PTR to procs  (Read 683 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Transfering PTR to procs
« Thread started on: Jul 7th, 2013, 06:30am »

Hi,

One of my programs requires records to be located using an index containing the pointers to each record. The routine opens the file and passes the file handle to a subroutine that loads the record. Due to the nature of the main routine, the file has to be opened first and then passed to the subroutine. However, I also have to pass the PTR to the subroutine via reference as well, as the subr assumes beginning of file otherwise.

This:
Code:
...
F% = OPENIN(file$)
PTR#F% = [indexed file ptr]
PROC_READ_RECORD(F%)
...

DEF PROC_READ_RECORD(fn%)
INPUT#fn%, text$
... 

will not work.

I need to do this:
Code:
...
F% = OPENIN(file$)
PROC_READ_RECORD(F%, [indexed file ptr])
...

DEF PROC_READ_RECORD(fn%, ptr%)
PTR#fn% = ptr%
INPUT#fn%, text$
... 


There is no real problem with doing this; it's just adding another parameter. I was just curious. Is this by design or the fact that a LOCAL variable is being used as the new file handle?

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Transfering PTR to procs
« Reply #1 on: Jul 7th, 2013, 06:49am »

on Jul 7th, 2013, 06:30am, Matt wrote:
There is no real problem with doing this; it's just adding another parameter.

There must be something wrong elsewhere in your program, since your first example - that you claim does not work - in fact is perfectly fine. A file is a global object, and if you set the file pointer in one part of your program it will remain set when accessed somewhere else. There's no way that simply calling a PROC can change it!

Go back to your original code, if you prefer it for simplicity, and debug the fault your end.

Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Transfering PTR to procs
« Reply #2 on: Jul 7th, 2013, 5:06pm »

on Jul 7th, 2013, 06:49am, Richard Russell wrote:
There must be something wrong elsewhere in your program, since your first example - that you claim does not work - in fact is perfectly fine. A file is a global object, and if you set the file pointer in one part of your program it will remain set when accessed somewhere else. There's no way that simply calling a PROC can change it!

Go back to your original code, if you prefer it for simplicity, and debug the fault your end.



Mmm! Ok. Not sure what went wrong to start with. Just changed it and it worked fine. I did experiment with it at the start and it didn't seem to work what ever I did. Oh, well. Thanks.

Matt
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls