| 
 
| 
|  Author | Topic: Transfering PTR to procs  (Read 684 times) |  |  
| 
| 
| Matt Developer
 
 member is offline
 
  
 
 
 
 
  
 Gender:
  Posts: 210
 
 | 
|  | 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
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| admin Administrator
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 1145
 
 | 
|  | 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.
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| Matt Developer
 
 member is offline
 
  
 
 
 
 
  
 Gender:
  Posts: 210
 
 | 
|  | 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
 |  
| 
|  |  Logged |  
 |  |  |  
 |