Author Topic: How to run a (command..) function from modeless dialog  (Read 108 times)

Rakesh Rao

  • Member
  • *
  • Posts: 25
How to run a (command..) function from modeless dialog
« on: September 21, 2021, 05:55:14 AM »

Dear Forum Users,

I am using BricsCAD V21 and trying to run a Lisp function from a modeless dialog. The Lisp function uses (command) function many times.

It seems to fail with the following error:

; error : during LISP function [Creator_O/Creator_O/Tree_Main#OnClicked] invoke from BRX/SDS interface,
          please check Lisp function definition and call arguments.

I have already set the event invoke property of the form to 1 (asynchronous) as per what I saw in some posts, and get the same error.

The function works perfectly when called manually from the command-line.

Any pointers would be deeply appreciated. I have volunteered to do a major job in OpenDCL and hope to get this through.

I have even tried setting the KeepFocus property to True and False, and both give me the same result (error).


Many thanks and Best Regards
Rakesh Rao

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 3059
    • Outside The Box
Re: How to run a (command..) function from modeless dialog
« Reply #1 on: September 21, 2021, 08:25:37 AM »
There are some events which must run synchronously (because the return value is required by the event handler). OnClicked should work asynchronously, so you might double check to make sure you are loading the correct project that has the form set to EventInvoke=1. An alternative solution is to make the event handler just call (dcl-SendString "THE_REAL_HANDLER\n") (defined as (defun C:THE_REAL_HANDLER '()) in my example), to then execute the asynchronous portion later, after the handler has returned.

Rakesh Rao

  • Member
  • *
  • Posts: 25
Re: How to run a (command..) function from modeless dialog
« Reply #2 on: September 21, 2021, 09:45:07 PM »

Thanks Owen, That worked, more or less. I need to test further.

Also, I just realized that if I make EventInvoke=1 (asynchronous), the callback function works only if it is preceded with a C:.

I normally like to have Lisp functions without a C:, b ut I found that  Creator_O/Creator_O/Tree_Main#OnClicked does not work but c:Creator_O/Creator_O/Tree_Main#OnClicked does work.

Am I doing something wrong?

The EventInvoke property is available both for the form and for the Tree Control. I have set it to 0 for the form and 1 for the Tree, and it worked for the moment.

What is the impact of changing the value  0/1 in the Form?

Many thanks & Best Regards
Rakesh Rao


owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 3059
    • Outside The Box
Re: How to run a (command..) function from modeless dialog
« Reply #3 on: September 22, 2021, 09:29:58 AM »
I believe the form property only affects form events, so setting it on the control is appropriate. Modeless dialogs are running in application context at the UI level, but using (command) requires to be running inside a command context, so that is why you can only make the event handler a command. It is then executed like any other command, in order to create your command context, then call your event handler from within the running command.