Determining an Array's Length in Pascal

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 1
Reputation: Scottie_uk is an unknown quantity at this point 
Solved Threads: 0
Scottie_uk Scottie_uk is offline Offline
Newbie Poster

Determining an Array's Length in Pascal

 
0
  #1
Sep 29th, 2006
I am a mainly Java and VB programmer. However, I am writing a program that generates computer code in various languages. One of these is Pascal.

What I am asking is simple.

To detemine the size of an array in Java and VB I would enter:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. anArray.length

What is the Pascal equivalent?? I have looked arround the web and found no info. Is there no such equivalent??

Thanks for your kind help

Andrew.
Last edited by Scottie_uk; Sep 29th, 2006 at 3:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 523
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: Determining an Array's Length in Pascal

 
0
  #2
Sep 30th, 2006
I've not used Delphi for a while but is it something like

Pascal and Delphi Syntax (Toggle Plain Text)
  1. Length(anArray)
Note to self... pocket cup
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 5
Reputation: codewritinfool is an unknown quantity at this point 
Solved Threads: 0
codewritinfool codewritinfool is offline Offline
Newbie Poster

Re: Determining an Array's Length in Pascal

 
0
  #3
Oct 8th, 2006
Originally Posted by Scottie_uk View Post
I am a mainly Java and VB programmer. However, I am writing a program that generates computer code in various languages. One of these is Pascal.

What I am asking is simple.

To detemine the size of an array in Java and VB I would enter:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. anArray.length
What is the Pascal equivalent?? I have looked arround the web and found no info. Is there no such equivalent??

Thanks for your kind help

Andrew.
Use Low() and High() to find the lowest element or highest element index, respectively, of an array.

code
Last edited by codewritinfool; Oct 8th, 2006 at 2:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 59
Reputation: needs_help is an unknown quantity at this point 
Solved Threads: 2
needs_help's Avatar
needs_help needs_help is offline Offline
Junior Poster in Training

Re: Determining an Array's Length in Pascal

 
0
  #4
Dec 31st, 2006
in pascal, you have to predefine all your variable types, including array lengths, so you should already know the length.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 5
Reputation: codewritinfool is an unknown quantity at this point 
Solved Threads: 0
codewritinfool codewritinfool is offline Offline
Newbie Poster

Re: Determining an Array's Length in Pascal

 
0
  #5
Dec 31st, 2006
Originally Posted by needs_help View Post
in pascal, you have to predefine all your variable types, including array lengths, so you should already know the length.
NOT TRUE. Free Pascal permits dynamic arrays defined like this:

Type
TByteArray : Array of Byte;
Var
A : TByteArray;

SetLength(A,1000);


After a call to SetLength, valid array indexes are 0 to 999: the array index is always zero-based.

Borland Object Pascal (Delphi) permits dynamic arrays defined like this:

var
byteArray : Array of Byte;

SetLength(byteArray, 5);



code
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 59
Reputation: needs_help is an unknown quantity at this point 
Solved Threads: 2
needs_help's Avatar
needs_help needs_help is offline Offline
Junior Poster in Training

Re: Determining an Array's Length in Pascal

 
0
  #6
Dec 31st, 2006
Ok, but in dev-pascal, you can't change the length.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 5
Reputation: codewritinfool is an unknown quantity at this point 
Solved Threads: 0
codewritinfool codewritinfool is offline Offline
Newbie Poster

Re: Determining an Array's Length in Pascal

 
0
  #7
Dec 31st, 2006
Originally Posted by needs_help View Post
Ok, but in dev-pascal, you can't change the length.
dev-pascal is an IDE, not a compiler. It commonly uses Free Pascal or GNU Pascal.

I've already shown how to do it in Free Pascal.

In GNU Pascal, you can use Schemata:

http://www.mirrorservice.org/sites/w...schemademo.pas
code
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC