Lazarus pascal/Delphi - Child form is not editable - forms

I'm creating a new instance of a form and trying to show it as a child from on a PANEL. But The form doesn't seem to be usable. I mean I cannot edit any textbox. But there are other controls like the tree and button that seem clickable.
Here is the code:
procedure TForm1.ProcfrmSetupItemCategories;
var
NewForm: TfrmSetupItemCategories;
begin
NewForm:=TfrmSetupItemCategories.Create(BodyPanel);
NewForm.Parent := BodyPanel;
NewForm.Top:=5;
NewForm.Left:=5;
NewForm.Show;
end;
But if I remove the line NewForm.Parent := BodyPanel; the form is editable but it goes out of the parent form/Panel.
Also when the parent is set, the child form is not active (looking at the title bar)
Am I missing something? Please advice.
Thanks!

A Form needs to be a child of other forms or TApplication. The TPanel does not know how to manage forms so your form will not get activated and its components will not receive focus.
Instead you could use normal forms and write a procedure to align your forms. Now add a timer to your main form and call the alignment procedure from the ontimer event. As the user moves or resizes the main form, the other forms re-align.
Dave Peters
DP Software

Related

How to stop the user from change the size of the form

I have created my project to fir in a portion of the form. I disabled the buttons on the top right hand side of the form(I apologize as I don't know its technical name). I would like to also disable the user from adjust the from size via the cursor. Is that possible through code in delphi?
Set the form's BorderStyle property to bsSingle; if it isn't a dynamically generated form, you can do this using the Object Inspector. Also, I understand that you have already removed biMaximize from BorderIcons (hence, you have removed the Maximize title bar button).
I assume now that this is the main form of your application. If, on the other hand, it is a dialog box displayed when you invoke a menu item (for instance), you should instead set BorderStyle to bsDialog. Such forms are also not resizable, and they have no maximize or minimize title bar buttons).
Do the following:
Set the form's BorderIcons.biMinimize = false and BorderIcons.biMaximize = false. (As I think you already have)
Assign an event handler for the form's event OnCanResize, and code it as follows:
.
procedure TForm1.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
Resize := False;
end;
This prevents the user from resizing the form with the mouse, while the form still has the appearance of a normal form.

How to set MDI child form border to none?

On my MDI Form (Parent Form), whenever I trigger a command to create a new MDI Child Form, I do these stuff (but it doesn't work):
procedure TfrmMDI.CreateChildForm(const childName: string);
var Child: TfrmChild;
begin
Child := TfrmChild.Create(Application);
Child.Caption := childName;
Child.BorderStyle := bsNone;
end;
I tried to set the Border Style of the MDI Child Form to bsNone through object inspector but it doesn't work as well.
I finally tried to set the MDI Child's Form BorderStyle through run-time however, it doesn't seemed to work too.
procedure TfrmChild.FormCreate(Sender: TObject);
begin
BorderStyle := bsNone;
end;
For additional information, my current MDI Child Form looks like this:
We may want to set our MDI Child's BS like this MDI Parent's BS:
What you are attempting to do is not how MDI is meant to be used. The GUI you want to have would likely be better served by using client-aligned TFrame objects instead of MDI child forms.
Upon waiting for some answers, I have read a documentation from Embarcadero that states:
"Changing the border style of an MDI child form to bsDialog or bsNone has no effect"
I tried to change the Application Appearance of my program to some pre-installed styles created by Embarcadero and It helped.
I just override the default style setting of my project.
Finally, it looks like this. Any border style changes will be applied to your MDI Child Form if you override the default form style:

Display a Form in front of another Form that is always at the top

I have a Form that stay always on top with FormStyle -> fsStayOnTop, and I did another Form with this same settings. But when I show this other Form, it is showed always behind, and not in front of first Form. So, how I do to the second Form be displayed in front of the first Form?
An owned top level window always appears above its owner. So, make the fsStayOnTop form be the owner of the other form. In VCL terms, that means setting the PopupMode property to pmExplicit, and assigning the PopupParent property.
OtherForm.PopupMode := pmExplicit;
OtherForm.PopupParent := AlwaysOnTopForm;
OtherForm.Show;

access 2003 cycle current page not working if subform is in form view

I have a form with multiple sub-forms.
I would like to have the following behaviour: pressing the tab key in the last field of the main form or in the last field of a subform the focus moves to the next subform or back to the main form according to the defined Tab order.
To achieve this, all subforms as well as the main form have the Cycle property set to Current page.
All subforms are shown within the main form as Datasheets except one that is shown in Form view.
Now I get the behaviour I want only for the main form and for the subforms shown as datasheets but not for the subform shown as Form.
Is this the normal behaviour in access 2003, of is there some other property that I have to change?
Note: if I change the default view of the "misbehaving" form to Datasheet as the others, it also behaves as I want...What am I doing wrong?And... if this is the way access 2003 works... what would be the best way to obtain the desired behaviour using vba given that I cannot find an OnTab method?
Edit: While waiting to understand if this can be done setting the right properties in the forms, I acheved the desired behaviour with this code in the first and last fields of the "misbehaving" subform.
'In the last field
Private Sub Posizione_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyTab And Shift = 0) Then
KeyCode = 0
Me.Parent!Autore_Subform.SetFocus
End If
End Sub
'in the first field
Private Sub Stanza_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyTab And Shift = 1) Then
KeyCode = 0
Me.Parent!Pagine.SetFocus
End If
End Sub
I was just looking for an answer to the same question, and found this via Google: Ctrl-Tab will move from the last control in the subform to the next control in the main form. I found from experimenting (with Access 2007) that it doesn't matter which control has focus in the subform, Ctrl-Tab will pop you out of the subform to the next control in the main form.

