[futurebasic] Re: [FB] question about pointers [important]

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2000 : Group Archive : Group : All Groups

From: Robin <robinc@...>
Date: Tue, 25 Jul 2000 08:05:26 +1000
> 1) You said that you can't use DIM aPointer AS POINTER TO anyRecord, but can
> you in a local function? For example:
> 
> LOCAL FN ClearWeaponRecord(WeaponRecord AS POINTER TO WeaponRec)
> 
> WeaponRec is the name of the record for my weapon information (its in
> globals because it is editable by the user in the scenario editor).

Yes, that will work, if you pass a pointer to it of course, as in:

DIM weapon as WeaponRec '<<< global or local DIM both OK
FN  ClearWeaponRecord(@ weapon)

> 2) So.. would this function work?
> 
> LOCAL FN WhatWeaponField(number, WeaponRecord AS POINTER TO WeaponRec)
> DIM aPointer AS POINTER
> SELECT number
> CASE 1
> aPointer = @WeaponRecord.start
> CASE 2
> aPointer = @WeaponRecord.middle
> CASE 3
> aPointer = @WeaponRecord.end
> END SELECT
> END FN = aPointer

Yes, but there isn't much point. You can get the same result faster and
simpler by doing aPointer = @WeaponRecord.start etc in the caller. Ie,
instead of:

LOCAL FN Caller
    DIM weapon as WeaponRec, aPointer as POINTER
    ...
    aPointer = FN WhatWeapon(2,@weapon)
    ...
END FN
    
just this:

LOCAL FN Caller
    DIM weapon as WeaponRec, aPointer as POINTER
    ...
    aPointer = @weapon.middle
    ...
END FN

-- 
Robin
====================================================
Genesearch Pty Ltd
E-mail: robinc@...
WWW:    http://www.genesearch.com.au
====================================================