From: broersma.juda_ANTISPAM_@tiscali.nl   
      
   Op Mon, 9 May 2005 11:12:51 +0200 schreef "Oliver Bleckmann"   
   :   
      
   >Hey there,   
   >I have a little question for you,   
   >how do I realise a progy, which stores an adressbook (name, city,   
   >phone,etc.) in alphabetical order?   
   >what record structur do i need (must be sortable) and how do i determin the   
   >end of that record,   
   >especially, when it is restored from a file (the eof thing, you know!)?   
   >   
   Hi there,   
      
   Well, after the 'Hello world' kind of programs, we all tend to make   
   something like this don't we.   
   It's good programming exercise !   
      
   You might make an array of records, sort them yourself before saving   
   to disk.   
      
   e.g.   
      
   type TAdrRec = Record {basic data structure of the adress record}   
    Name, City: String[80];   
    Phone: string[30];   
    end;   
    TAdrArray: Array[1..100] of TAdrRecord;   
    {for handling the records in memory}   
      
   var MyAdrArray: TAdrArray;   
    MyFile: File of TAdrRec; {for saving to file}   
    Index: Integer; {points to the current active AdressRecord}   
    LastRecord: Integer; {total nr. of records}   
      
   In the helpfiles take a look at   
   - records   
   - arrays   
   - typed files   
      
      
   In short:   
      
   Reading the file of records:   
      
    Assign(MyFile,'book.dat');   
    Index := 1;   
    while not eof(MyFile) do   
    begin   
    Read(MyFile,MyAdArray[Index]);   
    Index := index + 1;   
    end;   
    LastRecord := Index - 1;   
    Close(MyFile);   
      
   Saving to file:   
      
    Assign(MyFile,'book.dat');   
    for Index := 1 to LastRecord do   
    begin   
    Write(MyFile,MyAdrArray[Index]);   
    end;   
    Close(MyFile);   
      
   {All code from the top of my head, not tested, no guarantees ect...}   
      
   You'll need a sorting routine as well. (Google for shellsort,   
   bubblesort, quicksort)   
   And as you'r reading and writing to/from disk, you'll need IO   
   (Input/Output) error detecting and handling too ...   
      
   But first, keep it easy. Try to make a simple test program based on   
   the above suggestions. See if you can read and write to disk.   
   If you get the basics, the rest will come too.   
      
      
      
   A very different approach is to use some sort of database (dBase,   
   Paradox) en use index files for sorting, not that easy if your   
   programming language does not have database driver support built in...   
      
      
   Hope this helps a little.   
   Let me know if you have more questions.   
      
      
   Bart   
   --   
   Bart Broersma   
   broersma.juda_ANTISPAM_@tiscali.nl   
   (ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|