Tuesday, May 1, 2012

Delphi-like MessageDlg in Javascript with jQuery

As you may already know, the good old MessageDlg function in Delphi is not available for web applications, so you're done to a few options: I've created my own MessageDlg function that is very close to the Delphi function, however, the dependencies are jQuery and jQuery UI
function MessageDlg( text, type, buttons, callback ) {
  /* code */
  • text: text to be displayed
  • type: dialog type, i.e. Information, Confirmation, Warning, Error
  • buttons: array of button types to be added on the dialog, ala delphi, i.e. [mbOK, mbYes, mbNo]
  • callback: function to be called when the user clicks a button, the function gets a integer parameter passed which is equal to the button type, i.e. mbOK = mrOK
Here's the code: filename.js

as you can see, the core of the function doesn't require that much code, however, I've added a few effects here and there to make it more eye pleasing and to be flexible, now the css part: filename.css

that's quite a bit of css for something so simple that could have been achieved using a table element, but hey, it works, also, it allows you to tweak things the way your heart dictates. Checkout http://code.google.com/p/delphigeist-javascript-stuff/ for code and other future stuff.


  1. Smart mobile have an iOS dialog built into it, you can find it under TW3CustomApplication.

  2. @$ABBA if you look at the code, you'll see that this is a very trivial task, I would have been very surprised if smart didn't have it...


Blogroll(General programming and Delphi feeds)