{ gzasob.pas Copyright (c) TrSek alias Zdeno Sekerak } { Implemantacia ZASOBNIKA } { - dynamicke pole so smernikmi na obsah } { } { Datum:17.04.2007 http://www.trsek.com } unit GZasob; interface CONST MaxPocet = 20; TYPE TVrchol = 0..MaxPocet; TIndex = 1..MaxPocet; TPrvok = record PolMenu: string; { polozka menu } end; TPrvky = array[TIndex] of TPrvok; TUdaje = record Vrchol : TVrchol; Prvky : TPrvky; end; PUdaje = ^TUdaje; TZasobnik = PUdaje; cMenuList = object Zasobnik : TZasobnik; Highlight : integer; { tato polozka bude zvyraznena } constructor Init; destructor Done; virtual; function Mohutnost: integer; { zisti pocet zaznamov } function JePrazdna: boolean; { urci ci je zoznam prazdny } { zobrazovace } procedure SetHighlight( ihigh: integer ); { cislo polozky ktoru chcem zvyraznovat } procedure UkazPolozku; procedure MainMenu; { pridavace, mazace } procedure Pridaj (line: string); { prida novy prvok } procedure Vyber (var line: string); { vyberie prvok } End; implementation uses crt; { vytvorime zasobnik } constructor cMenuList.Init; begin New( Zasobnik ); { chyba nieje dost pamete } if( Zasobnik = nil )then begin writeln('Problem pri alokacii pamete'); halt(1); end; Zasobnik^.Vrchol:=0; end; { zrusime alokovanu pamat } destructor cMenuList.Done; begin Dispose( Zasobnik ); end; { zisti pocet zaznamov } function cMenuList.Mohutnost: integer; begin Mohutnost := Zasobnik^.Vrchol; end; { urci ci je zoznam prazdny } function cMenuList.JePrazdna: boolean; begin if( Zasobnik^.Vrchol = 0 )then JePrazdna := true else JePrazdna := false; end; { prida do zasobnika dalsi prvok } procedure cMenuList.Pridaj (line: string); begin with Zasobnik^ do begin { este nieje plny - mozem } if( Vrchol < MaxPocet )then begin Inc(Vrchol); Prvky[Vrchol].PolMenu:=line; end; end; end; { vyberie zo zasobnika prvok } procedure cMenuList.Vyber (var line: string); var i:integer; begin { este tam nieco je } if( not( JePrazdna ))then begin with Zasobnik^ do begin line := Prvky[1].PolMenu; Dec(Vrchol); { ostatne posuniem } for i:=1 to Vrchol do Prvky[i] := Prvky[i+1]; end; end; end; { zvyrazni polozku } procedure cMenuList.SetHighlight( ihigh: integer ); begin { len pre existujuce polozky } if(( ihigh > 0 ) and ( ihigh <= Zasobnik^.Vrchol ))then Highlight := ihigh; end; { zobrazi hlavne menu } procedure cMenuList.MainMenu; begin textcolor(white); textbackground(black); writeln(' Menu'); writeln(' ----'); writeln; end; { zobrazi polozku } procedure cMenuList.UkazPolozku; var line: string; begin { zvyraznovat text alebo nie } if( Zasobnik^.Vrchol = Highlight )then textbackground( Green ) else textbackground( Black ); Vyber( line ); writeln( line ); textbackground( black ); end; begin end.