Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
Closing application correctly
-
- Posts: 112
- Joined: Wed Jul 01, 2020 10:22 am
Re: Closing application correctly
It does not occur eny errors, but does not close application correctly. The demo.exe is still in memory after closing application.
- salvadordf
- Posts: 4052
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Closing application correctly
Here's the fixed demo. All the files have changes.
The OSR browsers need to have the GlobalCEFApp.WindowlessRenderingEnabled property set to TRUE in the DPR file.
I also changed a few things in the form and the pas unit.
The code comments in the demos still make a reference to the old way of closing the browsers. Instead of setting the "Result" parameter to false in the TChromium.OnClose events you have to set "aAction" to "cbaClose" because these are OSR browsers. Sorry about that.
Copy the missing code from the SimpleOSRBrowser demo in order to show the browser contents.
The OSR browsers need to have the GlobalCEFApp.WindowlessRenderingEnabled property set to TRUE in the DPR file.
I also changed a few things in the form and the pas unit.
The code comments in the demos still make a reference to the old way of closing the browsers. Instead of setting the "Result" parameter to false in the TChromium.OnClose events you have to set "aAction" to "cbaClose" because these are OSR browsers. Sorry about that.
Copy the missing code from the SimpleOSRBrowser demo in order to show the browser contents.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 112
- Joined: Wed Jul 01, 2020 10:22 am
Re: Closing application correctly
Tnanks. And now I have placed TTimer component on the form and added theese strings:salvadordf wrote: ↑Sun Aug 30, 2020 10:13 am Here's the fixed demo. All the files have changes.
The OSR browsers need to have the GlobalCEFApp.WindowlessRenderingEnabled property set to TRUE in the DPR file.
I also changed a few things in the form and the pas unit.
The code comments in the demos still make a reference to the old way of closing the browsers. Instead of setting the "Result" parameter to false in the TChromium.OnClose events you have to set "aAction" to "cbaClose" because these are OSR browsers. Sorry about that.
Copy the missing code from the SimpleOSRBrowser demo in order to show the browser contents.
Code: Select all
procedure TForm1.Timer3Timer(Sender: TObject);
var
i:integer;
MouseCoord:TCefMouseEvent;
begin
timer3.Enabled:=false;
Chromium1.LoadURL('https://yahoo.com');
for I := 0 to 999 do
begin
MouseCoord.x:=random(200);
MouseCoord.y:=random(200);
Chromium1.SendMouseMoveEvent(@MouseCoord,false);
sleep(500);
application.ProcessMessages;
end;
end;
Re: Closing application correctly
Перед завершением работы программы ты должен сам позаботиться, что ничего не будет использовать уничтоженные объекты, в твоем случае в таймере цикл не знает что программа завершается и обращается к хромиуму, добавь туда переменную которая будет проверяться что послан сигнал завершения программы и нужно прервать цикл.
-
- Posts: 112
- Joined: Wed Jul 01, 2020 10:22 am
Re: Closing application correctly
Это довольно непросто сделать. Выше лишь пример и достаточно без новых переменных лишь указать if Form1.Visible, а в моей программе тысяча функций и каждой ставить условие... эх...Student wrote: ↑Sun Aug 30, 2020 9:49 pm Перед завершением работы программы ты должен сам позаботиться, что ничего не будет использовать уничтоженные объекты, в твоем случае в таймере цикл не знает что программа завершается и обращается к хромиуму, добавь туда переменную которая будет проверяться что послан сигнал завершения программы и нужно прервать цикл.
Странно, что в предыдущей версии я спокойно это делал функцией, кажется CEFDestroy + halt;
Re: Closing application correctly
А под отладкой ошибку какую выбивает? Внутри функции есть проверка, через переменную Initialized. Тебе нужно просто сделать так чтоб циклы прерывались после нажатия на закрытие.
Code: Select all
procedure TChromiumCore.SendMouseMoveEvent(const event: PCefMouseEvent; mouseLeave: Boolean);
begin
if Initialized then
Browser.Host.SendMouseMoveEvent(event, mouseLeave);
end;
Re: Closing application correctly
Halt это крайняя мера, она вынуждает резкое завершение текущего приложения и не гарантируется, что ресурсы будут освобождены при вызове halt.
-
- Posts: 112
- Joined: Wed Jul 01, 2020 10:22 am
Re: Closing application correctly
Can I make something like this?
Code: Select all
Chromium1.Closebrowser;
repeat
application.processmesages;
until Chromium1.Initialized = false;
Chromium2.Closebrowser;
repeat
application.processmesages;
until Chromium2.Initialized = false;
Application.terminate;
- salvadordf
- Posts: 4052
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Closing application correctly
I would not recomend using "Application.ProcessMessages", "Halt" or "Application.terminate".
Chromium expects the application to behave asynchronously and to close the app following some steps.
Trying to do things any other way only increases the probabilities of having stability issues.
Chromium expects the application to behave asynchronously and to close the app following some steps.
Trying to do things any other way only increases the probabilities of having stability issues.
-
- Posts: 112
- Joined: Wed Jul 01, 2020 10:22 am
Re: Closing application correctly
Unfortunatelly, only this code works
I do not know the reason, maybe postmessage() does not work as needed (maybe wrong handle?)
Code: Select all
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
form1.Hide;
if not(FClosing) then
begin
FClosing := True;
Chromium1.CloseBrowser(True);
Chromium2.CloseBrowser(True);
repeat
application.ProcessMessages;
until FCanClose1 and FCanClose2;
end;
CanClose := FCanClose1 and FCanClose2;
end;