Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

Using the OLE.ExecuteCmd property in a Hyperlink control

I have added an SRP.Hyperlink.1 control to a window that has several other hyperlink controls (which may, or may not, be material). This particular hyperlink is a request to go to a browser and call MapQuest. The process to parse the data and send the string to MapQuest works OK when it actually happens. The problem is that the user has to click the Hyperlink control twice for the process to work unless it is a new record. Following is the actual code that calls the OLE.ExecuteCmd property:
OnClick.HYP_MAPQUEST: CallString = "http://www.mapquest.com/maps?address=" DelStreet = Trim(Get_Property(@Window:".EDB_STREET","TEXT")) DelCity = Trim(Get_Property(@Window:".EDL_CITY","TEXT")) DelSt = Trim(Get_Property(@Window:".EDL_DELIVERY_STATE","TEXT")) DelZip = Get_Property(@Window:".EDL_DELIVERY_ZIP","TEXT")[1,5] If DelStreet and DelCity and DelSt and DelZip then Swap CRLF$ with " " in DelStreet Swap " " with "+" in DelStreet CallString:= DelStreet If Index(DelCity," ", 1) then Swap " " with "+" in DelCity end CallString:= "&city=":DelCity:"&state=":DelSt:"&zipcode=":DelZip:"&redirect=true" Set_Property(@Window:".HYP_MAPQUEST", "OLE.ExecuteCmd", CallString) end else Mesg = "You must have entered the complete delivery address to display MapQuest." Msg(@Window, Mesg) end return
I have used messages and the debug command to satisfy myself that this code is accessed on the first click the user makes - i.e. the "OnClick" event fires and this section of the code is activated, but the exit to the browser doesn't occur until the second click. Why?

Comments

  • Hi Jan,

    I think I understand what is happening here. The ExecuteCmd property is designed so that when you click on the HyperLink control it will execute the command automatically without using the OnClick event. That is, the ExecuteCmd property and the OnClick event are meant to be mutually exclusive.

    In your case, the first time you click on the HyperLink control the ExecuteCmd property does not have the correct command so it will not work as expected. Yet, the OnClick event fires and this updates the ExecuteCmd property correctly. So the second time you click on the HyperLink control it works.

    You have two choices: 1.) Make sure the ExecuteCmd property is updated properly prior to clicking on the HyperLink control or 2.) Don't use the ExecuteCmd property at all and launch the browser command within the OnClick event using another technique.

    The first option might be more work than is worth it since you would have to update the ExecuteCmd property whenever a relevant data control is modified (e.g., state, city, zip, etc.) The second option can be done using the ShellExecute function. Here is an example of the syntax:
    hwnd = Get_Property(@Window, "HANDLE") showCmd = 0 rv = ShellExecute(hwnd, 'open':\00\, "http://www.srpcs.com":\00\, "":\00\, "":\00\, showCmd)
  • OK. I understand what you are saying about the work arounds, and clearly the second is the better option. However, for my future understanding, I don't understand how something executes without an event. If the user clicks on the HyperLink control and the commuter routine doesn't have the ExecuteCmd property in the OnClick Event, where is it found?
  • Jan,

    Think of the ExecuteCmd property like a QuickEvent. It is intended to be a way to conveniently launch commands (like website addresses) without you having to write a lot of code. Normally you would update the ExecuteCmd property during the CREATE event of the form or perhaps use the Property dialog box from the Form Designer to update it. That way the command just executes when the user clicks on the link.

    In your case, you have to do something akin to a script event because the command itself is dynamic.
Sign In or Register to comment.