{------------------------------------------------------------------------------}
{
   Unit Name: ErrorCom
   Purpose  : To ask a comment text line to ErrorLog
   Author   : Vesa Lappalainen
   Date     : 26.7.1998
   Changed  :

   ToDo     :
}
{------------------------------------------------------------------------------}

unit ErrorCom;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, savepos;

type
  TFormErrorComment = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    SavePos1: TSavePos;
    ButtonDelete: TButton;
    PanelLabel: TPanel;
    LabelHelp: TLabel;
    PanelCB: TPanel;
    CBComment: TComboBox;
    Panel3: TPanel;
    ButtonOK: TButton;
    procedure ButtonDeleteClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


function GetComment(var s:string):boolean;
function AddComment : boolean;

implementation

uses kErrors;

{$R *.DFM}

var ceComment : TCommError;

function GetComment(var s:string):boolean;
var fe: TFormErrorComment;
  function GetString : boolean;
  begin
    fe.CBComment.Text := '';
    Result := false;
    try
      fe.CBComment.Items.LoadFromFile('Comments.txt');
    except
    end;
    if ( fe.ShowModal <> mrOK ) then exit;
    if ( fe.CBComment.Text = '' ) then exit;
    s := fe.CBComment.Text;
    Result := true;
    if ( fe.CBComment.Items.IndexOf(s) >= 0 ) then exit;
    fe.CBComment.Items.Insert(0,s);
    fe.CBComment.Items.SaveToFile('Comments.txt');
  end;
begin
  Result := false;
  fe :=  TFormErrorComment.Create(nil);
  if ( fe = nil ) then exit;
  Result := GetString;
  fe.Free;
end;

function AddComment : boolean;
var s:string;
begin
  Result := GetComment(s);
  if ( not Result ) then exit;
  ceComment.Add(s);
end;

procedure TFormErrorComment.ButtonDeleteClick(Sender: TObject);
var i:integer;
begin
  with CBComment do begin
    i := ItemIndex;
    if ( i >= 0 ) then begin
      Items.Delete(i);
      if ( i >= Items.Count ) then i := Items.Count-1;
      ItemIndex := i;
    end;
  end;
end;


initialization begin
//  ( sc : 'co'; expl : 'Comment'           ; err : False; show:false;log:true),
  RegisterError(ceComment,'co','Comment',false,false,true);
end;

end.
