                              7.

                            .

     ணࠬ  ᪠ ࠤ樮     ६  
ᮧ ,    ন   ,  ⠪ 
易 ᯨ᪨  ᪨ ᨢ.   ᢨ⥫쭮   
       ९뢠  ⫠ ᭮ 
᭮.
     ࠤ樮 ᪠  ᯥ稢  ⮫쪮 ஥  
ᨢ. ⠫    ࠧࠡ뢠 ᠬ.
     ਬ, ᫨    ᮡࠥ ࠭   ᨢ,  
室    ᮧ ᨢ, ஢ 
 ᨢ,  롮ન   ᨢ  ࠡ⪨ , ⭮, 
뢮     ன⢮  /.  ,         ணࠬ
ॡ  ⨯ ⮢ ᨢ,  筥  ᭠砫.
     뫮  ,  ᫨  ⨯ ᨢ 㯠    ,
 㤥 ࠡ뢠 設⢮ 権,    筮
ந  ᨢ,   ᫨   ⨯  ᨢ    뫮
   ਣ .
      ⮬ 祭 ⨯ TCollection  Turbo Vision.  ꥪ,
 ࠭    㪠⥫  ।⠢ ஥ ⮤
 樨 .


                        ꥪ 樨.

     ᪮   -    ꥪ  ,  ᫥⥫쭮,  
⮤, ஥  ,    2 ⥫  
 ࠢ      ᨢ   ᪠   -  ᪨  ࠧ  
䨧.


                       ᪨ ࠧ.

      ⠭  ᨢ Turbo Pascal 䨪  ६
樨     㤮,  ᫨    筮    ࠧ  襣
ᨢ,     ६  ࠡ  襩  ணࠬ      
   .     ࠧ   ᨢ   ॡ
   ४樨.
      樨  ⠭ ࢮ砫 ࠧ,    
 ᪨   㢥稢      ६   믮,  ⮡
ᮮ⢥⢮ , ࠭騬  .    ணࠬ
    ஢ .


                           䨧.

     ஥ ᢮⢮ ᨢ, ஥   ࠭祭 
襩 ணࠬ    ⮬,        ᨢ  
 ⨯   ⨯ ।  ६ 樨.
     樨 室    ࠭祭,  ᯮ ⨯஢
㪠⥫.    ⮫쪮      䥪⨢,      
樨 ᮤঠ  ꥪ  (   ꥪ) ࠧ ⨯ 
ࠧ஢.    ⮪,      祣    
ࠡ뢠 ꥪ.  ⮫쪮 ࠭   뤠  .


                    ஢ઠ ⨯  樨.

      室 ண ஢ ⨯ ࠤ樮 ᪠.
 砥,       - , 
 롨ࠥ   ⭮,    ஢ 
।   .       
ꥪ    ⭮   㣮        
 ।।   ⮬.
      ணࠬ    Turbo  Pascal,         뢠
। ᪮    ⮩ 樨.  ஢ઠ ⨯ ᪠,
஬ ᥣ 祣,  ࠭   ⫠  
㫮 訡.  蠩 ⥫쭮:    ᯮ
 㤭 宦 ⠪ 訡,  ᪮   
    !   ,  ᫨    ணࠬ  ᠥ,  ⥫쭮
஢ ⨯ ꥪ⮢, ࠭塞    権.


                      樨  ꥪ⮢.

        ⠪      ,   騥
ꥪ⠬,   ਢ  㣮 쥧  ஡.  樨
  ⨯஢ 㪠⥫  -.  
⮤ TCollection   ।祭        ࠡ⪨    権
஢, ஦    TObject.      ᥡ ⮤
㯠  ⮪ PutItem  GetItem,   ⠪  ⠭ 楤
FreeItem.
      砥,     ࠭ PString  樨, 
᫨   ⠥  ।     ⮪,   
㤮⢮⥫ १,  ᫨    ४஥  ⠭
⮤ GetItem  PutItem. 筮,   ⠥ ᢮
,  ᢮  , ᯮ FreeItem. ᫨
   ᯮ짮   樨   ⨯ TObject,  
室 ८।  ""    GetItem,  PutItem  
FreeItem.  TStringCollection, ਬ,   .
     ᫨  ࠡ⠥  ஦,      樨  (
ꥪ, ஦        権)    묨,      
ࠨ묨 ࠬ .


                         樨.

        ⠪   ,   । ⨯ ,
   ࠭. ।,   ⠭  
