Solved

Delphi XE5: problem with myForm.hide

Posted on 2014-04-23
4
649 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

747 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

9 Experts available now in Live!

Get 1:1 Help Now