unit TextBufWin;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, TextEditor;

type
  TTextBufFrm = class(TForm)
    teBuffer: TTextEditor;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    FBufferName: string;
  public
    constructor Create(AOwner: TComponent;
      const ABufferName, ABufferText: string); reintroduce;
    property BufferName: string read FBufferName;
    procedure AddLine(const AText: string);
  end;

var
  TextBufFrm: TTextBufFrm;

implementation

uses
  MainForm, FormFader, WinMgrForm;

{$R *.dfm}

procedure TTextBufFrm.AddLine(const AText: string);
begin
  teBuffer.EditMode := emText;
  try
    teBuffer.AddLine(AText);
  finally
    teBuffer.EditMode := emReadOnly;
  end;
end;

constructor TTextBufFrm.Create(AOwner: TComponent;
  const ABufferName, ABufferText: string);
begin
  inherited Create(AOwner);
  FBufferName := ABufferName;
  Caption := ABufferName;
  teBuffer.PlainText := ABufferText.TrimRight;
  teBuffer.TextFile.GotoEOF;
  TFormFader.Create(Self);
  TWindowWatcher.Create(Self);
end;

procedure TTextBufFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  AlgosimMainForm.TextBufferWnds.Remove(FBufferName);
  Action := caFree;
end;

end.
