Jump to content

how to make set focus on button messagedlg when the dialog show?


jemmyhatta

Recommended Posts

Hello friends,  how to make set focus on button messagedlg when the dialog show?

 

Hi,

 

If I understand correctly, one of the ways

  (If you do not create a "Message" programmatically on JS) ...

/*
* Ext.MessageBox internal button array:
*
* [0] 'OK'
*
* [1] 'Yes'
*
* [2] 'No'
*
* [3] 'Cancel'
*/

1. 

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  UniSession.AddJS('Ext.override(Ext.MessageBox, {defaultButton: 3});');
end;

2. Can also be changed in runtime:

procedure TMainForm.UniButton8Click(Sender: TObject);
begin
  UniSession.AddJS('Ext.override(Ext.MessageBox, {defaultButton: 2});');
  MessageDlg('mbYesNoCancel', mtConfirmation, mbYesNoCancel, DCallBack4);
end;

Try ..

 

Best regards.

  • Upvote 1
Link to comment
Share on other sites

Hi,

 

If I understand correctly, one of the ways

  (If you do not create a "Message" programmatically on JS) ...

/*
* Ext.MessageBox internal button array:
*
* [0] 'OK'
*
* [1] 'Yes'
*
* [2] 'No'
*
* [3] 'Cancel'
*/

1. 

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  UniSession.AddJS('Ext.override(Ext.MessageBox, {defaultButton: 3});');
end;

2. Can also be changed in runtime:

procedure TMainForm.UniButton8Click(Sender: TObject);
begin
  UniSession.AddJS('Ext.override(Ext.MessageBox, {defaultButton: 2});');
  MessageDlg('mbYesNoCancel', mtConfirmation, mbYesNoCancel, DCallBack4);
end;

Try ..

 

Best regards.

 

Hi,

 

Thanks for telling me the way. It works!

 

Another question then, how it works if not in the mainform? Can you tell me how to do that too? Let say in UniForm1. I already tried to call unisession from other form but it can't be called even when i already added "use unit" into  that uniform1. Anything i missed, or there's some trick for that case?

 

Thanks in advanced, best regards.

Link to comment
Share on other sites

I want to share my experience related to this matter.

 

Something odd but true, insignificant but annoying.

 

Please check the pictures below:

 

Picture 1 (Listing Code Ok.png):

This is part of the coding in the event "OnExit".

 

If the program executed, the steps becoming like this:

 

Picture 2 (Step1.jpg):

The module to view the data where people could see and choose the relevant data for editing and/or deleted. After got the necessary data, I double click the data which is located on that grid.

 

Picture 3 (Step2.jpg):

The selected data will move to the module which function is to edit or delete. then, click the button "hapus" ("delete"), then all selected data will appear to each columns according to the data before delete. Cursor set focus is on the "NoBukti" column and then if we do some "OnExit" from the "NoBukti" column the "messagedlg" will be appeared.
 

Picture 4 (Step3.png):
The dialog is appeared, and set focus on button messagedlg. Success.

Picture 5 (Listing Code Trouble.jpg)
I add up some code on that part.

Picture 6 (Step 3 Trouble.png)

After adding some codes there, I re-run the applications again like the sequences before, but the result  I've got is the dialog is not set focus on button messagedlg.

The codes I've added up more or less have same function, just move the data to the designated columns. Is it bugs or what? Please update me, let me know where to fix and how to do that. Thank you.

 

Best Regards
 

NB: While waiting for your kind reply, I'll still searching the solution for this problem myself.

 

post-2205-0-08220900-1420596050_thumb.jpg

post-2205-0-29006400-1420596069_thumb.jpg

post-2205-0-29505500-1420596075_thumb.jpg

post-2205-0-38606400-1420596080_thumb.png

post-2205-0-10938500-1420596263_thumb.jpg

post-2205-0-25004000-1420596394_thumb.png

Link to comment
Share on other sites

  • 3 weeks later...

Hello,

 

Sorry for the late reply, I've got many things to do lately (works).

Below I attached source code of my simple test case. Please review and correct me, where I've made mistakes? Or, is there some sort of magic trick on handling the MessageDlg? Thanks in advance.

 

Best Regards.

Tes.zip

Link to comment
Share on other sites

Hi,

 

Try:

procedure TMainForm.BSaveClick(Sender: TObject);
begin
if strlen(pchar(trim(EKode.Text)))=0 then
  begin
  UniSession.AddJS('Ext.override(Ext.MessageBox, {defaultButton: 0});');
  Messagedlg('Kolom Kode Harus Di isi !!!', mtwarning, [mbOk], CallBack);
  
  //EKode.SetFocus;       <-----------------

  Exit;
  end;

if strlen(pchar(trim(ENama.Text)))=0 then
  begin
  UniSession.AddJS('Ext.override(Ext.MessageBox, {defaultButton: 0});');
  Messagedlg('Kolom Name Harus Di isi !!!', mtwarning, [mbOk], CallBack);
  
  //ENama.SetFocus;       <-----------------

  Exit;
  end;

.....

Best regards.

Link to comment
Share on other sites

Is it the proper way to use messagedlg? Below that command, nothing else than "exit" function?  May I know the reason why messagedlg on unigui behaves like that? imho(in my humble opinion), the future development of unigui could see this matter too.

 

Best Regards,

Link to comment
Share on other sites

  • 2 years later...

Frustating.. 

 

Hi,

 

Try:

procedure TMainForm.BSaveClick(Sender: TObject);
begin
if strlen(pchar(trim(EKode.Text)))=0 then
  begin
  UniSession.AddJS('Ext.override(Ext.MessageBox, {defaultButton: 0});');
  Messagedlg('Kolom Kode Harus Di isi !!!', mtwarning, [mbOk], CallBack);
  
  //EKode.SetFocus;       <-----------------

  Exit;
  end;

if strlen(pchar(trim(ENama.Text)))=0 then
  begin
  UniSession.AddJS('Ext.override(Ext.MessageBox, {defaultButton: 0});');
  Messagedlg('Kolom Name Harus Di isi !!!', mtwarning, [mbOk], CallBack);
  
  //ENama.SetFocus;       <-----------------

  Exit;
  end;

.....

Best regards.

I got same problem.. that code sometimes work, sometimes no action..  Finally i use native JS "alert" to display message box

Link to comment
Share on other sites

×
×
  • Create New...