One major point: Lazarus is NOT Delphi - Lazarus is __most__ sourcecode compatible in mode Delphi, but it is not Delphi !
The code show nothing about the used queries.
SQLQuery4.ParamByName('type').value:=SQLQuery3.FieldByName('type').value;
split this line and use a variable to see if it is comming from SQLQuery3 with wrong or a error in SQLQuery3. Maybe on the second try the parameter is not ok.
Another point of failure is, you corrupt in the meantime your SQL-Statements.
BTW: For such chaining often a master/slave Query is used. So the slaver query can read new datas if the row of the master is changed automatic. For SQLdb based queries. If you use componnets for the IB Connection it may be different.