Calling delphi function from javascript

Issue #2 resolved
Former user created an issue

I can call the Delphi function from the HTML as in the example. But when I put the Delphi function into a javascript function it does not work. See Below.

function responseTimer()
{
    delphi:PlaySound(); //beep.play();
    rspTime++;

    httpGet("get_is_alarm_rsp_acked.cgi?AlarmId="+alarmResponse.AlarmId, function()
    {
        if(this.responseText == "TRUE")
        {
            if (TID !== undefined)
                clearTimeout(TID);
            showPage("timer", "monitor");
            startMonitor();
        }
    });

    document.getElementById("counter").innerHTML =
        parseInt(rspTime / 60) + ":" + ("0" + rspTime % 60).substr(-2);
    if (rspSetting.RspTimeout == rspTime)
    {
        httpPOST_JSON("set_alarm_rsp_values.cgi", alarmResponse);
        showPage("timer", "monitor");
        startMonitor();
    }
    else
        TID = setTimeout(responseTimer, 1000);
}

Comments (6)

  1. 細川淳

    Your JavaScript is incorrectly written.
    For example, please write as follows.

    location = "delphi:PlaySound();";
    
  2. The Programmer

    document.location = "yourorgScheme:YourDelphiProcedure(Parameters1, Parameter2, Etc)";

    This code works

    #! Javascript

        document.location = "yourorgScheme:ReadManualLocation(''"+latitude+"'',''"+longitude+"'')";
    

    #! Delphi

    procedure TForm1.ReadManualLocation(latitude,longitude: String);
    begin
    ShowMessage(latitude);
    ShowMessage(longitude);
    end;
    

    #! Notice the parameters during call , (SINGLEQUOTE SINGLEQUOTE DOUBLEQUOTE + latitude + DOUBLEQUOTE SINGLEQUOTE SINGLEQUOTE ,

    #! Notice it also works with one single quote only , (SINGLEQUOTE DOUBLEQUOTE + latitude + DOUBLEQUOTE SINGLEQUOTE ,

    #! JavaScript single quote

    function onMapClick(e) 
    { 
         // get selected latitude
         var latitude= e.latlng.lat;
         // get select longitude
         var longitude= e.latlng.lng; 
        document.location = "yourorgScheme:ReadManualLocation('"+latitude+"','"+longitude+"')";
    
        myMarker.setLatLng(e.latlng);
    }
    

  3. Log in to comment