Board index » delphi » "data" statement in TP7

"data" statement in TP7

Quote
Jeremy Gershwin wrote:
> Is there a data statement like in BASIC or FORTRAN?  I need to store
> values in a string array and would like not to have to set each array
> subscript equal on separate lines.

Not per se.  Pascal is a good deal more structured, and variables must
all be either declared or initialized -- though there are ways to fake
it, you don't really see loose data collections floating around.

You can use typed constants, such as:

const
  newdata : array[1..10] of byte =
    (53,39,27,82,74,29,12,64,98,42);

This creates an array of bytes, with all 10 elements assigned values.
(Note that you can't assign values to fewer or more elements than are
declared in the variable.)

Quote
> Thanx.

--
Scott Earnest                      | _,-""-_,-""-_,-""-_,-""-_,-""-_,-"
|
set...@ix.netcom.com (primary)     | We now return you to our regularly
|
siny...@{*word*104}space.org (alternate) | scheduled chaos and mayhem. . . .
|
 

Re:"data" statement in TP7


Is there a data statement like in BASIC or FORTRAN?  I need to store
values in a string array and would like not to have to set each array
subscript equal on separate lines.

Thanx.

Re:"data" statement in TP7


In article <32DCECBA.7...@ix.netcom.com>, Scott Earnest
<set...@ix.netcom.com> writes

Quote
>You can use typed constants, such as:

>const
>  newdata : array[1..10] of byte =
>    (53,39,27,82,74,29,12,64,98,42);

>This creates an array of bytes, with all 10 elements assigned values.
>(Note that you can't assign values to fewer or more elements than are
>declared in the variable.)

Just like to make it clear to the original poster that a "typed
constant" in Turbo Pascal is a bit of a misnomer because they are really
initialized variables that can be modified just like any other variable.

Typed constants are always stored in the data segment, regardless of
whether they are declared locally or globally.  They should not
therefore usually be used for large structures because TP has only one
data segment which is limited to a maximum size of 64k.

Jay
--
 --------------------------------------------------------------------------
| Jason Burgon - author of Graphic Vision, TV-Like GUI for 256 Colour SVGA |
| g...@jayman.demon.co.uk                                                    |
| ***VERSION 1.40 OF GV AVAILABLE FROM*** -> http://www.jayman.demon.co.uk |
 --------------------------------------------------------------------------

Turnpike evaluation. For Turnpike information, mailto:i...@turnpike.com

Re:"data" statement in TP7


Quote
Jeremy Gershwin (mul...@gate.net) wrote:

: Is there a data statement like in BASIC or FORTRAN?  I need to store
: values in a string array and would like not to have to set each array
: subscript equal on separate lines.
:
: Thanx.

Write your data to a binary file - raw numbers only.
Use binobj.exe to convert the binary file to an object file.
Link this .obj file into your exe, and get the data from there - this has the
same effect as a data statement - hunks of numbers at the end of your prog.
assign a pointer to the linked data, and access it that way.

squigger hops again

Re:"data" statement in TP7


Quote
Nexus User wrote:

> Jeremy Gershwin (mul...@gate.net) wrote:
> : Is there a data statement like in BASIC or FORTRAN?  I need to store
> : values in a string array and would like not to have to set each array
> : subscript equal on separate lines.
> :
> : Thanx.

> Write your data to a binary file - raw numbers only.
> Use binobj.exe to convert the binary file to an object file.
> Link this .obj file into your exe, and get the data from there - this has the
> same effect as a data statement - hunks of numbers at the end of your prog.
> assign a pointer to the linked data, and access it that way.

> squigger hops again

Use a typed constant, such as:

const
  my_data : array[1..3] of string[10] = ('one', 'two', 'three');

Typed constants are nothing more than initialized global variables.

I hope it helps.

Votis Kokavessis

Re:"data" statement in TP7


Quote
Votis (vo...@paratiritis.the.forthnet.gr) wrote:
: Nexus User wrote:

: >
: > Jeremy Gershwin (mul...@gate.net) wrote:
: > : Is there a data statement like in BASIC or FORTRAN?  I need to store
: > : values in a string array and would like not to have to set each array
: > : subscript equal on separate lines.
: > :
: > : Thanx.
: >
: > Write your data to a binary file - raw numbers only.
: > Use binobj.exe to convert the binary file to an object file.
: > Link this .obj file into your exe, and get the data from there - this has the
: > same effect as a data statement - hunks of numbers at the end of your prog.
: > assign a pointer to the linked data, and access it that way.
: >
: > squigger hops again
:
: Use a typed constant, such as:
:
: const
:   my_data : array[1..3] of string[10] = ('one', 'two', 'three');
:
: Typed constants are nothing more than initialized global variables.
:
: I hope it helps.
:
: Votis Kokavessis

Yes, but what if you have HUNDREDS of bytes?  Are you going to do
constants for all of them?
If you want strings and such forth, use the ascii values and an end of
string marker of your choice, and just interpret the data appropriately -
it's not all that hard

squigger hops again

Re:"data" statement in TP7


On Tue, 21 Jan 1997 12:44:24 -0800,  Votis

Quote
<vo...@paratiritis.the.forthnet.gr> wrote:
>Nexus User wrote:
>> Write your data to a binary file - raw numbers only.
>> Use binobj.exe to convert the binary file to an object file.
>> Link this .obj file into your exe, and get the data from there - this has the
>> same effect as a data statement - hunks of numbers at the end of your prog.
>> assign a pointer to the linked data, and access it that way.

>Use a typed constant, such as:

>const
>  my_data : array[1..3] of string[10] = ('one', 'two', 'three');

>Typed constants are nothing more than initialized global variables.

Your solution may be acceptable for a small amount of data, but they go
in the ever previous 64k data segment. Your simple example uses 33 bytes
to store 14 bytes of information. If string data is "packed" end-to-end
in a code block, there would be no wasted space.  With an old version of
TP that doesn't support pointer arithmetic, you can still walk a string
pointer to the next string using:   p := @p^[Length(p^)+1];

If you simply write strings terminated with a carriage return (#13) and
follow the last carriage return with a ^Z, you can open the data as a
memory based text file. See OpenVAR TFDD in the files unit on my home
page.

    ...red

Re:"data" statement in TP7


Quote
Votis wrote:

[snipped]

Quote
> Of course I agree that some kind of binary file, possibly included into
> the executable as a dummy procedure, is much more efficient regarding the
> size of the data, but, this would require a way to reconstruct the data
> structure from the binary file (OK for me and you, but not exactly a
> trivial task for somebody coming from BASIC of FORTRAN).

Not necessarily: you could have a small program to create your data structures,
then dump the binary image to file and link it into you program.
In your program, refer to the linked-in data with a pointer to an identical
data structure, that should do the trick.
To make things easy, I would avoid using pointers in this data structure.
Also, under windows or DPMI you will have to create a selector alias.

Quote
> BTW, the array which will finally hold the data can not exceed 64K
> either. Of course we can use an array of pointers and allocate strings
> on a per-needed basis, but this makes the whole process even more
> complicated -- I hope you see my point.If dealing with a lot of strings, an external file would be my first choice.

However, this makes the data easily accessible to users, which might not
be acceptable (although encryption/compression might help there).

Quote
> Anyway, as I already said, what you are suggesting is basically right.

> Happy coding

> Votis Kokavessis

Succes

Remco
--
--------------------------------------------------------------------------------
This is an automatically generated signature for Remco Vietor in netscape.
The views expressed in this message should be taken as the personal views of
the author, unless stated otherwise.

Other Threads