[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

adding pages (tabsheets) to tpagecontrol

hi everyone,

i run into a problem that seems trivial but i can't find a solution, i need to add on run time tabsheets to a tpagecontrol component, now that's easy. the problem is that per new tabsheet i need to add a new trichedit.

for example, i add a new tabsheet called NewTab that will contain an empty (and aligned to allclient) trichedit.

any way to do this?

thanks for any help

uri
0
urif
Asked:
urif
  • 2
1 Solution
 
kretzschmarCommented:
var
  t : TTabSheet;
  r : TRichedit;
begin
  t := TTabsheet.Create(self);
  t.PageControl := PageControl1;
  t.parent := PageControl1;
  r := trichedit.create;
  r.parent := t;
  r.align := alClient;
  t.show;
end;

just from head, not tested

meikl ;-)

0
 
penichCommented:
Try to add a panel on each new tabsheet and use this panel like an layout for all your controls you need to add to your new tabsheet

NewTabSheet
    -----------
      NewPanel (Client Alignment)
         ----------
            Controls on the panel
0
 
kretzschmarCommented:
found an older sample from mine
(using a tmemo instead of an trichedit,
but this could be simpel replaced)

unit tn_u;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 StdCtrls, ComCtrls;

type
 TForm1 = class(TForm)
   Button1: TButton;  //Creates Pages
   PageControl1: TPageControl;
   CheckBox1: TCheckBox;  // Toggle Wordwrap
   Button2: TButton;  //Insert Lines
   procedure Button1Click(Sender: TObject);
   procedure CheckBox1Click(Sender: TObject);
   procedure PageControl1Change(Sender: TObject);
   procedure Button2Click(Sender: TObject);
 private
   { Private-Deklarationen }
 public
   { Public-Deklarationen }
 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}

Var ActiveMemo : TMemo = nil;  //Holds the selected Memo

procedure TForm1.Button1Click(Sender: TObject);  //Creates New Page
var
 TS : TTabsheet;
 TM : TMemo;
begin
 TS := TTabsheet.Create(PageControl1);
 TS.Parent := PageControl1;
 TS.PageControl := PageControl1;
 TM := TMemo.Create(TS);
 TM.Parent := TS;
 TM.Align := alClient;
 ActiveMemo := TM;
 CheckBox1.checked := TM.WordWrap;
 PageControl1.ActivePage := TS;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);  //Toggle WordWrap On Off
begin
 If ActiveMemo <> Nil then
   ActiveMemo.WordWrap := CheckBox1.Checked;
end;

procedure TForm1.PageControl1Change(Sender: TObject);  //Get the new ActiveMemo
var i : Integer;
begin
 if PageControl1.PageCount > 0 then
   for i := 0 to PageControl1.ActivePage.ControlCount - 1 do
     if (PageControl1.ActivePage.Controls[i] is TMemo) then
     begin
       ActiveMemo := TMemo(PageControl1.ActivePage.Controls[i]);
       CheckBox1.Checked := ActiveMemo.WordWrap;
     end;
end;

procedure TForm1.Button2Click(Sender: TObject);  // Add Lines to ActiveMemo
begin
 If ActiveMemo <> Nil then
   ActiveMemo.Lines.Add('This Line will be added');
end;

end.

hope this helps

meikl ;-)
0
 
urifAuthor Commented:
and it works perfect, thx!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now