Solved

Delphi XE5: problem with myForm.hide

Posted on 2014-04-23
4
658 Views
Last Modified: 2014-05-08
Hi

I have an application written in DXE2. No I compiled it with DXE5 and have the following problem (I describe a simple sample that I wrote to test):

- Two TForm, Form1, Form2
- on Form1 I have a Button, OnClick :
Form2.Show; 
Timer2.Enabled := true 

Open in new window

Timer2Timer:
Timer2.Enabled := false;
Form2.Hide

Open in new window

with another timer I show the value of Screen.ActivForm:
Timer1.Enabled := false;
Label1.Caption := Screen.ActiveForm.Name;
Timer1.Enabled := true;

Open in new window

If I compile this program with XE2: first Form1 is active, then with ButtonClick Form2 is active until Timer2Timer, then Form1 is active again (as I expected)

with XE5 after Timer2Timer Form2 stays the active form.

Is this a bug in XE5 or how have I to solve it?

Thanks, Peter
0
Comment
Question by:formi
  • 2
  • 2
4 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 40019318
why not post the complete with proc headers ?

if you want to experiment or check changing values
use a memo and updateActions ... don't think a timer is necessary
type
  TForm1 = class(TForm)
    Memo1: TMemo;
  private
    fLastActiveForm: TForm; 
  protected
    procedure UpdateActions; override;
  public 
    constructor Create(aOwner: TComponent); override;
  end;

procedure TForm1.UpdateActions;
var fNewActiveForm: TForm;
begin
  inherited UpdateActions;
  fNewActiveForm := Screen.ActiveForm;
  if fLastActiveForm <> fNewActiveForm then 
  begin
    if fNewActiveForm <> nil then 
      Memo1.Lines.Add(Format('Currently active: %s (%s)', 
        [fNewActiveForm.ClassName, fNewActiveForm.Name]))
    else 
      Memo1.Lines.Add('Currently active: nil');
  end;
end;

constructor TForm1.Create(aOwner: TComponent); 
begin
  fLastActiveForm := nil;
end;

Open in new window


did you try these extra lines ?
Form2.Hide;
Form1.Activate;
Form1.BringToFront;

maybe use a stack to maintain the order of forms ?
0
 

Author Comment

by:formi
ID: 40019355
of course I can add this lines but if have a project with half a million of lines with a lot of form.Show's. It doesn't make sense for me that - if a Form is hidden - it is always the active form. Embarcadero changed this. I have this code compiled in D7 and DXE2 and it was ok, but not in D XE5 and XE6.
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 40020361
a lot of form.show's ?
and no bringtofront ?
 
you'll have to file an sr with embarcadero to get the reason and a possible fix
for that they'll require a test case that proves the different behavior

posting that same test case here will give you responses from 2 sources ...
0
 

Author Closing Comment

by:formi
ID: 40052800
It seems to be a new philosophy from Embarcadero or Win8 (I didn't figure out yet) but I saw it is the same working in the IDE often after displaying another form (i.e. to explore a variable during debugging) the last form is no longer active and you have to click in it). So I solved it myself:

in the OnShow-events of the TForm I set a variable of type TForm:

  FLastForm := Screen.ActiveForm;

in the onHide-method I set the Focus to the last focused form:

  if (FLastForm <> nil) then
  begin
    i := 0;
    while i < Screen.FormCount do
    begin
      if Screen.Forms[i] = FLastForm then
      begin
        if FLastForm.Visible then
          FLastForm.SetFocus;
        i := Screen.FormCount;
      end;
      Inc(i);
    end;
  end;
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 323
Using idhttp to login to instagram 2 106
Firemonkey webbrowser scrollbars ? 1 50
Tvertscrollbox like a whatsapp layout 5 34
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question