࠭   ᯮ짮  ⠡  ,        ⥫䮭
   ⮢.   砫  ।  ꥪ  
(TClient),  㤥 ࠭  樨:

     {  । 㪠⥫    ⨯ ꥪ}
     type
       PClient = ^TClient;
       TClient = object(TObject)
         Account, Name, Phone: PString;
         constructor Init(NewAccount, NewName, NewPhone: String);
         destructor Done; virtual;
       end;

     ⥬  ॠ ⮤ Init   Done    ।  
᢮    .   ⨬,      ꥪ  ⨯
PString, ⠪     ।  ⮫쪮    ᯮ㥬
 ப. 㭪樨 NewStr  DisposeStr ࠡ뢠 ᪨
ப 祭 䥪⨢.

     constructor TClient.Init(NewAccount, NewName, NewPhone:
                              String);
     begin
       Account := NewStr(NewAccount);
       Name := NewStr(NewName);
       Phone := NewStr(NewPhone);
     end;

     destructor TClient.Done;
     begin
       Dispose(Account);
       Dispose(Name);
       Dispose(Phone);
     end;

     TClient.Done 뢠  ⮬᪨    
㤠 ᥩ 樨.   ᮧ   ࠭
 ⮢    ⠢    ⮢   .   
ணࠬ:

     { TVGUID17.PAS }
     var
       ClientList: PCollection;

     begin
       ClientList := New(PCollection, Init(50, 10));
       with ClientList^ do
       begin
         Insert(New(PClient, Init('90-167', 'Smith, Zelda',
                '(800) 555-1212')));
         Insert(New(PClient, Init('90-160', 'Johnson, Agatha',
                '(302) 139-8913')));
         Insert(New(PClient, Init('90-177', 'Smitty, John',
                '(406) 987-4321')));
         Insert(New(PClient, Init('90-160', 'Anders Smitty',
                '(406) 111-2222')));
       end;
       PrintAll(ClientList);
       SearchPhone(ClientList, '(406)');
       Dispose(ClientList, Done);
     end.

           ᮧ   .      
।   TCollection   ClientList,   
砫 ࠧ 50 ⮢.  ᫨  ClientList ⠢  50
⮢,  ࠧ 㢥稢  蠣 10 ⮢.  2 ᫥
 ᮧ  ꥪ   ⠢   .
Dispose ᢮  .
        ਫ 樨,       㤥
࠭ -  ⮫쪮 । 㪠⥫.


                       樮 ⮤.

     ⠢  㤠    ⢥묨  ﬨ  
ﬨ.    横 for  室  ᥬ ꥪ⠬
樨    ⮡ࠦ         믮   
᫥.       室      ᫥
  樨,  㤮⢮騩  ।  ᫮.  
 楫         3  樮  ⮤:  ForEach,
FirstThat   LastThat.        ᯮ  㪠⥫   
楤  㭪  ⢥ ࠬ.


                          ForEach.

     ForEach  㪠⥫  楤.   楤    1
ࠬ -  㪠⥫  ,  ࠭騩  樨.  ForEach
뢠  楤 1  ࠧ        樨  
浪,   ஬        樨.  楤
PrintAll  TVGUID17 ਢ ਬ  ForEach.

     procedure PrintAll(C: PCollection);

       procedure PrintClient(P : PClient); far;
       begin
         with P^ do
           Writeln(Account^, '':20-Length(Account^),
                   Name^, '':20-Length(Name^),
                   Phone^, ''20-Length(Phone^));
       end;

     begin
       Writeln;
       Writeln;
       C^.ForEach(@PrintClient); { 뢠 PrintClient  
                                     }
     end;

         樨,  ।  ࠬ 
PrintAll, 뢠  楤  PrintClient.  PrintClient
 ⠥  ଠ  ꥪ       ଠ஢
.
      室   ஦   롨  楤,    
뢠  ࠬ.   ⮬ ਬ  PrintClient    
楤ன -      ⮤ ꥪ -    
쭮 (    )  ணࠬ,    뢠
.   ⠪        楤  
 ४⨢ far,     ४⨢    $F+.
, 楤  ᯮ짮  ࠬ - 㪠⥫ 
 樨.


                   LastThat  FirstThat.

            ਬ  楤    
 樨    室    ।  
