I found a way to solve it, but I dont know why is it happening.
I opened the *.lfm file of the named form. Remember, Lazarus creates files with extension .pas, where it keeps the Pascal code, and another one with extension .lfm where it keeps some information. So i opened that one, the *.lfm file, and found the lines that apply to the query that makes the problem, and it was missing the lines with :
Database = fmeni.MySQL50Connection1
Transaction = fmeni.SQLTransaction1
while the other query (one that wokrs) had these lines. So, i simply typed these lines, and here's the complete section of the trouble-making query :
object qgrid: TSQLQuery
IndexName = 'DEFAULT_ORDER'
Database = fmeni.MySQL50Connection1
Transaction = fmeni.SQLTransaction1
ReadOnly = False
Params = <>
left = 40
top = 174
end
And that finished the job.
But, I think that it's a bug of Lazarus : one form, two queries, one query wokrs, other doesnot.
The Lazarus IDE for some reason once writes these lines into the myform.lfm and once doesnot.