Jump to content

UniSweetAlert.execute without return


fiorilli

Recommended Posts

Hello, I am using unisweetalert and want to use the execute method to indicate a response, however I am creating the unisweet alert at runtime in a class responsible for generating message boxes, my code is as follows:


class function function TMessageUtils.UniSweetAlertQuestion(msg: string): boolean;
var
  sweetAlert: TUniSweetAlert;
begin
  sweetAlert := TUniSweetAlert.Create(nil);
  with sweetAlert do
  begin
    AlertType := atQuestion;
    html := msg;
    ConfirmButtonText := 'yes
    CancelButtonText := 'no';
    ShowConfirmButton := true;
    ShowCancelButton := true;
    title := string.Empty;
    AllowEscapeKey := false;
    AllowOutsideClick := false;
    InputType := ItNone;
  end;
  if sweetAlert.Execute then
    result := true
  else
    result := false
end;


at no moment the function enters if. 
I did some tests and found out that the problem happens because you are passing nil when creating the component, is there any way around this?

  • Upvote 1
Link to comment
Share on other sites

3 hours ago, fiorilli said:

Hello, I am using unisweetalert and want to use the execute method to indicate a response, however I am creating the unisweet alert at runtime in a class responsible for generating message boxes, my code is as follows:


class function function TMessageUtils.UniSweetAlertQuestion(msg: string): boolean;
var
  sweetAlert: TUniSweetAlert;
begin
  sweetAlert := TUniSweetAlert.Create(nil);
  with sweetAlert do
  begin
    AlertType := atQuestion;
    html := msg;
    ConfirmButtonText := 'yes
    CancelButtonText := 'no';
    ShowConfirmButton := true;
    ShowCancelButton := true;
    title := string.Empty;
    AllowEscapeKey := false;
    AllowOutsideClick := false;
    InputType := ItNone;
  end;
  if sweetAlert.Execute then
    result := true
  else
    result := false
end;


at no moment the function enters if. 
I did some tests and found out that the problem happens because you are passing nil when creating the component, is there any way around this?

Hello

You can use UniMainModule.MasterForm instead of nil

 

sweetAlert := TUniSweetAlert.Create(UniMainModule.MasterForm);

 

  • Like 1
  • 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...