樨   ᭮    .    
FirstThat  LastThat.  ᬠਢ   ⨢
ࠢ    ,     ,  ᮮ⢥騩
 㫥᪮ 㭪樨, ।  㬥.
     FirstThat   LastThat    㪠⥫      (
᫥) ,      ᮮ⢥   ᫮    ᪠.
ᬮਬ ।騩 ਬ ᯨ᪠ ⮢  ࠧ,   
 ᯮ        筮      .
    ,           Montana.
⮬  㤥 ᪠ ࢮ 宦        
406. 楤, 믮  :

     procedure SearchPhone(C: PClientCollection;
                           PhoneToFind: String);

       function PhoneMatch(Client: PClient): Boolean; far;
       begin
         PhoneMatch := Pos(PhoneToFind, Client^.Phone^) <> 0;
       end;

     var
       FoundClient: PClient;
     begin
       FoundClient := C^.FirstThat(@PhoneMatch);
       if FoundClient = nil then
         Writeln('No client met the search requirement')
       else
         with FoundClient^ do
           Writeln('Found client: ', Account^, ' ', Name^, ' ',
                   Phone^);
     end;

      ⨬,    PhoneMatch   ᯮ 
 맮.    㭪  頥  True  ⮫쪮  ᫨  
⥫䮭     蠡 ᪠ ᮢ.  ᫨  樨 
ꥪ, ᮮ⢥饣  ᪠,  頥  㪠⥫
nil.
     : ForEach    뢠     楤,     ।
짮⥫,   FirstThat   LastThat 뢠 㫥 㭪,
। 짮⥫.     । 㪠⥫
 ꥪ  樨.


                    ஢ 樨.

        室            ।
浪. Turbo   Vision  ᯥ稢  ᯥ樠  ⨯  樨,
     㯮冷        ᯮᮡ:
TSortedCollection.
     TSortedCollection ஦    TCollection     ⮬᪨
 砥  ꥪ.    ⠪   ⮬᪨ ஢
,                   ⢥࣠
㡫஢ .
     TSortedCollection -  ࠪ  ⨯.  ⮡  ᯮ짮
,   砫 ,   ⨯   㤥 
     ।  2   ⮤,   ᮮ⢥騥   ᯮᮡ
஢. ⮡   ᤥ  ,    㦭  த    ⨯
樨   TSortedCollection.    襬   砥      
TClientCollection.
      TClientCollection 㦥         ࠡ  
樥.     ⠢      ⮢   㤠
騥, ᪮   ᫥      ᭮      
TCollection.  室 ⮫쪮  TClientCollection, 
 ᯮ짮      ஢      ࠢ   
⮢   ।,        室  ।  㣨 
樨.   ,  ४뢠 ⮤  KeyOf    Compare  
ॠ    :

     PClientCollection = ^TClientCollection;
     TClientCollection = object(TSortedCollection)
       function KeyOf(Item: Pointer): Pointer; virtual;
       function Compare(Key1, Key2: Pointer): Integer; virtual;
     end;

     function TClientCollection.KeyOf(Item: Pointer): Pointer;
     begin
       KeyOf := PClient(Item)^.Name;
     end;

     function TClientCollection.Compare(Key1, Key2: Pointer):
                                        Integer;
     begin
     {室 ᯮ짮 ਢ ⨯  祩, ᪮
       - ⨯஢ 㪠⥫ }
       if PString(Key1)^ = PString(Key2)^ then
         Compare := 0
       else if PString(Key1)^ < PString(Key2)^ then
         Compare := -1
       else
         Compare := 1;
     end;

     KeyOf ।,         ᯮ짮
  ஢.   襬  砥  -      Name  .
Compare   2   ஢  ।    
 . Compare 頥 -1, 0  1 ᨬ  ⮣,
   Key1  ,  ࠢ      Key2.   ਬ
ᯮ 䠢 ஢ ப 祩.
     ⨬,     ᪮    ,   頥   KeyOf   
। Compare -  ⨯஢  㪠⥫,    室
믮 ਢ ⨯  PString  뫪  .
      ,          ।!   ,   ᫨   
८। ClientList   PClientCollection  PCollection
(   var    맮  New),    ᯥ⠥   
⮢  䠢⭮ 浪.


     { TVGUID18.PAS }
     var
       ClientList: PClientCollection;
     ...
     begin
       ClientList := New(PClientCollection, Init(50, 10));
       ...
     end;

            ᤥ  ᯥ  ᯨ᪠  ⮢,
