Welcome, Guest
Guest Settings
Help

Thread: Another TPageControl Question



Permlink Replies: 3 - Last Post: Mar 10, 2017 3:15 PM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Alan Jordan

Posts: 207
Registered: 3/2/01
Another TPageControl Question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2017 10:09 AM
I have an application that uses multiple forms for input and output. I am using these forms in TPageControl with the following code:
var
Form : TForm;
Sheet : TTabSheet;
procedure MainForm.FormCreate(Sender, TObject);
begin
Sheet:=TTabsheet.Create(PageControl1);
Sheet.PageControl:=PageControl1;
Form:=TKinematicsDataDlg.Create(Application);
Form.BorderStyle:=bsNone;
Form.Parent:=Sheet;
Form.Visible:=true;
PageControl1.ActivePage:=Sheet;
Sheet.Caption:=Form.Caption;
end;
In each form that is shown, which now I am only showing one, I have OnKeyPress and OnMouseUp events that I want to fire. I don't see how to call those events from the MainForm that holds the PageControl.

Also, the only place the MainForm where the OnMouseDown or OnMouseUp fires is when I click in the PageControl area of the form. What am I missing?
Remy Lebeau (Te...


Posts: 7,723
Registered: 12/23/01
Re: Another TPageControl Question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2017 11:38 AM   in response to: Alan Jordan in response to: Alan Jordan
Alan wrote:

I have an application that uses multiple forms for input and output.
I am using these forms in TPageControl with the following code:

You really shouldn't embed TForm objects like that. Use TFrame instead.
Either way, I suggest you set the TTabSheet object as the Owner instead
of the TApplication object.

In each form that is shown, which now I am only showing one, I have
OnKeyPress and OnMouseUp events that I want to fire. I don't see how
to call those events from the MainForm that holds the PageControl.

Those events are fired when the user types while the child Form has input
focus, or when the user clicks on a blank area of the child Form's client
area, respectively. Why do you need the MainForm to fire the events? What
are you really trying to accomplish?

--
Remy Lebeau (TeamB)
Alan Jordan

Posts: 207
Registered: 3/2/01
Re: Another TPageControl Question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2017 12:15 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Alan wrote:

I have an application that uses multiple forms for input and output.
I am using these forms in TPageControl with the following code:

You really shouldn't embed TForm objects like that. Use TFrame instead.
Either way, I suggest you set the TTabSheet object as the Owner instead
of the TApplication object.
What is wrong with embedding a TForm in a PageControl? I want to use the same form in other code as a form, as well as embed in the PageControl.

In each form that is shown, which now I am only showing one, I have
OnKeyPress and OnMouseUp events that I want to fire. I don't see how
to call those events from the MainForm that holds the PageControl.

Those events are fired when the user types while the child Form has input
focus, or when the user clicks on a blank area of the child Form's client
area, respectively. Why do you need the MainForm to fire the events? What
are you really trying to accomplish?

If I am typing on the embedded form, doesn't it have input focus?

I can fire the embedded form's OnKeyPress with the following code, but I am using Activecontrol property in the form and I get an AV at that point.
Code from TPageControl form:

procedure TCamShaftForm.FormKeyPress(Sender: TObject; var Key: Char);

begin
if (Key=#13) then
begin
Form.OnKeyPress(Sender, Key); // This calls the form's FormKeyPress
end;

In the Embedded FormKeyPress lcode snippit looks like this:
procedure TKinematicsDataDlg.FormKeyPress(Sender: TObject; var Key: Char);
var
Str : String;
i : Integer;
begin
BackSpace:=false; // 02-22-2016 # 1886b
Str:=ActiveControl.Name; // this give an AV


--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 7,723
Registered: 12/23/01
Re: Another TPageControl Question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2017 3:15 PM   in response to: Alan Jordan in response to: Alan Jordan
Alan wrote:

What is wrong with embedding a TForm in a PageControl?

They don't always work correctly when embedded.

I want to use the same form in other code as a form, as well
as embed in the PageControl.

A TFrame is best for that. Put all the content on the TFrame, and then you
can embed it as a child of a TTabSheet or blank TForm as needed.

If I am typing on the embedded form, doesn't it have input focus?

Not necessary. Typically only input controls, like TEdit, can have focus
for keyboard input.

I can fire the embedded form's OnKeyPress with the following code, but
I am using Activecontrol property in the form and I get an AV at that
point.

TCamShaftForm is not checking if the Form variable is NULL before calling
its OnKeyPress event handler. And TKinematicsDataDlg is not checking if
its ActiveControl is NULL before accessing its Name.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02