Jump to content

Using Delphi name OR .JSName in a JS function?


ZigZig
 Share

Recommended Posts

Hi everybody,

 

When using AddJS() to execute some JavaScript on client side, it seems that we can concatenate SomeComponent.JsName to a JS function: MyComponent.JsName+'.someFunction()', or directly use its Delphi name : 'MainForm.MyComponent.someFunction()' : 

UniSession.AddJS(SomeComponent.JSName+'.someFunction();');
UniSession.AddJS('MainForm.SomeComponent.someFunction();');

Ex :

UniSession.AddJS(UniStringGrid1.JSName+'.store.suspendEvents();');
UniSession.AddJS('MainForm.UniStringGrid1.store.suspendEvents();');

 

Both seem to work perfectly. Is it right?

What is the difference? Is there a best practice?

 

 

Thanks a lot!

Link to comment
Share on other sites

I found that in some cases delphi name doesn't work. Maybe I am not using the Delphi name correctly, but here is my experience: recently I had to call some functions of the main form when as soon comes up, and I had to use its JSName, which I have found to be (unsurprisingly :)) "O0"

 

Here is an example
 

Form1.toFront(); //doesn't work
O0.toFront(); //its JSName, WORKS

Also, you need to use the JSName when firing (client side) the Ajax events.

Ajax=1&IsEvent=1&Obj=O0&Evt=activate&this=O0&_S_ID=zX4rfeDert67Gbe&_seq_=0
Link to comment
Share on other sites

  • Administrators

 

I found that in some cases delphi name doesn't work. Maybe I am not using the Delphi name correctly, but here is my experience: recently I had to call some functions of the main form when as soon comes up, and I had to use its JSName, which I have found to be (unsurprisingly :)) "O0"

 

Here is an example

 

Form1.toFront(); //doesn't work
O0.toFront(); //its JSName, WORKS

Also, you need to use the JSName when firing (client side) the Ajax events.

Ajax=1&IsEvent=1&Obj=O0&Evt=activate&this=O0&_S_ID=zX4rfeDert67Gbe&_seq_=0

 

Some components have sub components.

 

For example:

 

Form1.form

Form1.window

 

You can see this from ClientEvents dialog.

Link to comment
Share on other sites

  • 3 years later...

I meant,

is it possible to launch 'ClientEvents ' fonctions inside of Delphi code by this way ?

For instance, if I want to select a specific cell in a uniDBGrid, could I call the function as I wrote above ?

If so, how can I pass parameters ?

(is it more limpid now ?  ^_^)

Link to comment
Share on other sites

I got two use case in my grid:

  1. Multiselection Option: After a grid refresh, I would like to keep the same selected row. But arrows are not controling movement anymore, you have to click first on grid body ....
  2. CellSelection Option: Same problem but different approach!

First of all, how could I keep "focus" on my body grid (I actually got the focus as the onKeyDown event is fire, but arrows are not responding) and then retrieve selected row/cell ?

Any workaround ? :(

Link to comment
Share on other sites

Hello everyones!

 

I manage to do what I want but I still have two question:

 

Is the initialization of RecNo to 0 native on grid while refreshing the grid ? How could I override that in order to keep focus after a reconstruction of grid (in order to change grid options) or after grid refresh ?

Link to comment
Share on other sites

No worries! (:

 

The use case is as following:

 

you're in a uniDBgrid with row 4 selected, and you apply a grid refresh. After the refresh, the row number 0 will constatnly be selected and previously selected row will be lost. How can I override this behavior ? :o

Link to comment
Share on other sites

Hi,

 

Well, you can try this solution, for example:

 

1.

public
    { Public declarations }
    SavePlace: TBookmark;
  end;

2. UniDBGrid1 -> ClientEvents -> ExtEvents -> store.beforeload:

function store.beforeload(store, operation, eOpts)
{
    ajaxRequest(store.grid, '_beforeload', [])
}

3. UniDBGrid1 -> OnAjaxEvent:

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = '_beforeload' then
  begin
    if Assigned(SavePlace) then UniDBGrid1.DataSource.DataSet.FreeBookmark(SavePlace);
    SavePlace := UniDBGrid1.DataSource.DataSet.GetBookmark
  end;

end;

4. UniDBGrid1 -> OnAfterLoad:

procedure TMainForm.UniDBGrid1AfterLoad(Sender: TUniDBGrid);
begin
  Sender.DataSource.DataSet.GotoBookmark(SavePlace);
end;

Best regards,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...