Firebird Get Identity field after a Post

Firebird Get Identity field after a Post

I know you can use  as Returning to get the Identity field when using an insert SQL. But I need to do it with a SELECT statement and an insert; eg

uniquery.close;
uniquery.options.RequiredFields := false; //because of Identity field
uniquery.sql.clear;
uniquery.sql.add('SELECT ID, SURNAME FROM CUSTOMER');
uniquery.open;
if uniquery.recordcount=0 then
  uniquery.insert
else
 uniquery.edit;
uniquery.FieldByName('SURNAME').AsString:='some name';
uniquery.Post;
ID = uniquery.FieldByName('ID').AsLargeint;

ID is the identity field and this always returns a 0 value.

Any suggestions?

This is with Firebird 3 and Delphi 10.3.2 and UniDac 9.3.0