Você deve obter o ID de uma só vez
SQLQry := TSQLQuery.Create(self);
with SQLQry do begin
SQLConnection := SQLCon;
SQL.Add('INSERT INTO Sample_Table ');
SQL.Add('(mobile_number, message_body) VALUES');
SQL.Add(format('(%s, %s);',[QuotedStr('989121011689'), QuotedStr('Text1')]));
SQL.Add('SELECT LAST_INSERT_ID() EngineRefNo;');
Open;
ListBox1.items.Add(FieldByName('EngineRefNo').AsString);
Close;
end;
SQLCon.Close;
e você deve pensar em usar parâmetros para evitar injeção de sql
SQLQry := TSQLQuery.Create(self);
with SQLQry do begin
SQLConnection := SQLCon;
SQL.Add('INSERT INTO Sample_Table ');
SQL.Add('( mobile_number, message_body ) VALUES');
SQL.Add('( :mobile_number, :message_body );');
SQL.Add('SELECT LAST_INSERT_ID() EngineRefNo;');
ParamByName( 'mobile_number' ).Value := '989121011689';
ParamByName( 'message_body' ).Value := 'Text1';
Open;
ListBox1.items.Add(FieldByName('EngineRefNo').AsString);
Close;
end;
SQLCon.Close;