FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

FB II COMPILER

Pass a record to a local function



You can pass integers, strings, and floats to a function as parameters, but FB does not let you pass the entire record.

So you have to resort to a little trick called "pass by reference." Instead of passing the entire record to the function, just tell the function where to find the record by passing its pointer:

LOCAL FN processThisRecord(theRecordPtr&)
  theRecordPtr&.field% = somevalue&
  othervalue& = theRecordPtr&.otherfield&
END FN

DIM myRec.myType
FN processThisRecord(@myRec)

"Parameter block" is a Mac toolbox term. It is a record that refers to one entity - a serial port, a file, a folder. You can pass the same record to a series of Toolbox calls; they use the record to communicate with each other and to store the current information about the file.

Parameter blocks are often _variant records_, a structure FB doesn't support directly. It's a record that can have different sets of fields, depending on what the block represents.

Inside a funtion, to copy an entire record at once, use this syntax:

NewRecord;_myRecordSize = AddressOfRecord&

This means: copy the number of bytes specified in _myRecordSize (which must be a constant) from the variable AdressOfRecord& points at, into NewRecord.

Mars


If you like to save typing, here's a technique that Staz sometimes uses in their code snippets:

DIM a%,b&,25 c$
LOCAL FN TestRec(recAddr&)
  a%;_testRec=recAddr& ' copy record to the above location
  PRINT a%,b&,c$
END FN

It takes longer, but I imagine the extra time wouldn't be noticeable if your loop isn't too large. It's also good for putting strings in records, since you don't have to go back and automatically insert the length byte yourself.

Wave