Solved

form visible already true ???

Posted on 2011-02-16
27
406 Views
Last Modified: 2012-05-11
I understand the error msg but can't not imagine how this should happen inside my code ...


I do:
     form := Tform.Create(self)
     form.showmodal;

     if (form.modalresult=mrOK= then
                begin

                end


      form  has formstyle = fsnormal .....
      form is not created inside the *.dpr file, alraedy removed here
modal-error.jpg
0
Comment
Question by:BdLm
[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
  • 14
  • 8
  • 2
  • +2
27 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 34906688
Can you translate to English please.
0
 
LVL 8

Author Comment

by:BdLm
ID: 34906708
errror msg: "....   from a visible window you can not change to a modal window " 
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34906753
it's possible events inside the form to show modal cause it to become visible
before the call to showmodal is called

best solution:
find the code which sets the form onscreen
(like application.processmessages)

workaround:
hide the form before showmodal

form := Tform.Create(self)
try    
  form.Hide;
  form.showmodal;
  if form.modalresult = mrOK then
  begin

  end
finally
  form.Free;
end;
0
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!

 
LVL 24

Expert Comment

by:jimyX
ID: 34906766
What is your code? I can successfully use this code:
procedure TForm1.Button1Click(Sender: TObject);
var
  form : Tform;
begin
  form := Tform.Create(self);
  form.showmodal;
  if (modalresult=mrOK) then
  begin

  end;
  form.Free;
end;

Open in new window

0
 
LVL 8

Author Comment

by:BdLm
ID: 34907131
@jimxy : exactly my code ... used many times on other locations without a problem

@geerd : help to show the form butr still av at modual result
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34907139
set form visible property to false in design
and try again
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34907198
show the code in formcreate, constructor create, formshow, aftercreate and anything you call from those 4 procs/events
0
 
LVL 8

Author Comment

by:BdLm
ID: 34907318
---  no more code --- i promise except ....

procedure TForm.FormCreate(Sender: TObject);
begin
     
    // fDBList :=TDatabaseList.create;    //  more info seee   http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q__26825062.html 

     self.height   :=  Default_Height;

     self.Width    := Default_Width;

     scaled := true;
end;


and ...  I work with a TObjectist... once finished my work with the list a Button on that from disappears ....  never set the property visible to false (i can also promise)
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34907342
changing the width or height will cause an invalidate
which in turn causes your form to become visible :)

procedure TForm.FormCreate(Sender: TObject);
begin
     self.height   :=  Default_Height;
     self.Width    := Default_Width;
     scaled := true;
     visible := false;
end;
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34907369
or set the width and height in the constructor

0
 
LVL 2

Expert Comment

by:LelikInside
ID: 34907384
try to use  
 (self as Tform).height  :=  Default_Height;
 (self as TForm).Width  := Default_Width; 

Open in new window

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34907393
self is in this case of type TForm, that wouldn't make a difference
0
 
LVL 2

Expert Comment

by:LelikInside
ID: 34907432
Where did you get procedure TForm.FormCreate(Sender: TObject);? Why just TForm?
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34907486
something else in your code is causing the problem

i created a test sample and this doesn't have the problem:
 
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    Edit1: TEdit;
    procedure BitBtn1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

uses Unit3;

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  if ShowForm3(Self) then
    Edit1.Text := 'Ok'
  else
    Edit1.Text := 'oops';
end;

end.

Open in new window

unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm3 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
  public
  end;

var
  Form3: TForm3;

function ShowForm3(AOwner: TComponent): boolean;

implementation

{$R *.dfm}

function ShowForm3(AOwner: TComponent): boolean;
var form: TForm3;
begin
  Result := False;
  form := TForm3.Create(AOwner);
  try
    if form.ShowModal = mrOk then
    begin
      Result := True;
    end;
  finally
    form.Free;
  end;
end;

procedure TForm3.FormCreate(Sender: TObject);
begin
  Width := 200;
  Height := 300;
  Scaled := True;
end;

end.

Open in new window

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34907523
ow ow ow ... you override the standard TForm ?
with your own class TForm ?

so you subclassed the TForm ?
and want to add your own customizing ?
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34907558
nope , still works with subclassing

unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm = class(Forms.TForm)
  public
    constructor Create(AOwner: TComponent); override;
    procedure FormCreate(Sender: TObject);
  end;

type
  TForm3 = class(TForm)
  end;

var
  Form3: TForm3;

function ShowForm3(AOwner: TComponent): boolean;

implementation

{$R *.dfm}

function ShowForm3(AOwner: TComponent): boolean;
var form: TForm3;
begin
  Result := False;
  form := TForm3.Create(AOwner);
  try
    if form.ShowModal = mrOk then
    begin
      Result := True;
    end;
  finally
    form.Free;
  end;
end;

{ TForm }

constructor TForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  OnCreate := FormCreate;
end;

procedure TForm.FormCreate(Sender: TObject);
begin
  Width := 200;
  Height := 300;
  Scaled := True;
end;

end.

Open in new window

0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34908315


You can assign the ModalResult to a variable or just test it directly
 var
     form: Tform
  form := Tform.Create(self);
  try
    if form.ShowModal = mrOk then
  .........

or
  var
     FormResult: Integer;
      form: Tform;
  begin
     form := Tform.Create(self);
     try
       FormResult := form.ShowModal;
       ..............
 
 
 
0
 
LVL 8

Author Comment

by:BdLm
ID: 34908547
OK:  Geerd idea so far a bit improvement  on other pc the same code with a different run time behaviour,
means  only the missing button effect appears ......

the very bad thing :  the complete code had been functional a few month ago ....     but we did not track the changes with subversion of that unit :-(
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34910198
is this delphi 7 on a new pc showing the different behaviour ?

and you have also installed the patches for delphi 7 on the new pc ?
0
 
LVL 8

Author Comment

by:BdLm
ID: 34910234

no both PC (notebook) are almost identical , could not see any difference in the D7 behaviour -  no idea where this bug comes from ....
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34910293
it's easy to test a delphi... most common bug is oldcreateorder

this comes into play with a constructor and FormCreate

var Test: integer;

constructor TForm1.Create(AOwner: TComponent);
begin
  Test := 1;
  inherited Create(AOwner);
  ShowMessage('Create '  + IntToStr(Test));
  Test := Test +1;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowMessage('FormCreate ' + IntToStr(Test));
  Test := Test + 10;
end;

you should get Create 1, and then get FormCreate 2
with oldCreateOrder := False
otherwise the delphi version has the bug

at least that's what i found out some time ago with a unpatched delphi 7
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34910301
oh yeah: the type declaration

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
  end;
0
 
LVL 8

Author Comment

by:BdLm
ID: 34913857
add fastrMM4 and removed code from the project file now compile is failing with AV ??????
0
 
LVL 8

Accepted Solution

by:
BdLm earned 0 total points
ID: 34913860
here is the compiler msg ...  
delphi-compiler-error.png
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34917285
you forgot to blank out the other module name ... LayoutExtraction

Start the program with F8 in delphi.
Then in the menu search / Find error
enter 004AFF6A and see where it takes you ...
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34917346
you are now giving a completely different error
????????????????????????

and then deleting this question because you found the solution to that other error
thud ... my chin dropping on the floor in awe and staring wide eyed at my screen


 
+++
___ooo__0_0__ooo___

Open in new window

0
 
LVL 8

Author Closing Comment

by:BdLm
ID: 34949666
seems that a BDE failure has been the reason, therfore it does not make sense to me to abward the good discussion from yetserday, next time I spilt points again ...
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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

628 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