home *** CD-ROM | disk | FTP | other *** search
- PROGRAM vin;
-
- (*****************************************************************************
- Name: VIN
- Version: 1.0
- Edit Datum: 1. April 1992
- Autor: Andreas Schumm
- Kurzbeschreibung: Beispielprogramm WEIN
- *****************************************************************************)
-
- USES API, Kernel, Dialogs;
-
- CONST ProjektName = 'vin';
- MaxFarben = 3;
-
- Farben : array[1..MaxFarben] of string[8] =
- (( 'rot'),('rosé'),('weiß'));
-
- MuellIcon : Array[0..143] of Byte = (
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 15, 192, 0,
- 0, 16, 32, 0,
- 7, 240, 63, 128,
- 8, 0, 0, 64,
- 15, 255,255, 192,
- 4, 0, 0, 128,
- 4, 0, 0, 128,
- 4, 136, 136, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 68, 68, 128,
- 4, 136, 136, 128,
- 4, 0, 0, 128,
- 4, 0, 0, 128,
- 7, 255, 255, 128,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0);
-
-
- TYPE WeinString = String[39];
- Weintyp = record
- Titel : WeinString;
- Jahrgang : integer;
- Farbe : String[8];
- Geschmack: (trocken, staubig, suess, klebrig);
- Anzahl : integer;
- end;
-
- VAR LaunchResult : integer;
- MyEvent : EventTyp;
- Terminated : boolean;
- CurrentKat : String[39];
- CurrentFile : string;
- f : file of Weintyp;
- FarbIndex : integer;
-
-
- procedure DeleteWine(name:string);
- var f,g: file of WeinTyp;
- w : WeinTyp;
- begin
- assign(f,CurrentFile+'.OLD');
- {$i- }
- erase(f);
- assign(f,CurrentFile+'.VIN');
- rename(f,CurrentFile+'.OLD');
- assign(g,CurrentFile+'.VIN');
- rewrite(g);
- reset(f);
- repeat
- read(f,w);
- if w.Titel <> name then
- write(g,w);
- until eof(f);
- close(f);
- close(g);
- {$i+ }
- end;
-
- function LoadWine(name: string; var Wine: WeinTyp):boolean;
- var f : file of WeinTyp;
- begin
- LoadWine := false;
- assign(f,CurrentFile+'.VIN');
- {$i- }
- reset(f);
- if ioresult = 0 then
- begin
- repeat
- read(f,Wine);
- until eof(f) or (Wine.titel = name);
- close(f);
- if Wine.titel = name then LoadWine := true;
- end;
- end;
-
- procedure SaveWine(var Wine: WeinTyp);
- var f : file of WeinTyp;
- Scratch : WeinTyp;
- begin
- if LoadWine(Wine.Titel, Scratch) then DeleteWine(Wine.Titel);
- assign(f,CurrentFile+'.VIN');
- {$i- }
- reset(f);
- if ioresult <> 0 then rewrite(f)
- else seek(f,filesize(f)); { ans Ende }
- write(f,Wine);
- close(f);
- {$i+ }
- end;
-
-
- { **** Callbackprozeduren zum Lesen der Kategorien aus der Ini-Datei **** }
-
- procedure GetFirstKat(var name: ListString; var eol: boolean); far;
- var theline: string;
- begin
- eol := not GetInitFileListFirst('vin','Kategorie',theline);
- if not eol then GetParaString(theline,name);
- end;
-
- procedure GetNextKat(var name: ListString; var eol: boolean); far;
- var theline: string;
- begin
- eol := not GetInitFileListNext('Kategorie',theline);
- if not eol then GetParaString(theline,name);
- end;
-
- function GetWineFileName(name: ListString):string;
- var result : string;
- theline : string;
- thename : string;
- ready : boolean;
- begin
- GetWineFileName := '';
- ready := false;
- if GetInitFileListFirst('vin','Kategorie',theline) then
- repeat
- GetParaString(theline, thename);
- if name = thename then
- begin
- ready := true;
- GetParaName(theline, result); GetWineFileName := result;
- end;
- if not ready then ready := not GetInitFileListNext('Kategorie',theline);
- until ready;
- end;
-
- { **** Callback-Prozeduren zum Einlesen der Weine **** }
-
- procedure GetNextWine(var name: ListString; var eol: boolean); far;
- var MyWine: WeinTyp;
- begin
- eol := true;
- {$i- }
- read(f,MyWine);
- {$i+ }
- if ioresult = 0 then
- begin
- eol := false;
- name := MyWine.Titel;
- end
- else close(f);
- end;
-
- procedure GetFirstWine(var name: ListString; var eol: boolean); far;
- begin
- eol := true;
- if CurrentFile <> '' then
- begin
- assign(f,CurrentFile+'.VIN');
- {$i- *}
- reset(f);
- {$i+ }
- if ioresult = 0 then GetNextWine(name, eol);
- end;
- end;
-
-
- { **** Callback-Prozeduren zum Einlesen der Farbe *** }
-
- procedure GetNextColor(var name: ListString; var eol: boolean); far;
- begin
- if FarbIndex > MaxFarben then eol := true
- else
- begin
- eol := false;
- name := Farben[FarbIndex];
- inc(FarbIndex);
- end;
- end;
-
- procedure GetFirstColor(var name: ListString; var eol: boolean); far;
- begin
- FarbIndex := 1;
- GetNextColor(name,eol);
- end;
-
-
- procedure DialogProc1(TheEvent: EventTyp); far;
- var MYDLG : PDialog;
- MyEditor : PEditField;
- MyListBox : PListBox;
- MyCombo : PComboBox;
- MyRadios : PRadioButtons;
- error : integer;
- MyWein : WeinTyp;
- begin
- MYDLG := TheEvent.DlgAdr; { Adresse des Dialoges }
- if TheEvent.Class = DIALOGEVENT then With TheEvent do
- Case MSG of
- DLG_BUTTON : if ID = 199 then { löschen }
- begin
- MyEditor := MYDLG^.FindDlgItem(102);
- if MyEditor^.GetString <> '' then DeleteWine(MyEditor^.GetString);
- MyListBox := MYDLG^.FindDlgItem(103);
- MyListBox^.Update;
- end
- else if ID = 1 then
-
- begin { OK gedrückt, jetzt Plausibilität prüfen ! }
- error := 0;
- MyEditor := MYDLG^.FindDlgItem(102);
- if MyEditor^.GetString = '' then error := 102;
- MyEditor := MYDLG^.FindDlgItem(104);
- if not MyEditor^.IsInteger then error := 104;
- if MyEditor^.IsInteger and ((MyEditor^.GetValue < 1900) or (MyEditor^.GetValue > 2100))
- then error := 104;
- MyEditor := MYDLG^.FindDlgItem(107);
- if not MyEditor^.IsInteger then error := 107;
- if MyEditor^.IsInteger and (MyEditor^.GetValue < 0) then
- error := 107;
- if error <> 0 then MYDLG^.SetTheFocus(error)
- else
- begin
- MyEditor := MyDLG^.FindDlgItem(102); { Name lesen }
- MyWein.Titel := MyEditor^.GetString;
- MyEditor := MyDLG^.FindDlgItem(104); { Jahrgang lesen }
- MyWein.Jahrgang := MyEditor^.GetValue;
- MyEditor := MyDLG^.FindDlgItem(107);
- MyWein.Anzahl := MyEditor^.GetValue;
- MyRadios := MyDLG^.FindDlgItem(105); { Geschmack lesen }
- Case MyRadios^.WhosChecked of
- 111 : MyWein.Geschmack := staubig;
- 112 : MyWein.Geschmack := trocken;
- 113 : MyWein.Geschmack := suess;
- 114 : MyWein.Geschmack := klebrig;
- end;
- MyCombo := MyDLG^.FindDlgItem(106);
- MyWein.Farbe := MyCombo^.GetSelected;
- SaveWine(MyWein);
- MyListBox := MYDLG^.FindDlgItem(103);
- MyListBox^.Update;
- end;
- end;
-
- DLG_CANCEL : begin
- MYDLG^.flags := MYDLG^.flags or MF_CANCELLED;
- MYDLG^.DestroyDialog;
- end;
-
- DLG_COMBOSELECT : if ID = 101 then { Kategorie geändert }
- begin
- MyCombo := MyDLG^.FindDlgItem(101);
- CurrentKat := MyCombo^.GetSelected;
- CurrentFile := GetWineFileName(CurrentKat);
- MyListBox := MyDlg^.FindDlgItem(103);
- MyListBox^.Update;
- MyEditor := MYDLG^.FindDlgItem(102);
- MYEditor^.SetString('');
- MSG := DLG_LISTMOVED;
- DialogProc1(TheEvent); { rekursiver Aufruf }
- end;
-
- DLG_LISTSELECT,
- DLG_LISTMOVED : begin
- MyListBox := MyDLG^.FindDlgItem(103);
- if LoadWine(MyListBox^.GetMarked, MyWein) then
- begin
- MyEditor := MyDLG^.FindDlgItem(102);
- MyEditor^.SetString(MyWein.Titel);
- MyEditor := MyDLG^.FindDlgItem(104); { Jahrgang }
- MyEditor^.SetValue(MyWein.Jahrgang);
- MyEditor := MyDLG^.FindDlgItem(107); { Anzahl }
- MyEditor^.SetValue(MyWein.Anzahl);
- MyRadios := MyDLG^.FindDlgItem(105); { Geschmack }
- Case MyWein.Geschmack of
- staubig : MyRadios^.CheckButton(111);
- trocken : MyRadios^.CheckButton(112);
- suess : MyRadios^.CheckButton(113);
- klebrig : MyRadios^.CheckButton(114);
- end;
- MyCombo := MyDLG^.FindDlgItem(106);
- MyCombo^.Select(MyWein.Farbe);
- end;
- end;
- end;
- end;
-
-
- procedure Verwaltung;
- var MyDialog : Dialog;
- MyEditor : PEditField;
- MyLabel : PLabelText;
- MyCombo : PComboBox;
- MyListBox : PListBox;
- MyChecker : PCheckBox;
- MyRadios : PRadioButtons;
- MyButton : PButton;
- MyUserButton : PUserButton;
- MyWine : Weintyp;
- begin
- MyDialog.Init(55*FontX, 16*FontY, MF_CAPTION, DialogProc1);
- MyDialog.SetCaption('in vino veritas');
- MyDialog.SetTopic('Wein');
-
- new(MyCombo, Init(FontX, 2*FontY, 27,8, 101, GetFirstKat, GetNextKat));
- MyDialog.AddItem(MyCombo);
-
- CurrentKat := MyCombo^.GetSelected;
- CurrentFile := GetWineFileName(CurrentKat);
-
- new(MyLabel, Init(FontX, FontY,0,'Kategorie:'));
- MyDialog.AddItem(MyLabel);
-
- new(MyLabel, Init(FontX, 4*FontY,0,'Bezeichnung:'));
- MyDialog.AddItem(MyLabel);
-
- new(MyEditor, Init(FontX, 5*FontY,29,39,102,''));
- MyDialog.AddItem(MyEditor);
-
- new(MyListBox, Init(FontX, 7*FontY, 19,8, 103, GetFirstWine, GetNextWine));
- MyDialog.AddItem(MyListBox);
-
- new(MyLabel, Init(23*FontX, 7*FontY,0,'Jahr:'));
- MyDialog.AddItem(MyLabel);
- new(MyEditor, Init(23*FontX, 8*FontY,5,4,104,''));
- MyDialog.AddItem(MyEditor);
-
- new(MyLabel, Init(32*FontX, 7*FontY,0,'Anzahl:'));
- MyDialog.AddItem(MyLabel);
- new(MyEditor, Init(32*FontX, 8*FontY,5,4,107,'0'));
- MyDialog.AddItem(MyEditor);
-
- new(MyRadios, Init(23*FontX,11*FontY,22*FontX,4*FontY-8,105,'Geschmack',
- new(PRadioButton, Init(FontX,FontY,111,'staubig',
- new(PRadioButton, Init(FontX,2*FontY,112,'trocken',
- new(PRadioButton, Init(11*FontX,FontY,113,'süß',
- new(PRadioButton, Init(11*FontX,2*FontY,114,'klebrig',nil))))))))));
- MyDialog.AddItem(MyRadios);
- MyRadios^.Checkbutton(111);
-
- new(MyCombo,Init(41*FontX,8*FontY,6,3,106,GetFirstColor,GetNextColor));
- MyDialog.AddItem(MyCombo);
- new(MyLabel,Init(41*FontX,7*FontY,0,'Farbe:'));
- MyDialog.AddItem(MyLabel);
-
- new(MyButton, Init(40*FontX,FontY, 14*FontX, 2*FontY-8, 1,'Speichern'));
- MyDialog.AddItem(MyButton);
-
- new(MyButton, Init(40*FontX,3*FontY,14*FontX, 2*FontY-8, 2,'Abbruch'));
- MyDialog.AddItem(MyButton);
- MyButton^.MakeCancelItem;
-
- new(MyUserButton, Init(33*FontX,FontY,6*FontX,4*FontY-8,29,35,199,'D',@MuellIcon));
- MyDialog.AddItem(MyUserButton);
-
- MyDialog.Show;
- MyDialog.DoDialog;
- MyDialog.Done;
- end;
-
-
- PROCEDURE HandleMsg(MyMessage: EventTyp); far;
- Begin
- With MyMessage Do
- Case Class Of
- Menu : begin
- Case MenuItemID of
- 0 : Terminated := true; { Programm beenden }
- 101 : Verwaltung;
- end;
- end;
- end; { Case Class }
- End;
-
-
- Begin
- Terminated := false;
- DebugOn;
- LaunchResult := OpenMainApplication(HandleMsg,
- APP_NOFONT+APP_NOHELP,
- ProjektName);
-
- If LaunchResult = 0 then
- begin
- repeat
- GetEvent(MyEvent);
- DispatchMessage(MyEvent);
- until Terminated;
- CloseMainApplication;
- end
- Else
- Writeln('Programm kann nicht gestartet werden. Fehler: ',LaunchResult);
- End.