Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How call a procedure when user clicks TIWURL
#1
I'm writing an IntraWeb 14 application in Delphi and I want to reset and enable my input form when the user clicks on the URL to the instructions page.

However, TIWURL does not have an OnClick or OnAsyncClick event.  OnAsyncClick shows up via Code Completion, but I can't actually access and use it.  I know that there is an OnClick event in the ScriptEvents property, but I know nothing of Javascript and have no idea of how to write a script to call my Delphi code procedure.  My best guess is that I need to define a callback function, but I have no idea of how to call it via Javascript, and even better, how to pass a parameter back to Delphi from Javascript.

Does anyone know how to do this?  A simple example would be awesome!

Thanks in advance,

George
Reply
#2
(05-24-2022, 08:22 PM)DEKETO Wrote: I'm writing an IntraWeb 14 application in Delphi and I want to reset and enable my input form when the user clicks on the URL to the instructions page.

However, TIWURL does not have an OnClick or OnAsyncClick event.  OnAsyncClick shows up via Code Completion, but I can't actually access and use it.  I know that there is an OnClick event in the ScriptEvents property, but I know nothing of Javascript and have no idea of how to write a script to call my Delphi code procedure.  My best guess is that I need to define a callback function, but I have no idea of how to call it via Javascript, and even better, how to pass a parameter back to Delphi from Javascript.

Does anyone know how to do this?  A simple example would be awesome!

Thanks in advance,

George

Hi George,

it is very simple to implement.

This is what you add to your onClick event in ScriptEvents property:

It is basically 1 line of very simple JavaScript. The first parameter is the name of your callback (the one that you will declare in your Delphi code, ahead), and the second is a string containing one or more parameters. Each parameter should be like name=value, separated by an ampersand &. Very simple.

Code:
ajaxCall("MyCallback", "param1=this is a string parameter&param2=2");


Now, in your Delphi code you do this:

1- Declare MyCallback method such as:

Code:
type
  TIWForm1 = class(TIWAppForm)
    IWURL1: TIWURL;
    procedure IWAppFormCreate(Sender: TObject);
  private
    procedure MyCallback(EventParams: TStringList);
  public
  end;

implementation

{$R *.dfm}

procedure TIWForm1.MyCallback(EventParams: TStringList);
var
  Param1: string;
  Param2: Integer;
begin
  Param1 := EventParams.Values['Param1'];
  Param2 := StrToIntDef(EventParams.Values['Param2'], -1);
end;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  WebApplication.RegisterCallBack('MyCallback', MyCallback);
end;

You can give name the callback differently, of course.

Please let me know if you need more info about this
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)