Recent

Author Topic: [SOLVED] Showmodal and return form state  (Read 810 times)

superc

  • Sr. Member
  • ****
  • Posts: 250
[SOLVED] Showmodal and return form state
« on: April 18, 2023, 10:23:31 am »
Hello,

on my program:
Code: Pascal  [Select][+][-]
  1. var
  2.    ts: TFw;
  3.    res: TModalResult;
  4. begin
  5.   try
  6.     ts := TFw.Create(self);
  7.     ts._productCode    := 'xyz';
  8.     ts._language       := 'en';
  9.     ts._productVersion := 1;
  10.     res := ts.ShowModal;
  11.     ShowMessage(IntToStr(res));
  12.   finally
  13.     ts.Free;
  14.   end;
  15. end;  
  16.  

I have to return a status to the modal form in order to understand if the user has pressed the 'ok' or 'abort' button
, but in the TFw form, on the abort button I wrote this code :
Code: Pascal  [Select][+][-]
  1.   Self.ModalResult:=mrAbort;
  2.   self.Close;  
  3.  
this on the ok button:
Code: Pascal  [Select][+][-]
  1.   Self.ModalResult:=mrOK;
  2.   self.Close;
  3.  

but on res variable i obtain same value, it is obvious that I am doing something wrong, what is the correct way to handle the return of a modal form?
Thanks in advance.
« Last Edit: April 18, 2023, 11:14:56 am by superc »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Showmodal and return form state
« Reply #1 on: April 18, 2023, 10:41:31 am »
You should assign to the Button a ModalResult like mrOK etc... and remove all buttonclick events, the modalresult will close form for you.
Small demo project attached.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

superc

  • Sr. Member
  • ****
  • Posts: 250
Re: Showmodal and return form state
« Reply #2 on: April 18, 2023, 11:14:40 am »
You should assign to the Button a ModalResult like mrOK etc... and remove all buttonclick events, the modalresult will close form for you.
Small demo project attached.

yes I remember now, thank you very much  :D

 

TinyPortal © 2005-2018