Closed kingga closed 5 years ago
The problem seems to be on the Receiver::onData() function after doing some testing I managed to get the line:
<= Received: {"method": "callObjectEventListener", "params": [5, "onclick"]}
printed into the console.
Obviously this isn't a permanent fix but this was what was happening:
public function onData($data)
{
$this->buffer .= $data;
if ($data === '{"method": "callObjectEventListener", "params": [5, "onclick"]}') {
$this->buffer = $data . "\0"; // I'm also using = instead of .= as the JSON is invalid otherwise.
}
// ...
}
The reply I was receiving wasn't terminated with a NULL character.
Log: $ php app.php
=> Sent: {"id":0,"method":"setObjectProperty","params":[0,"caption","PHP GUI"],"callback":{}}
=> Sent: {"id":1,"method":"setObjectProperty","params":[0,"width","1280"],"callback":{}}
=> Sent: {"id":2,"method":"setObjectProperty","params":[0,"height","720"],"callback":{}}
MainController
=> Sent: {"id":3,"method":"createObject","params":[{"lazarusClass":"TForm1","lazarusObjectId":1,"parent":0}],"callback":{}}
=> Sent: {"id":4,"method":"createObject","params":[{"lazarusClass":"TScrollBox","lazarusObjectId":2,"parent":1}],"callback":{}}
=> Sent: {"id":5,"method":"createObject","params":[{"lazarusClass":"TLabel","lazarusObjectId":3,"parent":2}],"callback":{}}
=> Sent: {"id":6,"method":"createObject","params":[{"lazarusClass":"TLabel","lazarusObjectId":4,"parent":2}],"callback":{}}
=> Sent: {"id":7,"method":"createObject","params":[{"lazarusClass":"TButton","lazarusObjectId":5,"parent":2}],"callback":{}}
=> Sent: {"id":8,"method":"setObjectEventListener","params":[5,"onclick"],"callback":{}}
<= Received: {"method": "callObjectEventListener", "params": [5, "onclick"]}
=> Sent: {"id":9,"method":"exit","params":[],"callback":{}}
I can have a look at this when my time frees up a bit, possibly in the weekend.
noticed that someone else has brought this up a year ago but I though I would mention it again with some more information:
`$app->on('start', function () use ($app, $router) { // $router->handle('main'); $btn = (new Button())->setValue('Click'); $btn->on('click', function () use ($app) { $app->terminate(); }); });
$app->run();I`
The button gets created but the click event will not fire, I have tried on my Linux VM and it worked fine. Here's the console output:
=> Sent: {"id":0,"method":"setObjectProperty","params":[0,"caption","PHP GUI"],"callback":{}} => Sent: {"id":1,"method":"setObjectProperty","params":[0,"width",1280],"callback":{}} => Sent: {"id":2,"method":"setObjectProperty","params":[0,"height",720],"callback":{}} => Sent: {"id":3,"method":"createObject","params":[{"lazarusClass":"TButton","lazarusObjectId":1,"parent":0}],"callback":{}} => Sent: {"id":4,"method":"setObjectProperty","params":[1,"caption","Click"],"callback":{}} => Sent: {"id":5,"method":"setObjectEventListener","params":[1,"onclick"],"callback":{}}