஢  ࠬ,     .   室 
 ⮤ KeyOf    ACount   Name.


                         樨 ப.

      ணࠬ 室 ࠭  ஢  ப.
 ⮣   Turbo   Vision   ।⠢   ᯥ樠  
TStringCollection. ⨬,     TStringCollection  -  
ꥪ,  㪠⥫  ப Turbo Pascal.  ᪮ 
ப ᫥   TSortedCollection,  㡫஢  ப  
࠭.
     ᯮ짮 樨   ப   .        
६ 㪠⥫    ப.  । 樨,
 砫쭮 ࠧ  饭    ७  樨
।:

     { TVGUIDE19.PAS }
     var
       WordList: PCollection;
       WordRead: String;
       ...
     begin
       WordList := New(PStringCollection, Init(10, 5));
       ...


     WordList ࢮ砫쭮 ࠭ 10 ப,   ⥬ 㢥稢
 饭 5.  ,     -   ⠢  ப  
.   ⮬  ਬ  ᫮     ⥪⮢ 䠩 
⠢  :

     repeat
       ...
       if WordRead <> '' then
         WordList^.Insert(NewStr(WordRead));
         ...
     until WordRead = '';
     ...
     Dispose(WordList, Done);

     ⨬,   㭪  NewStr  ᯮ  ᮧ 
᫮, ஥ 뫮 ⠭,     ப  ।  
.   ᯮ  ,    ᥣ । 
ࠢ  ᮡࠥ묨 묨.  㤥 ⥫쭮 ᢮
,    ࠡ.  㤥 ᮮ⢥⢮ 맮
Dispose;   ᢮        樨,      ⥬
᢮ ᠬ  WordList.


                          .

     ⮤ ForEach 室  ᥩ  樨    ।  
   ।⠢    楤.  த  ।騩
ਬ, 楤  PrintWord  砥  㪠⥫    ⮡ࠦ
ப. ,      PrintWord      (   쭠)
楤. Print ᯮ  ⮤  ForEach    ।  
 樨  楤 PrintWord.

     procedure Print(C: PCollection);

     procedure PrintWord(P : PString); far;
     begin
       Writeln(P^);
     end;

     begin { Print }
       Writeln;
       Writeln;
       C^.ForEach(@PrintWord);
     end;


     맮 PrintWord   룫廊  ਢ筮.      楤,
   㪠⥫    ப    ।    祭  
Writeln. ⨬ ४⨢ far   PrintWord. PrintWord 
   ⮤  -        楤ன.   (楤
CallDraw   TVGUID20.PAS  뢠    맢  ⮤   맮
).  ⠪     楤ன.   
ᯮ짮   楤,  ⠪  PrintWord,  
    Print    쭥 楤ன.


                           .

     ஢ 樨  (  ᫥⥫쭮  樨 ப)
 ⮤ Search,   頥     
祬.        ஢ 樨?  
  ,   ਩ ᪠  砥 ? 筮
室 ᯮ짮 FirstThat  LastThat.   ।
㫥 㭪  㦭 ਥ ᪠  뢠 FirstThat.


                       樨.

      ,    樨    ࠭    ⨯  
᪨    ᮤঠ ⮤,  騥    䥪⨢
      樨.    ⢨⥫쭮  TCollection
। 23 ⮤.      ᯮ  樨    
ணࠬ,  㤨 ᪮  ࠡ.  ஥஢ 
ᯥ祭   ॠ  㤨 묨.
        㢨  ॠ    権:   
ࠡ뢠 䭮.    砥,        
, 祬    ࠭  ⨯ ꥪ  樨;   
࠭ ⢮  ࠧ  ⨯  ꥪ⮢        
娨 ꥪ⮢.
      ਬ,    ᬠਢ   ,  
樨 뫨    ⨯.    樨    ࠭  
ꥪ, ஦  TObject    ᢮  ᬥ訢 
ꥪ. 筮      室    ꥪ    ।
室⢮.
      ਬ ᬮਬ ணࠬ,   頥 3 ࠧ
᪨ ꥪ      .   ⥬        ForEach
ᯮ    室     樨    ⮡ࠦ  
ꥪ.
      ਬ  ᯮ   Graph  ࠩ BGI,  ⮬
 ६ 樨 GRAPH.TPU      ⥪饬  ࠢ筨
   ࠢ筨  㫥  (Options/Directories/Unit Directory).
 믮  ணࠬ  ३      ࠢ筨,   ᮤঠ騩
