Jump to content


Photo

Using FreeForm


  • Please log in to reply
15 replies to this topic

#1 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 14 February 2018 - 06:25 AM

Hello Friends,
I am trying to optimize my code
By using ultra lightweight technic sugested by Farshad on :
http://www.unigui.co...p/free-form.htm

But how to get this text, as i am using traditional showCallBack procedure on Asynchrone mode ?
Thx.
  • 0

#2 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5314 posts

Posted 14 February 2018 - 06:47 PM

Hi,

 

Can you explain a little more what you wanted ?!

 

Best regards,


  • 0

#3 delphidude

delphidude

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 233 posts
  • LocationNorway

Posted 14 February 2018 - 09:50 PM

You call the getText function, which creates the form, and on modalresult

then reads the public text property, which triggers the form's private getText

function, which reads the edit text and returns control to the app.

 

Interesting way of using a free form, indeed. I tested it and it works,

just remember to set the modalresult properties on the buttons...


  • 0

#4 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 15 February 2018 - 06:25 AM

Thank you friends,
Yes DelphiDude, that is the purpose.
But, in build 1434, the freeForm is showing and the program continue... don't stop onShowModal.
Maybe i forgot a property setting !?
I will test and come back soon.
Thx.
  • 0

#5 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 15 February 2018 - 08:56 AM

Mmm...

Could'nt get it  in 1434.

(not tested in 1424).

 

Do i forget something ?

@DD, here is a test Case.

 

Thx.

Attached Files


  • 0

#6 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 16 February 2018 - 10:13 PM

Hello  Friends,

 

I really block  !

 

@DD, any news about the testCase  ?

@DelphiDude, can you send here a zip of your test ?

 

Thank you in advance.


  • 0

#7 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5314 posts

Posted 17 February 2018 - 11:24 AM

Hi,

 

In this case you should use EnableSynchronousOperations = True


  • 1

#8 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 17 February 2018 - 11:41 AM

Hello Farshad,
As i don'nt like EnableSynchronousOperations,
I am trying to enable it at runtime when i need a freeform, and comeback to False after modalshow.
But this rise an exception :
"Blocking function showmodal..."

So, Is there a way to use your leightweight technic also in a traditional callback show (synchonous = False) ?
Thx.
  • 0

#9 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 17 February 2018 - 02:07 PM

So, Is there a way to use your leightweight technic also in a traditional callback show (synchonous = False) ?
 

procedure TMainForm.UniButton2Click(Sender: TObject);
var Frm: TUniForm1;
begin
  Frm := TUniForm1.Create(UniApplication);
  Frm.ShowModal(
    procedure (Sender: TComponent; Res: Integer)
    begin
      if Res = mrOK then begin
        UniMemo1.Lines.Add(Frm.UniEdit1.Text);
      end else begin
        UniMemo1.Lines.Add('!Cancel!');
      end;
    end
  );
end;

  • 1

#10 Farshad Mohajeri

Farshad Mohajeri

    Administrator

  • Administrators
  • 10551 posts

Posted 17 February 2018 - 02:20 PM

Hello Farshad,
As i don'nt like EnableSynchronousOperations,
I am trying to enable it at runtime when i need a freeform, and comeback to False after modalshow.
But this rise an exception :
"Blocking function showmodal..."

So, Is there a way to use your leightweight technic also in a traditional callback show (synchonous = False) ?
Thx.

 

Then you must use traditional callbacks which are recommended by default.


  • 0

#11 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 17 February 2018 - 03:16 PM

Thank you Friends,
@Oliver : BRAVO very nice !

Best regards.
  • 0

#12 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 18 February 2018 - 10:44 AM

Hello Oliver,

 

procedure TMainForm.UniButton2Click(Sender: TObject);
var Frm: TUniForm1;
begin
  Frm := TUniForm1.Create(UniApplication);
  Frm.ShowModal(
    procedure (Sender: TComponent; Res: Integer)
    begin
      if Res = mrOK then begin
        UniMemo1.Lines.Add(Frm.UniEdit1.Text);
      end else begin
        UniMemo1.Lines.Add('!Cancel!');
      end;
    end
  );
end;

 

Do we have to free the temporary  variable  Frm  ?

Where to put  :   Frm.Free   ?

Or is it automatically free  ?

 

Thx


  • 0

#13 Oliver Morsch

Oliver Morsch

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 274 posts
  • LocationGermany

Posted 18 February 2018 - 11:02 AM

Do we have to free the temporary  variable  Frm  ?

Where to put  :   Frm.Free   ?

Or is it automatically free  ?

 

 

Set Form2.FreeOnClose to true; then it is automaticly freed. Otherwise you must use .Free in the callback procedure after doing your stuff.


  • 1

#14 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 18 February 2018 - 01:10 PM

Thank you very much Oliver,
I prefer the first method :
By default freeForm has FreeOnClose = True.
So, we don't care about memoryleak.

@Farshad, it's a high flying
i think, it's necessary to complete the online doc by all these important points.
Not obvious !
Thanks to all of you :)
  • 0

#15 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5314 posts

Posted 18 February 2018 - 02:24 PM

Hi,

 

The owner of the free form is not the global application, but the instance handling the current session.

Notice also that the form (frm) is automatically released (FreeOnClose is true and a value was assigned to ModalResult).

The variable itself will be released after going out-of-scope (when exiting the function GetText).

http://www.unigui.co...p/free-form.htm


  • 0

#16 Abaksoft

Abaksoft

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 637 posts
  • LocationAlgeria

Posted 18 February 2018 - 02:49 PM

Thank you DD,
Decidedly this topic is not over.
What sugest Oliver is not the same :
- on the online doc, variable frm is declared on the freeform. It's easy to understand that all will freed on closing the freeForm (FreeOnClose = True).
- on the code above (oliver) the frm is declared in a Mainform procedure. That why i couldn't understand the automatic free.
Thx again :)

Edited :
The code below don't use the online lightweight technic, but a classical way (frm.uniEdit.Text not the tip property Text sugested on online doc).
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users