Jump to content
ChrisChuah

ShowModal does not show window after a few tries (It does not pop up)

Recommended Posts

HI 

I am having this funny problem in Delphi 11.1 using VCL.

 

====

  FDetailForm := TfrmAircraftTypesNew.Create(self);
  try
    (FDetailForm as TfrmAircraftTypesNew).setData(UpdateRow, l_rec);
    FDetailForm.Visible := false;
    FDetailForm.ShowModal;
  finally
    l_rec.Free;
  end;
  FDetailForm := nil;
=======

When i open and close the FDetailForm a few times, the detail form would not show and the main window will hang.

See this video to see what i mean.

 

In the Form Close of the TfrmAircraftTypesNew, i will have

Action := caFree;

1655068418_Screenshot2022-08-22at20_58_57.thumb.png.44d4ad21823c1bf09bcda563e4cbe085.png

Can help why the form is not able to show on top. 

I have already tried to put the PopupMode to Explicit.

 

Another Finding:

when i remove or commented the style from the startup, i did not have this problem of not able to showModal

 

Application.Initialize;
//  TStyleManager.TrySetStyle('Iceberg Classico');  <== Remove/commented this line
  Application.CreateForm(TDataModule1, DataModule1);
  Application.CreateForm(TfrmMain, frmMain);
  Application.Run;

 

Not sure why this style is giving problem....

 

Please advise

regards

chris

Edited by ChrisChuah
added a finding

Share this post


Link to post

In any case, I miss FDetailForm.Free; I don't know if it will help.

Share this post


Link to post
5 minutes ago, Stano said:

In any case, I miss FDetailForm.Free; I don't know if it will help.

See this  in the OP:

In the Form Close of the TfrmAircraftTypesNew, i will have

Action := caFree;

Share this post


Link to post

The DetailForm close event will have Action := caFree

I tried this way

 

===== Ghosting Windows

procedure DisableProcessWindowsGhosting;

var
  DisableProcessWindowsGhostingProc: procedure;
begin
  DisableProcessWindowsGhostingProc := GetProcAddress(
    GetModuleHandle('user32.dll'),
    'DisableProcessWindowsGhosting');
  if Assigned(DisableProcessWindowsGhostingProc) then
    DisableProcessWindowsGhostingProc;

end;

 

begin
  Application.Initialize;
  DisableProcessWindowsGhosting;
  TStyleManager.TrySetStyle('Iceberg Classico');
  Application.CreateForm(TDataModule1, DataModule1);
  Application.CreateForm(TfrmMain, frmMain);
  Application.Run;
end.
=======================

 

But will also have the same effect that open and close the form too many times will result in hanging of the application or the form will not show.

 

Only when i removed the Style Manager, then i will not have this problem.

The Grid is also having its own DrawColumnCell Event

 

=====================

procedure TfrmMain.dbgACTDrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  l_bitmap : TBitmap;
  l_rect : TRect;
  l_bmpWidth, l_width : integer;
  l_str : string;
begin
  with dbgACT do begin
    if (gdSelected in State) then begin
      Canvas.Font.Color := clBlack;
      Canvas.Brush.Color := clLime;
    end
    else begin
      if ( (DataSource.Dataset).RecNo mod 2 = 0) then begin
        if Canvas.Brush.Color = Color then begin
          Canvas.Brush.Color := clSkyBlue;
        end;
      end;
    end;
  end;
  l_rect := Rect;
  l_str := Column.Field.DisplayText;
  l_width := dbgACT.Canvas.TextExtent(l_str).cx + 5;
  if Column.FieldName = 'ROW_ID' then begin
    l_bitmap := TBitmap.create;
    try
      ImageList2.GetBitmap(tsACT.ImageIndex, l_bitmap);
      l_bmpWidth := (Rect.bottom - Rect.Top);
      l_rect.Right := Rect.Left + l_bmpWidth;
      dbgACT.Canvas.StretchDraw(l_rect, l_bitmap);
    finally
      l_bitmap.Free;
    end;
    // cc : reset the output rectangle
    l_rect := Rect;
    l_rect.Left := l_rect.Left + l_bmpWidth;
    l_width := 5 + dbgACT.Canvas.TextExtent(l_str).cx;
  end;
    if (l_width > Column.Width) then
      Column.Width := l_width;
  dbgACT.DefaultDrawColumnCell(l_rect, DataCol, (Column as TColumn), State);
end;
====================

 

But not sure if this affected the style manager or not

 

regards

chris

 

Share this post


Link to post

I'm not an expert, but in my opinion Action := caFree; frees things in the form, but not the form itself. I am happy to learn.
Personally, I would just show and hide the form. It did not destroy and set to null. I don't know if such behavior is suitable for the given situation.
I won't get involved in your business anymore. I can't do it:classic_dry:

Edited by Stano

Share this post


Link to post

We are just learning. I am still learning too

I tried not to create the form but to call showmodal each time user click on the update button

But i will get a problem is that cannot Showmodal when the form is visible.

In the FormClose of aircrafttype form, i set it to caHide instead of caFree

and i have that error.

 

I feel that even though i have use delphi since Delphi 1, i am still learning how to use this language.

Delphi 6 was the most stable version that i used and I am still using that now to do minor changes to those application written in 2007.

 

Edited by ChrisChuah
comments

Share this post


Link to post
26 minutes ago, Stano said:

I'm not an expert, but in my opinion Action := caFree; frees things in the form, but not the form itself. I am happy to learn.
Personally, I would just show and hide the form. It did not destroy and set to null. I don't know if such behavior is suitable for the given situation.
I won't get involved in your business anymore. I can't do it:classic_dry:

From the manual:
"

caFree

The form is closed and all allocated memory for the form is freed.

"

 

@TS, Maybe, maybe,  FDetailForm.SetZOrder(True) would help. 

if i remeber there's also a winapi call to reset/refresh zorder of windows,  i'll try to find that.

 

(but big question is still why form goes behind mainform after couple of times)

 

Edited by mvanrijnen

Share this post


Link to post

IMHO, using caFree seems not the best approach for the ShowModal case.

 

With caFree a message CM_RELEASE is placed inside the message queue of the form, which will lead to Free when this message is processed later. This is OK when calling Show for the form.

 

I suggest to keep the default caHide Action in the FormClose and add a FDetailForm.Free in the finally block.

Share this post


Link to post

I tried it with 2 almost empty forms in D11.1, with same method as TS, but the modalform stays appearing on top, after 50 times.

Is TS using a specific componentset ? or does the subform do something with z-order ?

(i last had some troubles with a specific componentset in D11.1 on Win11, where i had 2 click the closebutton of the "child" form twice to close, but they fixed that)

 

ah, read over the styles part, try that also here now.

 

Edited by mvanrijnen

Share this post


Link to post

Ok. I will try to write a small part of the code to see if i can reproduce the same error or not

 

thanks

chris

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×