unit Befund2B;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    GroupBox3: TGroupBox;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Panel1: TPanel;
    ScrollBar1: TScrollBar;
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ScrollBar1Change(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

const Max = 100;
      DateiName = 'Diagnose.txt';
var
  Form1: TForm1;
  Diagnose: Array[1..Max] of String;
  Nr, Anzahl: Integer; Datei: Text;


implementation

{$R *.DFM}

{Diagnosefeld leermachen}
Procedure ClearDiagnose;
Var i: Integer;
Begin
  For i := 1 to Max Do Diagnose[i] := '';
End;

{Diagnosetext laden, wenn vorhanden}
Procedure InitDiagnose;
Begin
  Anzahl := 0;
  If Not FileExists (DateiName) Then
  Begin
    Anzahl := 1; Diagnose[1] := 'Keine Sprechstunde'; Exit;
  End;
  AssignFile (Datei, DateiName);
  Reset (Datei);
  While Not (Eof (Datei)) And (Anzahl < Max) Do
  Begin
    Inc (Anzahl);
    Readln (Datei, Diagnose[Anzahl]);
  End;
  CloseFile (Datei);
End;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;
  ClearDiagnose;
  InitDiagnose;
  ScrollBar1.Min := 1;
  ScrollBar1.Max := Anzahl;
  Panel1.Caption := '';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Nr := Random (Anzahl) + 1;
  Panel1.Caption := Diagnose[Nr];
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := '';
  Edit1.SetFocus;
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  Panel1.Caption := Diagnose[ScrollBar1.Position]
end;

end.
