Jump to content
Sign in to follow this  

[FIXED] ShowDialog - anonymous procedure issue

Recommended Posts

When the following code is run within Chrome the code is run twice.

Simply place a tw3button on the form or create in code. In InitializeObject add the following

  W3Button1.onclick := procedure(sender:tobject) begin
    Application.showDialog('Click yes','Are you sure you want'+#13+' to click yes?',aoYesNo,
      procedure(const Dialog: TW3Dialog; const DialogResult: TW3DialogResult) begin

        if DialogResult = roYes then
          writeln('IN HERE');//myarray.count);

In the internal browser and in firefox we see a single "IN HERE". However, in chrome we get two reports.


Chrome also throws an error


index.html:83 Uncaught TypeError: Cannot read property 'Destroy' of undefined
    at Object.Free (index.html:83)

Share this post

Link to post
Share on other sites

hhmm, thanks for checking that Jarto. I have trie dit at home with Chrome and no problems. Two computers at work demonstrate the problem. I have just tried and taken a screen shot to show I am not mad ;)

I will see if I can figure out what the difference in location contributes.


You can see that "in here" was written once, then twice and then twice again. Along with an error message. I have this bug on two machines at work and not on my home computer - version 62 of  Chrome on all



index:4307 looks like


         TW3Dispatch.Execute(TW3Dispatch,function () {
            TObject.Free(Dialog$2);    <------------------------------- this one

Share this post

Link to post
Share on other sites

On that last "Uncaught TypeError" -line, you see a small arrow to the left. Can you click on that, so I can see the stack trace?

You need to show this debugger first and then trigger the error to get the trace.

Share this post

Link to post
Share on other sites

I think i can fix this.
From what i see above, i have used TW3Dispatch to kill the dialog after the main procedure has been closed.
As I look at it now, i realize that the garbage collector can actually eat the Dialog & BlockBox objects since our "free" code executes after the procedure has exited.
It would have been different had the dialog + blockbox been fields in a class, then the values would have been safely stored there -- but since they are local variables, the JS runtime gobbles them up on exit and they are in effect "NIL" when i try to access them 100ms later

Share this post

Link to post
Share on other sites

OK, I have issued a fix which should go out with the build later today or tomorrow (not my table so the manager has to deal with that). I noticed several minor mistakes. For instance, the callback "prepare" in the overloaded ShowDialog method never fired. Delayed callback failed because the method was a class method, marked as static, which means the variables are killed on exit (hence the bug above).

Everything is now moved into a normal class, TW3DialogManager, which is available from TW3CustomApplication (or just, application).
The Showdialog methods are still exposed as usual, so you dont need to change anything.

About adjusting a dialog

You asked earlier how to change the glyph and glyph color on a dialog. I must apologize because I did not know the callback didnt fire.
But the way you would do this is as such:

  W3Button1.OnClick := procedure (Sender: TObject)
      procedure (const Dialog: TW3Dialog)
        Dialog.Header.Caption := 'The header';
        Dialog.Text.Caption := 'The text!';
        Dialog.Glyph.GlyphType := lgtFontAwesome;
        Dialog.Glyph.GlyphColor := clWhite;
        Dialog.Glyph.GlyphId := 'fa-5x fa-exclamation-triangle';

      procedure (const Dialog: TW3Dialog;
      const DialogResult: TW3DialogResult)
        writeln("You picked:" + DialogResult.ToString());

The dialog contains a "glyph" child control, this is of type TW3GlyphContainer (so you must include the unit SmartCL.GlyphContainer if you want to play with this).

As you see you have properties for everything here, like GlyphColor. And you need to use the normal Font-Awesome CSS codes to pick the image you want. Simply visit: http://fontawesome.io/icons/ for a list of available glyphs, and set the code(s) as you like. The size is determined by "fa-5x" (5 times the ordinary size).

Note: You can also use this in labels. If you set the caption of a label or a button caption to: 

W3Label1.Caption := ' <i class="fa fa-free-code-camp" aria-hidden="true"></i> Hello world!';

You get a nice fire glyph before the text :)

The fix should be in circulation shortly -- cheers!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this