Solved

Delphi XE5: problem with myForm.hide

Posted on 2014-04-23
4
650 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now