TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: ROWAN CROWE
from: DAVE NAVARRO
date: 1995-09-13 11:33:00
subject: Byval

RC> DN> - Passing a flex string:  PowerBASIC makes a copy of the flex string
RC> DN> and converts its type to a dynamic string.  Same rules as above.
RC>    Can you explain what flex strings are, and how they differ from 
ynamic
RC>and fixed length strings? Could they perhaps be strings with a constant
RC>address in memory space, but with variable length still? (ie, heaps faster
RC>than exhaustively allocating and deallocating memory)
RC>    I lost my copy of TRYPB due to HD crash, I can't remember whether that
RC>had online help anyway. :)
A flex string is similar to a fixed length string in the way in which is
is used.  However, the *fixed length* is determined at run-time, not
compile time.
For example, let's say you have a program which you updated from version
1 to version 2.  In version one, your data file had 30 characters for
the users name and in version two you allow 40 characters.  You could
code it like this:
OPEN "DATAFILE" FOR BINARY AS #1
  GET$ 1,,Header
  IF Header.Version = 1 THEN
    GET$ 1,30,UserName$
  ELSEIF Header.Version = 2 THEN
    GET$ 1,40,UserName$
  END IF
CLOSE
However, "everywhere" in your program where you read or write UserName$
you have to test the header version number in order to maintain
compatibility with older databases.
If you use a Flex string instead, it makes it all easier:
DIM UserName AS SHARED FLEX
OPEN "DATAFILE" FOR BINARY AS #1
  GET$ 1,,Header
  IF Header.Version = 1 THEN
    MAP UserName * 30
  ELSEIF Header.Version = 2 THEN
    MAP UserName * 40
  END IF
CLOSE
Now, all you need to do is access UserName which is pre-mapped to the
correct length when you load the header.  The rest of your code doesn't
need to know which version of the data file is being used.
Make sense?
--Dave
---
 * QMPro 1.53 * The road to success is always under construction
--- WILDMAIL!/WC v4.12 
---------------
* Origin: Toast House * (314) 994-0312 * (1:100/560.0)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.