How create Browser in hands

Post Reply
User avatar
Uefi1
Posts: 6
Joined: Tue Aug 24, 2021 1:58 pm

How create Browser in hands

Post by Uefi1 »

Hello, please tell me how to create a browser dynamically the window cefwindowparent1 is empty
also can not get url
memo1.Lines.Add(chrom.Browser.MainFrame.Url);
Error Access Violation

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
chrom:tchromium;
begin
Chrom:=Tchromium.Create(cefwindowparent1);
GlobalCEFApp := TCefApplication.Create;
chrom.Initialized;
GlobalCEFApp.UserAgent:='Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0';
chrom.CreateBrowser(cefwindowparent1);
chrom.Initialized;
GlobalCEFApp.WindowlessRenderingEnabled:=True;
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
chrom.LoadURL('https://yandex.ru');
memo1.Lines.Add(chrom.Browser.MainFrame.Url); //Access Violation
end;
User avatar
salvadordf
Posts: 3067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How create Browser in hands

Post by salvadordf »

If you need a child form with a browser then you can use the code from the ToolBoxBrowser demo.

If your application is MDI then you can take a look at the code from the MDIBrowser demo.

If you prefer to have multiple tabs then use the TabbedBrowser or TabbedBrowser2 demos.

All those demos create browsers dynamically at runtime.

Please, read the code comments of those demos because you need to follow some steps to close the application correctly.

There's a lot of information about CEF4Delphi here :
https://www.briskbard.com/index.php?lang=en&pageid=cef
User avatar
Uefi1
Posts: 6
Joined: Tue Aug 24, 2021 1:58 pm

Re: How create Browser in hands

Post by Uefi1 »

I need to use a browser in a multithreaded application, so I just need to create the load page every time get the current url to destroy the component.
Last edited by Uefi1 on Wed Aug 25, 2021 7:44 am, edited 1 time in total.
User avatar
salvadordf
Posts: 3067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How create Browser in hands

Post by salvadordf »

If you want to create and destroy browsers in a thread context then you have to use a browser in OSR mode.

Use the code from the WebpageSnapshot demo.
User avatar
Uefi1
Posts: 6
Joined: Tue Aug 24, 2021 1:58 pm

Re: How create Browser in hands

Post by Uefi1 »

Uses
uCEFBrowserThread;
src := @PByte(buffer)[TempSrcOffset];
[Error] uCEFBrowserThread.pas(446): Array type required
User avatar
salvadordf
Posts: 3067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How create Browser in hands

Post by salvadordf »

I'm sorry but I only have a Delphi 10.4.2 license and that demo works with the latest version of Delphi.
If you have an older version of Delphi then you have to modify the code for yourself.

You can also install Lazarus to run this equivalent demo : CEF4Delphi/demos/Lazarus_Windows/WebpageSnapshot
User avatar
Uefi1
Posts: 6
Joined: Tue Aug 24, 2021 1:58 pm

Re: How create Browser in hands

Post by Uefi1 »

Then I will return to the first question how to do?
User avatar
Uefi1
Posts: 6
Joined: Tue Aug 24, 2021 1:58 pm

Re: How create Browser in hands

Post by Uefi1 »

Why does it work that

Code: Select all

var
chrom:Tchromium;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Chrom.CreateBrowser(CEFWindowParent1)and (Chrom.Initialized) then
timer1.Enabled:=false;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Chrom:=Tchromium.Create(cefwindowparent1);
timer1.Enabled:=true;
chrom.LoadURL('https://yandex.ru');
end;

But it doesn't work ???????

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
chrom:Tchromium;
begin
Chrom:=Tchromium.Create(cefwindowparent1);
Chrom.CreateBrowser(CEFWindowParent1;
Chrom.Initialized;
chrom.LoadURL('https://yandex.ru');
end;
User avatar
Uefi1
Posts: 6
Joined: Tue Aug 24, 2021 1:58 pm

Re: How create Browser in hands

Post by Uefi1 »

Okey i am changed

Code: Select all

src := @PByte(buffer)[TempSrcOffset];
dst := @PByte(TempBufferBits)[TempDstOffset];
From
src := @PByteArray(buffer)[TempSrcOffset];
dst := @PByteArray(TempBufferBits)[TempDstOffset];
The project is now compiling how can i get the source code of the page or the current url ?

Code: Select all

GlobalCEFApp := TCefApplication.Create;
FThread:= TCEFBrowserThread.Create(AddressEdt.Text, 1024, 768);
FThread.LoadUrl(AddressEdt.Text);
Fthread.Browser.MainFrame.url ??? - none
Fthread.Browser.MainFrame.gesorcecode ????? - none 
User avatar
Uefi1
Posts: 6
Joined: Tue Aug 24, 2021 1:58 pm

Re: How create Browser in hands

Post by Uefi1 »

Oh yes I conquered it

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
chrom:Tchromium;
begin
chrom:=Tchromium.Create(cefwindowparent1);
chrom.DefaultUrl:='https://yandex.ru';
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.UserAgent:='Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0';
if not Chrom.Initialized then Chrom.CreateBrowser(cefwindowparent1);
end;
Post Reply