firebird 3 identity column - return last inserted id
Have a look at Delphi docs about ExecSQL. (Bold is mine)


  ExecSQL returns an integer value reflecting the number of rows affected by the executed SQL statement.


I'm mostly a CBuilder++ (old) user, but you can try by using:

aQry.Open();
result := aQry.Fields[0].AsInteger;
aQry.Close();


And let me suggest to enclose the query inside a try-catch block.