home *** CD-ROM | disk | FTP | other *** search
/ TopWare 18: Liquid / Image.iso / liquid / top1143 / gepackt.exe / BSPQTSW.EXE / MINIDB.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-06-28  |  9.7 KB  |  399 lines

  1. (***************************************
  2. * WG-VISION 1.0   BEISPIELPROGRAMM     *
  3. ****************************************
  4. *                                      *
  5. * Mini-Adressdatenbank zur Demons-     *
  6. * tration von Eingabemasken aus        *
  7. * TInputLine-Objekten                  *
  8. *                                      *
  9. ****************************************
  10. * (c) 1993 Dipl.Phys. Mathias Scholz   *
  11. ***************************************)
  12.  
  13. {$I COMPILER.INC}
  14.  
  15. program Mini_Adressdatenbank;
  16.  
  17. uses WApp,
  18.      WEvent,
  19.      WDecl,
  20.      WViews,
  21.      WDriver,
  22.      WDlg,
  23.      WFileDlg,
  24.      WUtils,
  25.      WText,
  26.      Dos,
  27.      Graph;
  28.  
  29.  
  30. const cmOpen      = 101;
  31.       cmSave      = 102;
  32.       cmErfassen  = 201;
  33.       cmBlaettern = 202;
  34.       cmBrowse    = 203;
  35.  
  36.       cmLeft      = 90;   {zum Blättern innerhalb des Anzeige-Fenster}
  37.       cmRight     = 91;
  38.       cmSaveData  = 92;
  39.  
  40.       msgDraw     = 100;
  41.  
  42. type TApplication=object(TApp)
  43.        FName : PathStr;
  44.        procedure InitMenuBar; virtual;
  45.        procedure SetDialogData; virtual;
  46.        procedure HandleEvent; virtual;
  47.        procedure LoadFile;
  48.        procedure NewFile;
  49.        procedure BrowseWindow;
  50.        procedure Erfassen(Mode:boolean);
  51.      end;
  52.  
  53.      PNewScroller=^TNewScroller;
  54.  
  55.      PScrollWindow=^TScrollWindow;
  56.      TScrollWindow=object(TWindow)
  57.        Scroller:PNewScroller;
  58.        procedure InitWindowScroller; virtual;
  59.        procedure HandleEvent; virtual;
  60.        destructor Done; virtual;
  61.      end;
  62.  
  63.      TNewScroller=object(TScroller)
  64.        procedure CreateData;
  65.        procedure ScrollDraw; virtual;
  66.      end;
  67.  
  68.      PErfassen=^TErfassen;
  69.      TErfassen=object(TDlgWindow)
  70.       PosIndex:word;
  71.       constructor Init(DInput:boolean);
  72.       destructor Done; virtual;
  73.       procedure DeleteDataRecord;
  74.       procedure HandleEvent; virtual;
  75.      end;
  76.  
  77. {Datenrecord für Datei}
  78.  
  79.      tAdressData   =record
  80.                       Firma    : string[40];
  81.                       PLZ      : string[5];
  82.                       Ort      : string[25];
  83.                       Strasse  : string[30];
  84.                       Telefon  : string[15]
  85.                     end;
  86.  
  87. {Dialog-Record}
  88.  
  89.      tAdressDataRec=record
  90.                       Schalter : string[9];
  91.                       Adr      : tAdressData;
  92.                     end;
  93.  
  94.  
  95. var MyApp      : TApplication;
  96.     AdressData : tAdressDataRec;      {Dialogrecord}
  97.     Adresse    : tAdressData;         {Adressen-Record}
  98.     dat        : file of tAdressData; {Datenbank-Datei}
  99.  
  100.  
  101. {Implementation TApplication}
  102.  
  103. procedure TApplication.InitMenuBar;
  104. begin
  105.   MainMenu('~D~atei',0);
  106.    SubMenu('~A~dressen laden',cmOpen,0,0,false,false);
  107.    SubMenu('~N~eue Adreßdatei',cmSave,0,0,false,false);
  108.    NewLine;
  109.    SubMenu('E~x~it  Alt-X',cmCloseApplication,0,altX,false,false);
  110.   MainMenu('~B~earbeiten',0);
  111.    SubMenu('~A~dressen Erfassen',cmErfassen,0,0,true,false);
  112.    SubMenu('~B~lättern',cmBlaettern,0,0,true,false);
  113.    SubMenu('B~r~owse',cmBrowse,0,0,true,false);
  114. end;
  115.  
  116. procedure TApplication.SetDialogData;
  117. begin
  118.   with AdressData do
  119.    begin
  120.      Schalter:='TTTLLLLLS';
  121.      FillChar(Adr.Firma,SizeOf(Adr.Firma),' ');
  122.      FillChar(Adr.PLZ,SizeOf(Adr.PLZ),' ');
  123.      FillChar(Adr.Ort,SizeOf(Adr.Ort),' ');
  124.      FillChar(Adr.Strasse,SizeOf(Adr.Strasse),' ');
  125.      FillChar(Adr.Telefon,SizeOf(Adr.Telefon),' ');
  126.    end;
  127. end;
  128.  
  129. procedure TApplication.HandleEvent;
  130. var I:integer;
  131. begin
  132.   Heap^.ShowHeapStatus(523,8,White);
  133.   TProgram.HandleEvent;
  134.   case Event.Command of
  135.    cmOpen      : LoadFile;
  136.    cmSave      : NewFile;
  137.    cmErfassen  : Erfassen(true);
  138.    cmBlaettern : Erfassen(false);
  139.    cmBrowse    : BrowseWindow;
  140.   end; {case}
  141.   if Event.Message=msgLoadFile then
  142.    begin
  143.      FName:=Event.InfoString;
  144.      for I:=1 to 3 do MMenu[2]^.SbMenu[I]^.DeAktiviere;
  145.      ClearMessage;
  146.    end;
  147.   if Event.Message=msgSaveFile then
  148.    begin
  149.      if Pos('.',Event.InfoString)=0 then FName:=Event.InfoString+'.DBS'
  150.       else FName:=Event.InfoString;
  151.      MMenu[2]^.SbMenu[1]^.DeAktiviere;
  152.      ClearMessage;
  153.    end;
  154.   if WinAnz<>0 then
  155.    begin
  156.      MMenu[1]^.SbMenu[1]^.Aktiviere;
  157.      MMenu[1]^.SbMenu[2]^.Aktiviere;
  158.    end
  159.    else
  160.    begin
  161.      MMenu[1]^.SbMenu[1]^.DeAktiviere;
  162.      MMenu[1]^.SbMenu[2]^.DeAktiviere;
  163.    end;
  164. end;
  165.  
  166. procedure TApplication.LoadFile;
  167. var Window:PInputDialog;
  168. begin
  169.   Window:=New(PInputDialog, Init('Dateiauswahl','*.DBS'));
  170.   InsertDesktop(Window);
  171. end;
  172.  
  173. procedure TApplication.NewFile;
  174. var Window:POutputDialog;
  175. begin
  176.   Window:=New(POutputDialog, Init('Neue Adreß-Datei'));
  177.   InsertDesktop(Window);
  178. end;
  179.  
  180. procedure TApplication.BrowseWindow;
  181. var R:TRect;
  182.     Window:PScrollWindow;
  183. begin
  184.   R.Assign(20,60,616,446);
  185.   Window:=New(PScrollWindow, Init(R,'ScrollWindow / Quelltext-Lister',winDouble+winPanel+winMenu+winKey));
  186.   InsertDesktop(Window);
  187. end;
  188.  
  189. procedure TApplication.Erfassen(Mode:boolean);
  190. var Window:PErfassen;
  191.     I:integer;
  192. begin
  193.   Window:=New(PErfassen, Init(Mode));
  194.   InsertDesktop(Window);
  195.   for I:=1 to 3 do MMenu[2]^.SbMenu[I]^.DeAktiviere;
  196. end;
  197.  
  198. {Implementation TScrollWindow}
  199.  
  200. procedure TScrollWindow.InitWindowScroller;
  201. var R:TRect;
  202.     SBH1,SBV1:PScrollBar;
  203. begin
  204.   R:=Frame^.Area;
  205.   SBH1:=New(PScrollBar, Init(R,HorizDir));
  206.   SBV1:=New(PScrollBar, Init(R,VertDir));
  207.   Scroller:=New(PNewScroller, Init(R,SBH1,SBV1));
  208.   Scroller^.CreateData;
  209.   List^.InsertItem(Scroller);
  210. end;
  211.  
  212. procedure TScrollWindow.HandleEvent;
  213. begin
  214.   TWindow.HandleEvent;
  215.   if Event.Message=msgDraw then
  216.    begin
  217.      with Scroller^ do
  218.       begin
  219.         CreateData;
  220.         Draw;
  221.       end;
  222.      ClearMessage;
  223.    end;
  224. end;
  225.  
  226. destructor TScrollWindow.Done;
  227. begin
  228.   TWindow.Done;
  229.   Dispose(Scroller, Done);
  230. end;
  231.  
  232. {Implementation TNewScroller}
  233.  
  234. procedure TNewScroller.CreateData;
  235. var LfdPtr:PLine;
  236. begin
  237.   SetFont(Wndw19);
  238.   if Liste<>nil then Liste^.DeleteItems;
  239.   Assign(dat,MyApp.FName);
  240.   Reset(dat);
  241.   while not Eof(dat) do
  242.    begin
  243.      LfdPtr:=New(PLine, Init);
  244.      Read(dat,Adresse);
  245.      with Adresse do
  246.       LfdPtr^.Eintrag:=Firma+' │ '+PLZ+' │ '+Ort+' │ '+Strasse;
  247.      Liste^.InsertItem(LfdPtr);
  248.    end;
  249.   SetLimit(25,Liste^.AnzElem,8,16);
  250.   Close(dat);
  251. end;
  252.  
  253. procedure TNewScroller.ScrollDraw;
  254. var I:integer;
  255.     LfdPtr:PGroup;
  256.  
  257. function Clip(P,N:byte;z:string):string;
  258. begin
  259.   Clip:=Copy(z,P,N);
  260. end;
  261.  
  262. {------}
  263.  
  264. begin
  265.   SetFontColor(White,Blue);
  266.   Mouse.HideMouse;
  267.   with Border do
  268.    begin
  269.      SetFillStyle(SolidFill,GetPalColor(1));
  270.      SetColor(GetPalColor(2));
  271.      for I:=Delta.Y to WDelta.Y do
  272.       begin
  273.         LfdPtr:=Liste^.GetItems(I);
  274.         Bar(A.X,A.Y+(I-Delta.Y)*Py+10,B.X,A.Y+(I-Delta.Y)*Py+10+Py);
  275.         WriteText(A.X+20,A.Y+(I-Delta.Y)*Py+10,Clip(Delta.X,
  276.                   Spalten*8 div 8-5,PLine(LfdPtr)^.Eintrag));
  277.       end;
  278.      if VertiScrollBar<>nil then
  279.       for I:=(WDelta.Y-Delta.Y)+1 to Zeilen do
  280.        Bar(A.X,A.Y+I*Py+10,B.X,A.Y+I*Py+10+Py);
  281.    end;
  282.   Mouse.ShowMouse;
  283. end;
  284.  
  285. {Implementation Erfassen}
  286.  
  287. constructor TErfassen.Init(DInput:boolean);
  288. var RR:TRect;
  289. begin
  290.   PosIndex:=0;
  291.   RR.Assign(60,80,440,350);
  292.   Assign(dat,MyApp.FName);
  293.   {$I-}
  294.   Reset(dat);
  295.   {$I+}
  296.   if IOResult=0 then            {Existiert Datei ?}
  297.    begin
  298.      if not DInput then
  299.       begin
  300.         Read(dat,Adresse);
  301.         AdressData.Adr:=Adresse;
  302.         SetData(AdressData);
  303.       end
  304.       else
  305.       begin
  306.         DeleteDataRecord;
  307.         Seek(dat,FileSize(dat));
  308.       end;
  309.    end
  310.    else Rewrite(dat);
  311.   TDlgWindow.Init(RR,'Erfassen von Adressen',winDouble+winPanel);
  312.   SetPushButton(134,225,100,22,'OK',cmCloseWindow);
  313.   SetPushButton(260,225,40,22,'<<',cmLeft);
  314.    if DInput then SetDisabled;
  315.   SetPushButton(310,225,40,22,'>>',cmRight);
  316.    if DInput then SetDisabled;
  317.   SetInputLine(140,90,25,'~F~irma    :',40,ASCII);
  318.    if not DInput then SetDisabled;
  319.   SetInputLine(140,115,5,'~P~LZ      :',5,ZIFFERN);
  320.    if not DInput then SetDisabled;
  321.   SetInputLine(140,140,20,'~O~rt      :',25,ASCII);
  322.    if not DInput then SetDisabled;
  323.   SetInputLine(140,165,20,'~S~traße   :',30,ASCII);
  324.    if not DInput then SetDisabled;
  325.   SetInputLine(140,190,15,'~T~elefon  :',15,ZIFFERN);
  326.    if not DInput then SetDisabled;
  327.    if DInput then SetStaticText(40,35,'Adressenerfassung',LeftText)
  328.     else SetStaticText(40,35,'Blättern in der Datei',LeftText);
  329.    SetTextParameters(TriplexFont,HorizDir,2);
  330.    ChangePalColor(10,Red);
  331.   SetData(AdressData);
  332. end;
  333.  
  334. destructor TErfassen.Done;
  335. begin
  336.   Close(dat);
  337.   TDlgWindow.Done;
  338. end;
  339.  
  340. procedure TErfassen.DeleteDataRecord;
  341. begin
  342.   with AdressData do
  343.    begin
  344.      FillChar(Adr.Firma,SizeOf(Adr.Firma),' ');
  345.      FillChar(Adr.PLZ,SizeOf(Adr.PLZ),' ');
  346.      FillChar(Adr.Ort,SizeOf(Adr.Ort),' ');
  347.      FillChar(Adr.Strasse,SizeOf(Adr.Strasse),' ');
  348.      FillChar(Adr.Telefon,SizeOf(Adr.Telefon),' ');
  349.    end;
  350.   SetData(AdressData);
  351. end;
  352.  
  353. procedure TErfassen.HandleEvent;
  354.  
  355. procedure ReadDataRecord;
  356. begin
  357.   Seek(dat,PosIndex);
  358.   Read(dat,Adresse);
  359.   AdressData.Adr:=Adresse;
  360.   SetData(AdressData);
  361.   DrawMask;
  362.   Event.Command:=cmNothing;
  363. end;
  364.  
  365. {------}
  366.  
  367. begin
  368.   TDlgWindow.HandleEvent;
  369.   if Event.Message=msgNewMask then
  370.    begin
  371.      Adresse:=AdressData.Adr;
  372.      Write(dat,Adresse);
  373.      DeleteDataRecord;
  374.      DrawMask;
  375.      Event.Message:=msgDraw;    {Mitteilung an das Browse-Fenster}
  376.    end;
  377.   if Event.Command=cmRight then
  378.    if FilePos(dat)<FileSize(dat) then
  379.     begin
  380.       Inc(PosIndex);
  381.       ReadDataRecord;
  382.     end;
  383.   if Event.Command=cmLeft then
  384.    if PosIndex>0 then
  385.     begin
  386.       Dec(PosIndex);
  387.       ReadDataRecord;
  388.     end;
  389. end;
  390.  
  391. {Hauptprogramm}
  392.  
  393. begin
  394.   MyApp.Init('Adressen-Datenbank');
  395.   MyApp.Run;
  396.   MyApp.Done;
  397. end.
  398.  
  399.