The identifier ftDateTime
belongs to the enumeration TFieldTipe
, which is declared on the unit Data.DB
(in old versions of Delphi simply DB
). It would be necessary that you declare this unit within the use of your unit, so that the identifier is visible, if you do not have any unit in the uses clause, it would be something similar to:
implementation
uses Data.DB;
If you already have units declared, then add it to the list, separated by a comma, for example:
implementation
uses MiUnidad1, MiUnidad2, Data.DB;
On the other hand, the code that you publish does not compile, but beyond that, I find some problems that I am commenting you with each line:
query.close;
This has a bad smell. It can be derived from a bad practice, if you need to start by closing the object query
, I have seen code that has an object for general use and in this it leaves open datasets with any result that remain that way in memory and from which the programmer loses control over the data that they contain or for what they are used. I suggest that you create and destroy a query object whenever you need it, this keeps the code cleaner and, as the application gets more complex, you avoid annoying side effects and errors that are difficult to debug.
query.sql.clear
query.sql.text := (' delete from tabla where (campo_fecha between :fecha1 and :fecha2);
You assign a value to the property Text
of SQL
, which is a TStrings
. The previous statement that cleans the SQL is, therefore, superfluous. It is not that this has a high cost, but the fact that you have written (or copied) this code implies that you do not fully understand the operation of the classes, nor the code you are writing. This also smells bad to me. In addition, in the code you publish, the string of characters is poorly constructed, and therefore, the compiler will give an error on this line.
query.Parameters.ParamByName('fecha1').DataType := ftDateTime; //aqui tengo el error
query.Parameters.ParamByName('fecha2').DataType := ftDateTime; // aqui tambien
query.Parameters.ParamByName('fecha1').Value := FormatDateTime('yyyy/mm/dd',Datetimepicker1.Date);
query.Parameters.ParamByName('fecha2').Value := FormatDateTime('yyyy/mm/dd',Datetimepicker1.Date);
Here you assign the data type, such as DateTime, and then assign a string of characters to the property. There is a bit of the above. The property Value
of the parameters can directly accept the date or date / time of the DateTimePicker and, if necessary, will automatically adjust the type of the parameter.
query.ExecSQL;
query.refresh;
You execute the SQL, which contains an erase statement, and then you refresh the Query object, which since it executed a delete
, does not contain data, why do you refresh it?