How to kill the focus of Microsoft Word™ document window? - delphi

I'm developing a Word addin in Delphi, on a task pane I put a Virtual treeview, in the OnFocus event of the Virtual Treeview I call Word to insert a file into the current Word document via method ActiveDocument.Range.InsertFile, but this operation will put the input focus back to the Word document window, so finally in this event handler I call TreeView.SetFocus to set the focus back to the treeview, this works except that the Word document window still has a unblinking caret shown.
I tried sending the WM_KILLFOCUS windows message to the handle of the Word document window but no luck. Any hints? Thank you in advance!

You can try to call Application.BringToFront or Application.MainForm.BringToFront.

Related

Jquery Select2 multiselect with Dragon NaturallySpeaking

I have implemented a select2 multiselect for list of states in a application, and it works fine using typing the state names. But with Dragon NaturallySpeaking software if you speak in select2 to select a state, it only show the last char of what you spoke and do not autosearch, you have to press space to see the whole text and then press backspace to start the search, looks like some event does not fire when you speak than type. Not sure if there is any solution that I can try. I have tried to fire the change event manually.. but not working !
Since the select2 box is not Select and Say, you probably need to dictate into the dictation box and transfer it over. Or, write a script to take in the dictation, convert it to what you need, and then paste it to clipboard. Then go over to box and paste from clipboard. Let us know what worked . . .
I have added a check if the selected element class is select2-search__field then I trigger a $(activeElement).trigger('change') in that element. that seems doing the job

TDBrichedit displays plain text rather than rich text

The context is that I am maintaining an application running on delphi 7 with the BDE. I programmatically assign dbricheditcontrols' datafields to allow users to edit rtf documents. When the relevant forms open, the unformatted text is displayed and then once say the person moves onto the next document, suddenly the rich text kicks in; I suspect it must be an initialisation problem of sorts, but what am I missing; could not locate a solution online.
Thanks
Ordinarily, I would not post an answer to a q which states
I programmatically assign dbricheditcontrols' datafields to allow users to edit rtf documents
but fails to include the code that you are using - you should have provided an MCVE (see https://stackoverflow.com/help/mcve).
However, what you say sugggests that you may be going about what you are trying to do the wrong way. You say you are using a TDBRichEdit component, but if you are using it correctly, it should not require any programmatic assignment of datafields to do it: you simply need to connect the component to the TTable or TQuery you are using via a TDataSource component, and configure the DBRichEdit to access whatever field of the TTable/TQuery that stores the richedit text. That can be done a design time using the Object Inspector in the IDE to set properties and does not require any code.
So, it seems to me that either you are not using the DBRichEdit correctly, or you are trying to do something that you have not explained in your q.
You can satisfy yourself that a DBRichEdit works automatically, without needing to load or save its contents in code, as follows:
Open the FishFacts demo
Add a TDBNavigator and a TDBRichEdit to the form. Set the DataField property of DBRichEdit1 to Notes.
Set the ReadOnly property of Table1 to False. Then set Table1's Active property to True.
Compile and run the project. While it's running
Start WordPad.Exe and create a bit of richtext in it. Copy it to the clipboard. Click the Save speedbutton of DBNavigator1.
Paste the richtext into DBRichEdit1.
You should find that you can navigate away from and back to the edited record and the richtext will be automatically reloaded.
Also, the following code works fine for me to load the Notes field from an .Rtf file
procedure TForm1.Button1Click(Sender: TObject);
begin
Table1.Edit;
TMemoField(Table1.FieldByName('Notes')).LoadFromFile('D:\test.rtf');
end;
and does not initially display the unformatted text as you describe. So I'm fairly sure you problem is arising in code of yours that you haven't shown us.
Btw, the only reason I am posting this as an "answer" is that there is more to say than will comfortably fit in a comment.

Using WM_SETFOCUS and WM_KILLFOCUS

In Delphi, I have two edit boxes and a button.
Edit1 is selected by default. I want to change focus using messages. But if I do as below, it all gets messed up with selection ranges in both edits, caret in the wrong box etc.
The reason I'm using messages is so that I can control focus in an external application. This seems to work, up to a point but clearly, the windows internal state is a bit scrambled. I don't have the source for the external program.
procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(edit1.handle,WM_KILLFOCUS,0,0);
PostMessage(edit2.handle,WM_SETFOCUS,0,0);
end;
... So can it be done? Am I missing a message?
WM_SETFOCUS and WM_KILLFOCUS are both notification messages that Windows sends to window handles when they receive and lose input focus, respectively, and you should not post those yourself. Instead, simply call SetFocus(edit2.handle) or edit2.SetFocus() to set the focus.
If for some reason you can't do that synchronously from your button click handler, you can post a custom message to a local message handler in your own form and make the SetFocus call from that message handler.

callback for twebbrowser delphi

I was wondering how i could make a callback function for the twebbrowser in delphi. I want it to recognize which input or edit box i am clicking in with the mouse..... any ideas?
As requested, hereby the update of the question, the user workflow.
The user would
1. select the inputfield on the twebbrowser by mouse. (the program would see what the information is about this inputfield(value, id, etc.....)
2. fill in the field with prefered information (name, password, whatever really)
At the same time this text is linked back into a memo box. That whould be the start, if i understand this it would be a good beginnning.
Will this code help you?
http://www.delphidabbler.com/articles?article=22&part=4#calling-delphi
The article is about calling Delphi-code from JavaScript.

Delphi memo box won't capture Return key

I have an application with two forms, both are dialogs and they both have memo boxes in them and they both have an OK button on them, however one dialog behaves differently from the other - if I am in the memo area and i type something and then press enter, the form closes but in the other form it goes to the next line in the memo (this is how I want it to behave).
I don't know how to fix the other form so that pressing enter inside the memo does not close it but makes it go to the next line. I even copied the memo component from the 'good' to the 'bad' form and it still does that, also compared the form properties but they are the same! Any idea why this is happening?
Two possibilities:
1) The Memo needs to have the WantReturn in order for the memo itself to process the RETURN key.
2) Check any KeyPress/KeyDown/KeyUp handler on the form that doesn't work to see if they process a RETURN key. If the form has KeyPreview=TRUE then the form's keyboard handler will be executed BEFORE the memo's and if the form's keyhandler processes RETURN then the memo will never see it.

Resources