home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / OOPTUT34.ZIP / OBCOMPAT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-14  |  6KB  |  243 lines

  1. {$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,R-,S+,V+,X-}
  2. {$M 16384,0,6000}
  3. program object_compatability;
  4.  
  5. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  6. { Program to show dynamic objects and to illustrate the compatability    }
  7. { of descendant objects with ancestors. A simple database situation is   }
  8. { created with Surname and Forenames having a descendant, Address, which }
  9. { in turn has a descendant, Phone. As in the Borland program, LISTDEMO,  }
  10. { a Node record is created on the Heap and this points to the data item  }
  11. { and to the next Node record.                                           }
  12. { The program uses the Exec procedure to call DOS Debug to inspect the   }
  13. { data on the Heap.                                                      }
  14. {                                                                        }
  15. { OBCOMPAT.PAS  ->  .EXE      R Shaw      2.11.92   and  22.11.92        }
  16. {________________________________________________________________________}
  17.  
  18. uses Dos, Crt, Hexa;
  19.  
  20. type
  21.    Str10 = string[10];
  22.    Str15 = string[15];
  23.    Str20 = string[20];
  24.    Str30 = string[30];
  25.    Str40 = string[40];
  26.  
  27.    PName = ^TName;
  28.    TName = object
  29.      Surname   : str20;
  30.      Forenames : str40;
  31.      Constructor Init(SName: str20; Fnames: str40);
  32.      Destructor Done; virtual;
  33.    end;
  34.  
  35.    PAddress = ^TAddress;
  36.    TAddress = object(TName)
  37.      Street   : str30;
  38.      Town     : str20;
  39.      County   : str20;
  40.      PostCode : str10;
  41.      Constructor Init(St: str30; T: str20; C: str20; Code: str10);
  42.    end;
  43.  
  44.    PPhone = ^TPhone;
  45.    TPhone = object(TAddress)
  46.      Number   : string[15];
  47.      Constructor Init(Num: str15);
  48.    end;
  49.  
  50.    PNode = ^TNode;
  51.    TNode = record
  52.      Item: PName;
  53.      Next: PNode;
  54.    end;
  55.  
  56.    PList = ^TList;
  57.    TList = object
  58.      Nodes: PNode;
  59.      constructor Init;
  60.      destructor Done; virtual;
  61.      procedure Add(Item: PName);
  62.    end;
  63.  
  64. var
  65.    HeapTop           : ^integer;
  66.    SegHeap, OfsHeap  : word;
  67.    SegHeapX,OfsHeapX : string;
  68.    i                 : integer;
  69.    ContactList       : TList;
  70.    NamePtr           : PName;
  71.    AddressPtr        : PAddress;
  72.    PhonePtr          : PPhone;
  73.    choice            : integer;
  74.    Code              : Str10;
  75.    Num               : Str15;
  76.    SName,T,C         : Str20;
  77.    FNames            : Str40;
  78.    St                : Str30;
  79.    reply             : char;
  80.  
  81. procedure InitData;
  82. begin
  83.    Code   := '';
  84.    Num    := '';
  85.    Sname  := '';
  86.    Fnames := '';
  87.    T      := '';
  88.    C      := '';
  89.    St     := '';
  90. end;
  91.  
  92. Constructor TName.Init(SName: str20; Fnames: str40);
  93. begin
  94.    Surname := SName;
  95.    Forenames := FNames;
  96. end;
  97.  
  98. Constructor TAddress.Init(St: str30; T: str20; C: str20; Code: str10);
  99. begin
  100.    TName.Init(SName,FNames);
  101.    Street   := St;
  102.    Town     := T;
  103.    County   := C;
  104.    PostCode := Code;
  105. end;
  106.  
  107. Constructor TPhone.Init(Num: str15);
  108. begin
  109.    TAddress.Init(St,T,C,Code);
  110.    Number := Num;
  111. end;
  112.  
  113. {--------------------------------------------------------}
  114. { TList's method implementations:                        }
  115. {--------------------------------------------------------}
  116.  
  117. constructor TList.Init;
  118. begin
  119.   Nodes := nil;
  120. end;
  121.  
  122. destructor TName.Done;
  123. begin
  124. end;
  125.  
  126. destructor TList.Done;
  127. var
  128.   N: PNode;
  129. begin
  130.   while Nodes <> nil do
  131.   begin
  132.     N := Nodes;
  133.     Nodes := N^.Next;
  134.     Dispose(N^.Item, Done);
  135.     Dispose(N);
  136.   end;
  137. end;
  138.  
  139. procedure TList.Add(Item: PName);
  140. var
  141.   N: PNode;
  142. begin
  143.   New(N);
  144.   N^.Item := Item;
  145.   N^.Next := Nodes;
  146.   Nodes := N;
  147. end;
  148.  
  149.  
  150. Function DebugPath : Pathstr;
  151.  
  152. var
  153.   DPath : PathStr;
  154.  
  155. begin
  156.   DPath := '';
  157.   DPath := FSearch('DEBUG.EXE', GetEnv('PATH'));
  158.   If DPath = '' then DPath := FSearch('DEBUG.COM', GetEnv('PATH'));
  159.   If DPath = '' then
  160.      begin
  161.         writeln('DEBUG file not found. Please check your DOS system.');
  162.         writeln;
  163.         writeln('Press any key to continue: ');
  164.         repeat until keypressed;
  165.      end;
  166.   DebugPath := DPath;
  167. end;      {of Function DebugPath}
  168.  
  169.  
  170. {Main}
  171.  
  172. begin
  173.    ClrScr;
  174.    Mark(HeapTop);
  175.    SegHeap := Seg(HeapTop^);
  176.    OfsHeap := Ofs(HeapTop^);
  177.    SegHeapX := IntToHex(SegHeap);
  178.    OfsHeapX := IntToHex(OfsHeap);
  179.    For i := OfsHeap to (OfsHeap + 1000) do Mem[SegHeap:i] := 0;
  180.    ContactList.Init;
  181.    Repeat
  182.    InitData;
  183.    writeln;
  184.    writeln('Please indicate type of entry by pressing the appropriate number key: ');
  185.    writeln;
  186.    writeln('   1  Names only');
  187.    writeln('   2  Names and address');
  188.    writeln('   3  Names and address and phone number');
  189.    writeln;
  190.    write('Please select now: ');
  191.    repeat
  192.      readln(choice);
  193.    until choice in [1..3];
  194.    writeln;
  195.    write('Surname: ');
  196.    readln(SName);
  197.    write('Forenames: ');
  198.    readln(FNames);
  199.    writeln;
  200.    if choice = 1 then
  201.       begin
  202.         NamePtr := New(PName,Init(SName,FNames));
  203.         ContactList.Add(NamePtr);
  204.       end;
  205.    if (choice = 2) or (choice = 3) then
  206.       begin
  207.         write('Street: ');
  208.         readln(St);
  209.         write('Town: ');
  210.         readln(T);
  211.         write('County: ');
  212.         readln(C);
  213.         write('Code: ');
  214.         readln(Code);
  215.       end;
  216.    if choice = 2 then
  217.       begin
  218.         AddressPtr := New(PAddress,Init(St,T,C,Code));
  219.         ContactList.Add(AddressPtr);
  220.       end;
  221.    if choice = 3 then
  222.       begin
  223.         write('Phone Number: ');
  224.         readln(Num);
  225.         PhonePtr := New(PPhone,Init(Num));
  226.         ContactList.Add(PhonePtr);
  227.       end;
  228.    writeln;
  229.    write('Press C to continue or Q to quit: ');
  230.    reply := readkey;
  231.    until UpCase(reply) = 'Q';
  232.    writeln;
  233.    writeln('HeapTop address is ',SegHeapX,':',OfsHeapX);
  234.    writeln;
  235.    writeln('DOS Debug now entered from program by means of Exec procedure.');
  236.    writeln('Please type D followed by a space and then the HeapOrg address, as above.');
  237.    writeln('Then continue to type D until end of collection. Then type Q.');
  238.    SwapVectors;
  239.    Exec(DebugPath,'');
  240.    If DosError <> 0 then writeln('Dos error # ',DosError);
  241.    SwapVectors;
  242.    ContactList.Done;
  243. end.