EOF 
Author Message
 EOF

Can you use Eof on an array. kinda something like

while not EOF(ray) DO
  X := X + 1;

ray = an array
matty mtat



Wed, 18 Jun 1902 08:00:00 GMT  
 EOF


Quote:

>Can you use Eof on an array. kinda something like

>while not EOF(ray) DO
>  X := X + 1;

>ray = an array

What you say makes no sense. Arrays do not have any internal pointers
that can be at any eof. If you want to compare X to the highest index in
array use if x<=high(ray)

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 EOF

Quote:

> Can you use Eof on an array. kinda something like
> while not EOF(ray) DO
>   X := X + 1;

Strange question...

  Type SomeTyp = Word;   { just as an example }
  Const a = -10; b = 10; { just as an example }

  Var Index,X: LongInt; RAY: Array[a..b] Of SomeTyp;
  Begin
    x := 0;
    For Index := Low(RAY) to High(RAY) Do
      X := X + 1;
  End.

  the same in one line:
  X := SizeOf(RAY) Div SizeOf(SomeTyp);

or do you mean

  Begin
    x := 0;
    For Index := Low(RAY) to High(RAY) Do
      X := X + RAY[Index];
  End.

???

Low(RAY) = Low bound of array RAY
High(RAY) = High bound of array RAY



Wed, 18 Jun 1902 08:00:00 GMT  
 EOF

XmtatX schrieb:

Quote:

> Can you use Eof on an array. kinda something like

> while not EOF(ray) DO
>   X := X + 1;

> ray = an array
> matty mtat

Your question is really strange for Pascal programmers. With Pascal an
array and its size is defined at compile time.

Yet there could be a reason why you need such an awkward construction,
if you pass the array to a procedure as Var parameter, say with an
untyped or typecast parameter. In Pascal you will have to pass the
actual size of the actual array too as an additional parameter.

There is one exception in TP: with strings this size parameter is passed
automatically by the compiler. And a string is an array, isn't it?`

With any other array you must pass the actual size. Another suggestion:
use records which contain the size and the array (as a pointer for
instance) or even better, use objects. Here you have all freedom.

But you must be aware that all typecasting and similar "tricks" bypass
the formidable type checking benefits of Pascal!

http://www.geocities.com/~franzglaser/tp.html
Franz Glaser
http://members.eunet.at/meg-glaser



Wed, 18 Jun 1902 08:00:00 GMT  
 EOF

Quote:



> >Can you use Eof on an array. kinda something like

> >while not EOF(ray) DO
> >  X := X + 1;

> >ray = an array

> What you say makes no sense. Arrays do not have any internal pointers
> that can be at any eof. If you want to compare X to the highest index
> in
> array use if x<=high(ray)

     It DOES make sense if you think about storing a
perhaps-unknown-at-compile-time
set of data in an array (for example, you read stuff in from a file, and
don't know how many items you'll be reading, except that it is less than
N).  What most would do is store,
separately, the number of valid elements that are in the array.
However, if you want to do
so, you can also use the "sentinel" technique, and store a special value
as an "EOF flag"
in the array.  One example that immediately comes to mind is the arrays
that are null-terminated character strings (of which u**x is so fond).
One uses the null character,
which is otherwise not a printing character, as the array flag "That's
all, folks".

Bob Schor
Pascal Enthusiast



Wed, 18 Jun 1902 08:00:00 GMT  
 EOF

ok,  what i am doing is making a built in function that searchs for some data
in an array, and i am trying to make it real easy to use so i want to make it
so u don't have to pass the size in when calling the function.  So i want to do
it in the function so i thought to use an Eof on the array then count how many
times it goes thoru getting the size. and i wanted to know if i can do it
matty mtat



Wed, 18 Jun 1902 08:00:00 GMT  
 EOF

Quote:

> ok,  what i am doing is making a built in function that searchs for some data
> in an array, and i am trying to make it real easy to use so i want to make it
> so u don't have to pass the size in when calling the function.  So i want to do
> it in the function so i thought to use an Eof on the array then count how many
> times it goes thoru getting the size. and i wanted to know if i can do it
> matty mtat

As I understand this - you won't know the amount of data in your array
until after it has been loaded from a file. I seldom work with actual
arrays because of the restriction on a set size. Instead I create a list
of Pointers which can be traversed (often in both directions). The last
pointer in any direction is always nil and this serves as a handy
equivalent of an EOF marker.

I don't know if this is suitable for what you are doing but thought I
might as well pass the idea along. Good luck.

--
Val Mehling - anti-spam in effect.
For e-mail reply to:



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Problem with EOF

2. TTable skipping to EOF

3. EOF/BOF error in D5 with ADOExpress Update Pack 2

4. problem with ADODataSet.EOF

5. Delete & EOF on detail tables

6. EOF returns true before accessed last record (Delphi 1)

7. Speeding up interation within while not Eof loop

8. dbase request beyond eof ???

9. delete last record and eof()

10. EOF in TPW 1.5

11. GotoNearest is the EOF

12. prompted read in WHILE not eof loop

 

 
Powered by phpBB® Forum Software