unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
PageCtrl: TPageControl;
btnNew: TButton;
btnDelete: TButton;
edtText: TEdit;
procedure btnNewClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure edtTextKeyPress(Sender: TObject;
var Key: Char);
private
{ Private-Deklarationen }
function NewTabSheet(pc : TPageControl; aCaption : TCaption) : TTabSheet;
function DeleteTabSheet(pc : TPageControl) : Boolean;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
function TForm1.NewTabSheet(pc: TPageControl; aCaption : TCaption): TTabSheet;
var
Panel : TPanel;
RichEdit : TRichEdit;
begin
Result:=TTabSheet.Create(Self);
Result.Parent:=pc;
Result.PageControl:=pc;
Result.Caption:=aCaption;
Panel:=TPanel.Create(Result);
Panel.Parent:=Result;
Panel.Align:=alClient;
Panel.BevelInner:=bvNone;
Panel.BevelOuter:=bvNone;
Panel.BorderWidth:=2;
RichEdit:=TRichEdit.Create(Result);
RichEdit.Parent:=Panel;
RichEdit.Align:=alClient;
Result.Tag:=Integer(RichEdit);
// Hier Zeiger auf TRichEdit merken.
end;
procedure TForm1.btnNewClick(Sender: TObject);
begin
NewTabSheet(PageCtrl,'
Tab '+IntToStr(PageCtrl.PageCount));
btnDelete.Enabled:=True;
end;
function TForm1.DeleteTabSheet(pc: TPageControl): Boolean;
var
aTabSheet : TTabSheet;
begin
Result:=True;
Try
aTabSheet:=pc.ActivePage;
FreeAndNil(aTabSheet);
Except
Result:=False;
end;
end;
procedure TForm1.btnDeleteClick(Sender: TObject);
begin
If Not DeleteTabSheet(PageCtrl)
then
ShowMessage('
Fehler');
end;
procedure TForm1.edtTextKeyPress(Sender: TObject;
var Key: Char);
var
aTabSheet : TTabSheet;
aRichEdit : TRichEdit;
begin
aTabSheet:=PageCtrl.ActivePage;
If aTabSheet<>
Nil then
begin
aRichEdit:=TRichEdit(aTabSheet.Tag);
If (aRichEdit<>
Nil)
and (Key=#13)
then
aRichEdit.Lines.Add(edtText.Text);
end;
end;
end.