?
Solved

Delphi XE5: problem with myForm.hide

Posted on 2014-04-23
4
Medium Priority
?
675 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

Technology Partners: 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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

741 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