Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delphi XE5: problem with myForm.hide

Posted on 2014-04-23
4
Medium Priority
?
678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 38

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 38

Accepted Solution

by:
Geert Gruwez earned 1500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

597 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