Found the problem. INCREDIBLE!



This is the sequence of my application:
1- I open program1 in window1, where DBGrid1 shows all the records in Table1
(MyTable.dbf).
2- I click on button1:
3- this opens program2 in window2, where a button executes a query on Table2
and shows results on DBGrid2.
Table2 refers to the same MyTable.dbf file in the disk.
4- I close program2 and go back to program1.
5- I close program1 clicking on an Exit button, where Table1 is closed. In
the statement "Table1.Close" I GOT A TERMINATING ERROR (while testing the
program, that got me into some sort of assembler panel).

After some research, I understood that probably Delphi could'nt find
anything in memory where the pointer to the Table1 was supposed to be. Why ?

NOW I KNOW, THOUGH I DO NOT UNDERSTAND ! HERE IS WHAT I FOUND:

The problem lies in program2 and not in program1.
In the query string I replaced the following statement:
" where NUM between ' + EditFrom.Text + ' and ' + EditTo.Text" //
(NUM is a "numeric" field)
with the following:
' where ( NUM BETWEEN :NUM1 and :NUM2 ) '
supplying the parameters with:
MyQuery.ParamByName('NUM1').AsInteger:= StrToInt(EditFrom.Text);
MyQuery.ParamByName('NUM2').AsInteger:= StrToInt(EditTo.Text);

Now, I don't really understand why and how a query in program2 may affect
the reference to a table component in program1, but it does!
I challenge anybody to give me an explanation. Just tell me what you need to
know more than just I said.


.


Quantcast