salvadordf / CEF4Delphi

CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
https://www.briskbard.com/forum/
Other
1.22k stars 373 forks source link

LoadString on Memo onChange #310

Closed shariful2011 closed 4 years ago

shariful2011 commented 4 years ago

I need to load my current text on Browser on memo onchange as I have to make a string dynamically which will load in Browser. I manage to load the string but the problem the memo is lost its focus on each keypress. How can I avoid this and load string as I write in a memo. Below is my code:

procedure TfrmMain.memEditorChange(Sender: TObject);
var
  st: TStrings;
  //s: string;
begin
  st := TStringList.Create;
  try
    st.Add(HTML_HEAD);
    st.Add(Format('%s', [memEditor.Lines.Text]));
    memEditor.SetFocus;
    st.Add(HTML_END);
    Chromium.LoadString(st.Text);
  finally
    st.Free;
  end;
end;
salvadordf commented 4 years ago

CEF browsers in normal mode steal the focus sometimes. This is a known issue but it has some workarounds.

Read these forum threads to know more details : https://www.briskbard.com/forum/viewtopic.php?f=8&t=1467 https://www.briskbard.com/forum/viewtopic.php?f=10&t=1198

Try setting the TChromium.DefaultWindowInfoExStyle property to WS_EX_NOACTIVATE before the TChromium.CreateBrowser call.

If that solution is not enough for you then try using a browser in OSR mode. That mode gives total control of the focus.

Please, use our forum for more questions : https://www.briskbard.com/forum/index.php

shariful2011 commented 4 years ago

How do I set OSR mode?

salvadordf commented 4 years ago

If your application uses VCL then use the SimpleOSRBrowser demo as a template for your application.

If it's a Firemonkey app then use the FMXExternalPumpBrowser demo.

The "off screen rendering" mode (OSR mode) needs more code and the browser has a different initialization. It's slower than the normal mode but you have absolute control.