Jump to content

Showmodal in Web Mode


Jaume

Recommended Posts

Hi, in VCL I usually had this kind of function in units that allow me to had one block of code for opening showmodal forms that are used for select one row in a grid and return an ID. This block of code can be used for a lot of forms, so it's not repeted. 

 

For example:

 

function choose_city() : integer;
var   f_Cities: TCities;
begin
result:=0;
     f_Cities := TCities.Create(nil);
     if f_Cities.init() then begin


          if f_Cities.ShowModal = mrok then begin
              result:= f_Cities.return_city_id;
         end;


     end;
f_Cities.free;
end;

In WEB mode this can't be done, because showmodal is not blocking. So do i have to repete this code in every form for every callback? Is there any better sugestion to help to reproduce the same behaviour in WEB mode with common code?

 

 

Thank you very much for your help.

 

Link to comment
Share on other sites

Thank you.

 

I've seen the demos before of course, but that is not what i asked for.

 

If I translate this:

function choose_city() : integer;
var   f_Cities: TCities;
begin
result:=0;
     f_Cities := TCities.Create(nil);
     if f_Cities.init() then begin


          if f_Cities.ShowModal = mrok then begin
              result:= f_Cities.return_city_id;
         end;


     end;
f_Cities.free;
end;

for 

 

function choose_city() : integer;
var   f_Cities: TCities;
begin
result:=0;
     f_Cities := TCities.Create(nil);
     if f_Cities.init() then begin

     if f_Cities.ShowModal(procedure(Result:Integer)
        begin
          if Result = mrok then 
          result:= f_Cities.return_city_id;
         end);
      end;
end;

this does not compile because in anonymus callbacks can't use the result of the funcion. So this makes the code not useful for a common purpose. So every time that i need to call choose_city i must re-code it again, but with the specific anonymous method.

 

Also, if i do it without anonymous method, and passing the callback as a parameter to choose_city(), i can't use the f_Cities variable from the callback procedure. 

 

So i asked if there is any idea or stardard method to code this type of VCL style functions with WEB mode, as i'm not used to this.

 

Thank you very much.

 

 

Link to comment
Share on other sites

Jaume,

 

In form form TCities create callback, example:

 

procedure TCities.returnKeyCities(Sender: TObject);
begin
      ModalResult:=<your key return>; 
end;
 
 

function Form.choose_city() : integer
      var   f_Cities: TCities;

             returnKey:integer;
begin
     f_Cities := TCities.Create(nil);
     f_Cities.init();

     f_Cities.ShowModal(

        procedure(result: Integer)
        begin
             returnKey:=result; //result already contains the value f_Cities.return_city_id;

        end);

 

 
PerjanBR
Link to comment
Share on other sites

Thanks for the answer.

 

Anyway, as i see I will have to re-code the funcion to every form.

 

My aim was to code this:

 

function Form.choose_city() : integer
      var   f_Cities: TCities;

             returnKey:integer;
begin
     f_Cities := TCities.Create(nil);
     f_Cities.init();

     f_Cities.ShowModal(

        procedure(result: Integer)
        begin
             returnKey:=result; //result already contains the value f_Cities.return_city_id;

        end);

 

into a Unit and use it from multiple forms. But as I imagine, i can't do it with callbacks, so i will have to re-code the same pice of code in every form.

 

If anyone has more ideas, please let me know.

 

Thank you.

Link to comment
Share on other sites

If anyone has more ideas, please let me know.

 

Instead of using a (global) function "choose_city(): integer" which returns an integer, I would use a (global) procedure "choose_city(DoAfterChooseCity: TDoAfterChooseCityProc)" which gets an anonymous procedure that contains the code to do after the city was choosen. And then call:

choose_city(procedure(CityCode: Integer)
   begin
     //do this after the user has choosen a city...
   end);
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...