Home > JavaScript, Object Pascal, Smart Mobile Studio > IE 10, 11 and Edge patch for Smart Mobile Studio

IE 10, 11 and Edge patch for Smart Mobile Studio

Last week I posted a momentum scrolling base-control for Smart Mobile Studio. It was meant as an example only, written for the new RTL which wont hit the userbase just yet.

It was a bit unfair perhaps, but in all honesty – adapting it to the present RTL is child’s play, and one of the forum members did just that and got it working more or less instantly.

Sadly, it didnt work at all under Internet Explorer. While I am shocked that people actually use Internet Explorer in this day and age – not to mention Edge (or any of Microsoft browsers), I took a few minutes to check out what the fuzz was about.

Microsoft IE strikes again

ie-devil_03Turns out Microsoft has altered the vendor information quite radically the past 4 years. This also means that the Smart Mobile Studio startup code was unable to determine the browser above IE version 10 – and in such a case we always fall back on Mozilla.

But ofcourse, IE wont accept “moz” prefixed CSS3 instructions, so while the visual controls does indeed work – they produced no visual scroll feedback due to the wrong driver.

Patching the RTL to recognize IE, Trident and Edge builds

All you have to do is to replace a function in SmartCL.System.pas called w3_getIsInternetExplorer(). With the new code in place, your SMS applications should start to behave as normal under Microsoft’s browsers:

  • Create a blank new visual project
  • Right-click on SmartCL.System in your main-form’s uses clause
  • Select “open file at cursor” from the pop-up menu
  • Press CTRL + H to open up the search dialog
  • Enter “w3_getIsInternetExplorer” to locate the function
  • Delete the old function and paste in this code
function  w3_getIsInternetExplorer: Boolean;
var
  ua: variant;

  function IE_10_Or_Older: boolean;
  var
    msie: variant;
  begin
    asm
      @msie = (@ua).indexOf('MSIE ');
      @result = (@msie > 0);
    end;
  end;

  function IE_11: boolean;
  var
    trident: variant;
  begin
    asm
      @trident = (@ua).indexOf('Trident/');
      @result = (@trident > 0);
    end;
  end;

  function IE_Edge: boolean;
  var
    edge: variant;
  begin
    asm
      @edge = (@ua).indexOf('Edge/');
      @result = (@edge > 0);
    end;
  end;

begin
  asm
    @ua = window.navigator.userAgent;
  end;
  result := IE_Edge or IE_11 or IE_10_Or_Older;
end;

A small shim for older IE

In some IE builds (8 and 9 I seem to remember) there is also a problem with “element.addEventListner()”. Where both Firefox, Chrome, Safari, Opera and the myriad of webkit clones expects the plain event-name, IE expects the event names to be prefixed with “on”. This flies straight in the face of what every other browser vendor supports (Microsoft always have to screw up like this, sorry but I just think they act like spoiled, retarded children at times).

You might want to add this shim to the Initialization section of your application unit, just to be on the safe side:

initialization
begin
  asm
  if (typeof Element.prototype.addEventListener === 'undefined') {
    Element.prototype.addEventListener = function (e, callback) {
      e = 'on' + e;
      return this.attachEvent(e, callback);
    };
  }
  end;
end;
Advertisements
  1. June 11, 2016 at 5:04 pm

    I think w3_getIsSafari should be changed to:

    function w3_getIsSafari: Boolean;
    begin
    asm
    @Result = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
    end;
    end;

  2. August 29, 2016 at 4:15 am

    Also InternalInitVendorInfo function wrongly reports Edge as Chrome.
    That’s because Edge for his useragent has Chrome (together with Edge) listed so function will return bvChrome (not bvIE).
    It would be good if next SMS version would have this fixed.

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: