Board index » delphi » Creating TTabSheets and RichEdit dynamically

Creating TTabSheets and RichEdit dynamically


2003-06-27 10:10:55 PM
delphi33
Hi,
I'm trying to dynamically add pages to a PageControl. Each page on this
PageControl is going ot have a Rich Edit control on it, that is maximised to
the size of the control. You can guess I am trying to write a text editor
that supports a tabbed view :-)
Below is the code I am using to create the pages and the RichEdit. For some
reason, the RichEdit doesn't want to appear.
procedure TForm1.FormCreate(Sender: TObject);
var
ts : TTabSheet;
i : integer;
re : TRichEdit;
begin
i := 0;
for i := 0 to 9 do
begin
ts := TTabSheet.Create(PageControl1);
ts.PageControl := PageControl1;
ts.Caption := 'Untitled' + IntToStr(i);
re := TRichEdit.Create(ts);
re.Left := 0;
re.Top := 0;
re.Width := ts.ClientWidth;
re.Height := ts.ClientHeight;
re.Visible := true;
end;
end;
Any help would be appreciated.
Thanks.
Wee Jin
 
 

Re:Creating TTabSheets and RichEdit dynamically

"Wee Jin Goh" <XXXX@XXXXX.COM>writes
Quote
for i := 0 to 9 do
begin
ts := TTabSheet.Create(PageControl1);
ts.PageControl := PageControl1;
ts.Caption := 'Untitled' + IntToStr(i);

re := TRichEdit.Create(ts);
re.Align := alClient;
re.Parent := ts;
end;
Igor
 

Re:Creating TTabSheets and RichEdit dynamically

"Wee Jin Goh" <XXXX@XXXXX.COM>writes
Quote
Below is the code I am using to create the pages and the RichEdit. For some
reason, the RichEdit doesn't want to appear.
Don't worry, you're not the first person to forget to set .Parent, and you
won't be the last...
And instead of setting .Left, .Top, .Width, and .Height, just set .Align to
alClient.
Cheers,
Ignacio
 

Re:Creating TTabSheets and RichEdit dynamically

thanks guys. Just a quick question about the Parent thing, is that a must
for all controls or just for the RichEdit?
Regards,
Wee Jin
"Ignacio Vazquez" <ivazquezATorioncommunications.com>writes
Quote
"Wee Jin Goh" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Below is the code I am using to create the pages and the RichEdit. For
some
>reason, the RichEdit doesn't want to appear.

Don't worry, you're not the first person to forget to set .Parent, and you
won't be the last...

And instead of setting .Left, .Top, .Width, and .Height, just set .Align
to
alClient.

Cheers,
Ignacio


 

Re:Creating TTabSheets and RichEdit dynamically

"Wee Jin Goh" <XXXX@XXXXX.COM>writes
Quote
thanks guys. Just a quick question about the Parent thing, is that a must
for all controls or just for the RichEdit?
It's required for all visual components. Otherwise no one knows that the
component needs to be repainted.
Cheers,
Ignacio
 

Re:Creating TTabSheets and RichEdit dynamically

Quote
It's required for all visual components. Otherwise no one knows that the
component needs to be repainted.
If that is so, what's the point of passing the parent to the Create method? I
thought that would associate the component with a parent component.
Regards,
Wee Jin
 

Re:Creating TTabSheets and RichEdit dynamically

"Wee Jin Goh" <XXXX@XXXXX.COM>writes
Quote
>It's required for all visual components. Otherwise no one knows that the
>component needs to be repainted.

If that is so, what's the point of passing the parent to the Create method?
I
thought that would associate the component with a parent component.
That's not the parent, that is the owner. The owner is responsible for
freeing the object when the owner itself is freed.
Cheers,
Ignacio
 

Re:Creating TTabSheets and RichEdit dynamically

well you thought incorrectly! :)
in the create usually the owner of the component is
passed.
all this does is allows the owner to free it when the owner free's
the parent on the other hand is needed to indicate the drawing surface window
and other GUI/GDI control
you can actually set the parent of a control to some other form other than the
owner and it will display there even though its not the owner of the resources
Wee Jin Goh writes:
Quote
>It's required for all visual components. Otherwise no one knows that the
>component needs to be repainted.

If that is so, what's the point of passing the parent to the Create method? I
thought that would associate the component with a parent component.

Regards,
Wee Jin