Jump to content

MessageDlg problems


petr.nehez

Recommended Posts

Can someone give me a solution how to pass a callback function to TExtMessageBoxSingleton's methods like Alert etc?

I'd like to have customized message dialogs with callbacks but I don't know how to do it.

 

Nevermind, I've already found a solution which works:

      MF := UniApplication.UniMainModule.MainForm;
     if (MF <> nil) and (MF is TUniForm) and (TUniForm(MF).WebForm <> nil) then
     begin
       EF := TUniExtFormAccess(TUniForm(MF).WebForm);
       CBF := TCallbackExtFunction.Create(aCallback);
       CBF.FAjaxIntercept := EF.AjaxParamIntercept;
       CBF.FAjaxParamListIntercept := EF.AjaxParamListIntercept;
       CBF.Ajax('callback', ['ButtonID', '%0'], True);

...

procedure TCallbackExtFunction.HandleEvent(const AEventName: string);
var
 MR: Integer;
begin
 if SameText(AEventName, 'callback') then
 begin
   if Assigned(FCallback) then
   begin
     if (ButtonsDict = nil) or not ButtonsDict.TryGetValue(ParamAsString('ButtonID'), MR) then
       MR := mrNone;
     FCallback(MR);
   end;
   FCallback := nil;
 end
 else
   inherited;
end;

initialization
 ButtonsDict := TTextDictionary<Integer>.Create;
 ButtonsDict.AddOrSetValue('ok', mrOk);
 ButtonsDict.AddOrSetValue('cancel', mrCancel);
 ButtonsDict.AddOrSetValue('yes', mrYes);
 ButtonsDict.AddOrSetValue('no', mrNo);

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...