Jump to content

UniSession.Synchronize shows hidden form


Clipe Informática

Recommended Posts

I have a situation where i create a form in background to use some methods from it. At some point i use the "UniSession.Synchronize" method and the form that i created in background is now beening shown at the screen. Why this happens? How can i avoid it? Here is the code:

var
  vSF0270 : TSF0270;
begin
  inherited;
  vSF0270 := TSF0270.Create(UniApplication);
  vSF0270.x:= 'bla bla bla';
  UniSession.Synchronize;
  showmessage(vSF0270.x);

I'm using the professional version.

Link to comment
Share on other sites

6 hours ago, Clipe Informática said:

I have a situation where i create a form in background to use some methods from it. At some point i use the "UniSession.Synchronize" method and the form that i created in background is now beening shown at the screen. Why this happens? How can i avoid it? Here is the code:


var
  vSF0270 : TSF0270;
begin
  inherited;
  vSF0270 := TSF0270.Create(UniApplication);
  vSF0270.x:= 'bla bla bla';
  UniSession.Synchronize;
  showmessage(vSF0270.x);

I'm using the professional version.

Do you want to show that form later or you will destroy it when you finish?

  • Like 1
Link to comment
Share on other sites

On 2/5/2021 at 5:29 PM, rgreat said:

UniGUI forms are shown right after they are created. That's normal.

You see, I´m migrating and old delphi application to uniGUI. On that app was normal to create a form just to call a function/procedure from it and then destroy it. I know its not the perfect/ideal way to do this, but it´s how was done.

Now the problem is that i need to show some logs on the screen during the process, and for that i need to use "UniSession.Synchronize;" Only when the synchronize is called the form that was created in background is showen.

There should be a way to create a form, use its methods/variables and destroy it without showing it in the process, even if i use "UniSession.Synchronize;"

Does this already exists? Am i missing something?

Link to comment
Share on other sites

14 hours ago, Clipe Informática said:

There should be a way to create a form, use its methods/variables and destroy it without showing it in the process, even if i use "UniSession.Synchronize;"

Just call vSF0270.Close; before UniSession.Synchronize;

Form will not be shown.

Maybe you should also set vSF0270.FreeOnClose:=False, if you want to work with form properties later.

Link to comment
Share on other sites

I tried as you said, but it doesn't work as you said. Here is what happens:

var
  vSF0270 : TSF0270;
begin
  inherited;
  vSF0270 := TSF0270.Create(UniApplication);
  UniSession.Synchronize;  //<- the form is shown
  vSF0270.Close;           //<- this does not hides the form
  vSF0270.x:= 'bla bla bla';
  UniSession.Synchronize;  //<- the form is still being shown
  sleep(5000);
  vSF0270.x:= vSF0270.x + 'x';
  UniSession.Synchronize;
  showmessage(vSF0270.x);  //<- the form is still being shown behind the message
  freeandnil(vSF0270);     //<- only here the form disappears

The form is only shown when I call "UniSession.Synchronize" and it keeps there until i call the freeandnil function.

Link to comment
Share on other sites

Yep. I checked it is not working now.

Still you could call Close; in form OnShow event.

 

Something like:


procedure TUniForm1.UniFormShow(Sender: TObject);
begin
   if CreateNonVisual then Close;
end;
That will do the trick.

That's quite a dirty way to do things, though.

 

I wish Farshad will change this behavior at least for free forms.

Link to comment
Share on other sites

FYI, i tried your suggestion and still the form is shown. That's how i made it:

var
  vSF0270 : TSF0270;
begin
  inherited;
  vSF0270 := TSF0270.Create(UniApplication);
  vSF0270.Parent:= Nil;
  UniSession.Synchronize;  //<- the form is shown
  vSF0270.Close;           //<- this does not hides the form
  vSF0270.x:= 'bla bla bla';
  UniSession.Synchronize;  //<- the form is still being shown
  sleep(5000);
  vSF0270.x:= vSF0270.x + 'x';
  UniSession.Synchronize;
  showmessage(vSF0270.x);  //<- the form is still being shown behind the message
  freeandnil(vSF0270);     //<- only here the form disappears

 

Link to comment
Share on other sites

On 2/15/2021 at 5:49 PM, Clipe Informática said:

FYI, i tried your suggestion and still the form is shown. That's how i made it

Hello,

You can adapt this code to your needs:

function window.show(sender, eOpts)
{
    this.setHidden(true);
}

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...