ࠩ .BGI    맮 InitGraph,  ⮡ 㪠 
ᯮ (ਬ C:\TP\BGI).
     砫 । ꥪ ࠪ⭮ ।.

     { TVGUID20.PAS }
     type
       PGraphObject = ^TGraphObject;
       TGraphObject = object(TObject)
         X,Y: Integer;
         constructor Init;
         procedure Draw; virtual;
       end;

        ⮣ ,    ᪨  ꥪ
 樠஢   (Init)    ⮡ࠦ    ᪮
࠭ (Draw).   । , 㦭  אַ㣮쭨,
᫥   饣 ।:

     PGraphPoint = ^TGraphPoint;
     TGraphPoint = object(TGraphObject)
       constructor Init;
       procedure Draw; virtual;
     end;

     PGraphCircle = ^TGraphCircle;
     TGraphCircle = object(TGraphObject)
       Radius: Integer;
       constructor Init;
       procedure Draw; virtual;
     end;

     PGraphRect = ^TGraphRect;
     TGraphRect = object(TGraphObject)
       Width, Height: Integer;
       constructor Init;
       procedure Draw; virtual;
     end;

      3 ꥪ ᫥  X  Y  PGraphObject,    
ࠧ ࠧ.  PGraphCircle    Radius,    PGraphRect
 Width  Height. 騩  ᮧ :

     ...
     List := New(PCollection, Init(10, 5));

     for I := 1 to 20 do
     begin
       case I mod 3 of
         0: P := New(PGraphPoint, Init);
         1: P := New(PGraphCircle, Init);
         2: P := New(PGraphRect, Init);
       end;
       List^.Insert(P);
     end;
     ...

       ,  横 for ⠢ 20 ᪨  ꥪ⮢  
 List.  ,    ,   ,    ꥪ 
List - -  ⨯   TGraphObject.  ᫥  ⮣,    
⠢  ,    ⮢ 㦭, 窠
 אַ㣮쭨.   䨧   㦭  ᪮쪮
  ᮤন    ꥪ     (Draw)  ॡ.
 ன    樨,  ᯮ  ⮤   
ꥪ ⮡ࠧ ᥡ ᠬ:

     procedure DrawAll(C: PCollection);

     procedure CallDraw(P : PGraphObject); far;
     begin
       P^.Draw;
     end;

     begin { DrawAll }
       C^.ForEach(@CallDraw);
     end;

     var
       GraphicsList: PCollection;
     begin
       ...
       DrawAll(GraphicsList);
       ...
     end.

      樨 ࠭  ࠧ,    易
ꥪ   ࠥ              ࠥ㣮  
ꥪ⭮-ਥ஢ ணࠬ஢.   ᫥饩    
㢨    ਭ樯  䨧   ࠢ ᯥ宬 ਬ 
⮪.


                  樨  ࠢ .

     TCollection    ᪨         ࢮ砫쭮
ࠧ, ⠭   Init    ᨬ쭮  ࠧ  16,380
⮢. ᨬ  ࠧ  樨  ࠭    ६
MaxCollectionSize Turbo  Vision.      ,      
   ,  ॡ ⮫쪮 4  ,  ᪮
 ࠭  㪠⥫.  ⥪  ᪨  
    㤥   ,   ᫨        ᯥ  ।⢮
㦥 訡.  ᫨  樠樨 樨  筮
,  頥 㪠⥫ nil. ᫨    
TCollection 筮 , 뢠 ⮤ TCollection.Error
     訡  ६  믮    .    
४ TCollection.Error,  ⮡ ᠬ  뤠  ᮮ饭  
訡  ॠ 堭 ⠭.
        ᮡ   ࠡ  訡  ,
᪮ 짮⥫      ணࠬ  Turbo  Vision  ࠧ
 ⥩,  祬  ࠤ樮 ணࠬ  ᪠. ᫨
짮⥫ ࠢ    ꥪ⮢   (ਬ
뢠       ࠭),    ᥣ  㤥  
।। 訡  .      ।ਭ 
蠣     짮⥫      ⠫쭮   訡   ६
믮   ᯮ ᮡ⢥ ஢ન   ࠡ 
樥,  ࠡ稪 訡 ६ 믮.

