Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic Array in free pascal
11-23-2009, 02:16 PM (This post was last modified: 11-23-2009 02:43 PM by codecaine.)
Post: #1
Dynamic Array in free pascal
This is a example of having a infinite size array. Just like a arraylist or list in which you see in java and c#

Click here to view source
Side note turbo pascal does not have a dynamic array function so you would have to created a linked list. To add to array without losing current data you just use SetLength(myarray,size) in fpc or delphi. A example of what a dynamic array in pascal would look like.

Code:
const   max= 512;
type     MyRecord = record
                S1: String;
                i1 : Integer;
           end;

            MyRecordPtr =^MyRecord;
            

var     RecordCount  :  Integer;
          MyRecordArray : array[1...max] of   MyRecordPtr;

procedure CreateNewRecord;
begin
       inc(recordCount)
       New(MyRecordArray[recordCount]);

end;


read Pointer:
      if MyRecordArray[i] = nil then writeln ('no data here')
                                       else
                                      writeln( 'data of S1:'  MyRecordArray[i]^ .S1);
Visit this user's website Find all posts by this user
Quote this message in a reply
11-23-2009, 09:21 PM
Post: #2
RE: Dynamic Array in free pascal
This is very good, and i like that they created this in Pascal, but it is far more better solution in C++ !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
11-24-2009, 12:14 AM
Post: #3
RE: Dynamic Array in free pascal
in 6 it will be the same as above but c++ has stl for this but most people create there own linklist in c++ also
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: