Delphi - Application main form gets focussed incorrectly - windows

In two parts of my application, the main form gets focussed at the wrong moment:
Bug 1. When clicking 'OK' from a specific printer form.
I open a FastReports PDF preview - that's the first popup. That popup is not shown seperately in the taskbar. This form is modal.
Then I click print,
That opens another window with standard printing options.
Then I click properties - that opens the specific form of the driver. I change the double printing setting.
When I click 'OK', the preview form (1) should be focussed, but the main form is brought to front. Because the preview form is still modal, it is hard to get back to the preview form. Only with random clicks, the preview form gets focussed again.
Bug 2. Clicking on or dragging this specific scrollbox focusses the main form
This window is active. This is a seperated window in the Windows task bar and is not modal. There is a gnostice pdf viewer on this form.
When I click the scrollbox to start dragging, the main form is brought to front. When I keep dragging, the scrolling at the pdf form still continues. Also, a tooltip near the mouse indicates what page is currently shown.
I want to solve this strange behaviour. So, my question is:
What can be causing these focussing bugs?
About the application:
I already noticed: the popup forms seems a bit too large, as you can see here:
see edit
Some forms are MDI child.
I searched in the code for all mouse events and put there breakpoints. But that code was not executed at the moment of the two bugs.
VCLskin is used.
Bug 1 occurs with Fast reports version 5.6.1 and 5.6.8.
Windows 10.
Delphi XE 10.2.
Edit
The application main form is set correctly. At startup, first a login form is shown. After your login, the datamodules are created, some forms are created without a owner (they are freed on application end).
All other forms, also the main form are owned by Application and not by the Login form. And indeed not as parent, but as owner, like #uwe-raabe said.
Then the main form is created. This is created via the Login form:
Frm_DatabaseLogin.CreateForm(TFrm_MainMenu, Frm_MainMenu);
That calls:
procedure TFrm_DataBaseLogin.CreateForm(InstanceClass: TComponentClass;
var Reference);
begin
Updateprogress(InstanceClass.ClassName);
Application.CreateForm(InstanceClass,Reference);
end;
In UpdateProgress nothing special happens.
After that, the other forms are created too, owned by application. At the end, the login form hides and therefore the main form is shown.

I'm making some assumptions here on your startup code.
"Main Form" can be a confusing term. From the TApplication point of view Application.MainForm is always the first form that is created using Application.CreateForm.
Since your login form creates your application's primary form and then hides itself, the login form is still the "main" form.
Your screenshot has two icons shown on the taskbar. I'm assuming you are either orverriding CreateParams or calling SetWindowLong to make that happen.
I have a similar setup with a "main" login form that is then hidden.
In my application, I override CreateParams for forms that should be standalone and have a taskbar icon:
procedure TMgrMain.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := 0;
end;
Then when showing popups I create the form with an owner (probably not needed), and then set PopupMode and PopupParent. Since I started this I no longer have forms that pop-behind.
procedure ShowAbout(Owner: TForm);
var
LocalForm: TAbout;
begin
LocalForm := TAbout.Create(Owner);
try
LocalForm.PopupMode := pmExplicit;
LocalForm.PopupParent := Owner;
LocalForm.ShowModal;
finally
FreeAndNil(LocalForm);
end;
end;
From the PopupParent help:
If the PopupMode property is set to pmExplicit and PopupParent is nil,
then the Application.MainForm is implicitly used as the PopupParent.
If no Application.MainForm is assigned, then Application.Handle is
used as the PopupParent.
If the PopupMode property is set to pmAuto, Screen.ActiveForm is used
as the PopupParent property.
Part of where I took my steps from were from an old Peter Below newsgroup post. Also this is really old advice now and was before the addition of PopupParent/PopupMode
Newsgroups: borland.public.delphi.winapi
From: "Peter Below (TeamB)" <100113.1...#compuXXserve.com>
Date: 2000/11/30
Subject: Re: Modeless window act like .exe
.. cut ..
Note that this can cause
some problems with modal forms shown from secondary forms. If the user
switches away from the app while a modal form is up and then back to
the form that showed it the modal form may hide beneath the form. It
is possible to deal with this by making sure the modal form is
parented to the form that showed it (using params.WndParent as above)
but this is not possible with the standard dialogs from the Dialogs
unit and exceptions, which need more effort to get them to work right
(basically handling Application.OnActivate, looking for modal forms
parented to Application via GetLastActivepopup and bringing them to
the top of the Z-order via SetWindowPos).
.. cut ..
Finally here is a blog post that talks about why the changes to PopupMode and PopupParent were made.

Related

How to force the back button to show on title bar?

Here's the scenario:
I'm working with Xamarin forms and using FreshMVVM.
My main screen is a FreshTabbedFONavigationContainer, one of the tabs navigate deeper into other pages while the others don't. If I'm in one of those deeper pages and do:
CoreMethods.PushNewNavigationServiceModal(...)
the next navigation page is added to the stack and the back button appears and works fine.
But if I call the same method from a root page in my main tabs page, the back button doesn't appear. I'm calling the same method, the same way, with the same argument types. I've even tried the same arguments.
Why would it work from a deeper FreshBasePageModel and not from the first FreshBasePageModel in a FreshTabbedFONavigationContainer? I've tried FreshTabbedNavigationContainer too and it made no difference.
Also, is there a way to force the back button to show and manage its behavior?

Visual Foxpro 9.0

I have a programming problem in Visual FoxPro, create a form that contains PageFrame with 2 Page.
1. On Page 1, Create a program to display data in the grid and give the sorting facilities, navigation and search.
2. On Page 2, create a program to calculate volumeTabung and spacious blanket.
Can anyone provide a solution? thank you
Although this is not DOING the answer, but a simple guide.
In the VFP command window,
Create Form [whatever form name you want]
Once form is up, look at the toolbar for "Form Controls". Click on the "PageFrame" control and then click on the form... There, you have a default pageframe with 2 pages as a default.
The "Properties" window should be visible by default. Click on the combobox on at the top which shows all controls. Open the drop-down and you will see "Page1" and "Page2" of the page frame control. Click on either page, and that will bring focus to that respective page.
Now, click on the Forms Controls toolbar again, such as to grab textbox, label, combobox, whatever and then click on the page and your controls are there. Then get focus to the second page and do the same for whatever you want.
Save and run the form. This just gets you to see the controls and how simple to put them on. Actual pulling your data and populating is really more your "to do" list.

Create dialog window in JSF

I would like to create a usual dialog window:
The user clicks a link or button
The screen becomes blackish, a new window appears (a DIV is created)
By using Ajax, the DIV is populated with a form.xhtml
By clicking on a cross in the DIV, the DIV is removed and the blackish screen too.
I know how to do some of this stuff with usual CSS/Jquery. However, I am lost on how the JSF link/button should call the Jquery code to create the dialog (because I am supposing that JSF cannot do it alone) and make the Ajax call to get the form.
I am not using auxiliary libraries.

Closed Windows Retaining Their Values/Choices

I have an application that has a few different forms. From the main form I can open a number of other forms, I use the following command to display the chosen window:
frmConversions.ShowModal;
Once the user has completed what they need to do in that window and they close that window I close the window using the following:
frmConversions.Close;
However if the user then goes back to frmConversions, the settings that they had previously chosen will still be selected/entered. Am I handling multiple windows correctly and if so how do I stop the retention of data?
It depends on how you create the form. If you auto-create the form, then it will exist for the lifetime of the program and so will retain any values stored in the form's variables. If, however, you create modal forms whenever needed and free them afterwards (as is the custom), then values will not be stored. This is done thus
with TFrmConversions.Create(nil) do
try
ShowModal;
finally
Free;
end;
IN the FormClose event, you can choose what happens to the form when you call Close (see the documentation and here. If the Action is for example caHide, the form is hidden, not freed. And thereby it will mantain the settings.
There are two basic approaches:
1) create the form each time before it is shown and free it when it is closed.
2) in the form's OnShow event, set all the variables the user might change to their initial values.
A way to accomplish #1 is to put a function in the form's unit file to create it, showmodal, then free it.

SL3 dataform validation indicators don't show in tab pages

I have a Prism/SL3 application with a tab control and each page of the tab control is a "Region" that has its own view and viewModel. when I want to validate the main page, I call dataForm.ValidateItem(), then I go to all the child views and do the same. the problem is, only the pages which user has clicked on them (on the tab page), get instantiated and the pages that are never shown, don't have their view instantiated, thus I can't validate them.
any help?
I created a psuedo work around for this. It's very hacky, but it does work. My example involved walking the visual tree (up and down) to find respective controls that are invalid and then "expanding" the selected item. I have used an accordian in my example, but have also tested this with tab:
http://thoughtjelly.wordpress.com/2009/09/24/walking-the-xaml-visualtree-to-find-a-parent-of-type-t/
HTH,
Mark
EDIT: Link updated.

Resources