Page 1 of 1

Closes form

Posted: Tue Sep 03, 2019 8:53 pm
by Kazann117
good evening, I am doing a mouse click simulation + a keyboard simulation, but the form just closes, not immediately, but after some time, what could be the reason?

MouseEvent.x :=30;
MouseEvent.y := 40;
form1.Chromium1.Browser.Host.SendFocusEvent (true);
form1.Chromium1.Browser.Host.SendMouseClickEvent (PCefMouseEvent(@MouseEvent), MBT_LEFT, false, 1);
form1.Chromium1.Browser.Host.SendMouseClickEvent (PCefMouseEvent (@MouseEvent), MBT_LEFT, true, 1);

for I := 0 to length(tel) do
begin
FillChar(event, SizeOf(TCefKeyEvent), 0);
event.kind := KEYEVENT_KEYDOWN;
event.character := tel;
event.windows_key_code :=ord(tel);
form1.Chromium1.Browser.Host.Browser.MainFrame.Browser.Host.SendKeyEvent(@event);

sleep(50);

FillChar(event, SizeOf(TCefKeyEvent), 0);
event.kind := KEYEVENT_CHAR;
event.character := tel;
event.windows_key_code := ord(tel);
form1.Chromium1.Browser.Host.Browser.MainFrame.Browser.Host.SendKeyEvent(@event);
sleep(50);



FillChar(event, SizeOf(TCefKeyEvent), 0);
event.kind := KEYEVENT_KEYUP;
event.character := tel;
event.windows_key_code := ord(tel);
form1.Chromium1.Browser.Host.Browser.MainFrame.Browser.Host.SendKeyEvent(@event);

end;

Re: Closes form

Posted: Wed Sep 04, 2019 7:38 am
by salvadordf
Maybe there's an AV caused by some access to a nil object or reading memory outside the limits of the memory assigned to a variable.

It's recommended to use the TChromium procedures and functions whenever you can. For example, replace this :

Code: Select all

form1.Chromium1.Browser.Host.SendFocusEvent(true);
with this :

Code: Select all

form1.Chromium1.SendFocusEvent(true);
The calls to SendMouseClickEvent and SendKeyEvent can also be replaced by the TChromium functions.

I assume "tel" is a string but the for..to loop with those initial and final values could cause problems if you try to access a character in that position.

I would also split that function into smaller functions to remove all the "sleep" calls.