Displaying forms using Tree in Qt

I'm building a Qt plugin with multiple forms. I have a main form which has a tree widget placed on the left of the form.
I want to add items to this tree, such that clicking on these items would load the corresponding form on the same form. But I want the tree widget to be active so that I can select any other form also.
I was able to display a form on the main form using the following code:
Form1 *myform;
myform=new Form1(this);
myform->show();
where Form1 is the class of the form i intend to display. However this, covers up the tree widget also. And I have to do a string comparison of the item in tree being clicked to display the appropriate form.
Can someone please help me with this as I'm very new to Qt programming.
Thanks
ixM has a good suggestion. The first step should definitely be to use layouts in your main window - separating the tree from the rest of the window - where you are going to put your form. I would suggest using a splitter, because then the user can resize the two halves. You can set the splitter as the main widget of your CentralWidget in your main window.
QSplitter splitter = new QSplitter(CentralWidget);
splitter->setOrientation(Qt::Horizontal);
splitter->setHandleWidth(3);
splitter->setChildrenCollapsible(false);
MyTree= new QTreeWidget(splitter);
splitter->addWidget(MyTree);
Then add your tree widget to the splitter, which will be on the left side.
The next step is to add a placeholder widget on the right side of your splitter. We are also going to add a layout inside that widget. This layout is very important we are going to use it later.
QWidget WidgetRightSide = new QWidget(splitter);
QVBoxLayout setupLayout= new QVBoxLayout(WidgetRightSide);
setupLayout->setSpacing(0);
setupLayout->setContentsMargins(0, 0, 0, 0);
Now, at this point, this is where my answer really differs from the previous answer. You could use a QStackedWidget. That is certainly an option. The problem with that is that you have to create and load all your forms at the beginning. That uses way more memory, and will take longer to start up. That's not so bad if you have 2-5 forms, but when we are talking about 20, 30 or more forms that's really ugly.
So what I would suggest instead, is that when the user selects something in the tree, we will remove the old form, and add the newly selected form at that point.
When the selected item in the tree changes this is now what we have to do.
First, remove all the stuff from the previously selection form.
QLayoutItem *_Item;
while ((_Item = setupLayout->takeAt(0)))
delete _Item;
Next, figure out what form to show next, and create it.
QWidget *ActiveSetupForm = NULL;
if ( I need to load form 1)
{
ActiveSetupForm = new YourNewForm( WidgetRightSide);
}
else ...
And lastly, add your new form to our layout.
if(ActiveSetupForm)
{
setupLayout->addWidget(pActiveSetupForm);
}
Just as a side note. Layouts are tricky to do by hand. I would strongly suggest that you look into using the QtDesigner when you are creating your forms. It makes life soooo much easier. If you would like to know more about it check out this link.
I don't exactly understand what you are trying to achieve but the bit of code you are showing suggests that you do not use the layouts provided by Qt.
If your goal is to be able to dynamically load a form depending on the item that was clicked in the tree, you could achieve that by having a layout (let's say QHBoxLayout) where you would insert your tree and a QStackedWidget in which you could "store" each form (by using addWidget()) and choose which one you want to display by calling setCurrentIndex().