Hi I need some help in creating a template function (as they are known in c++ if I’m correct). I’m using Delphi XE2, and I’m writing a database application using an MS Access database.
The problem is that there is a lot of functions that I write that does the same thing on different tables. So I thought that I can create template functions and then just use different parameters for the different tables.
For example, there is the Locate function that locates a specific record in a table or query. Now I would like to make a template function of this but I do not know how to do this.
I want to put the function in the public section of my datamodule, so I was thinking in the line of this
function find(tableName: TADOTable, fieldName: String, fieldValue: String):Boolean
Then…
function TDataModule.find(tableName: TADOTable, fieldName: String, fieldValue:String): Boolean;
var SearchOptions : TLocateOptions;
begin
SearchOptions := [loCaseInsensitive];
find := DataModule.tableName.Locate('fieldName', fieldValue, SearchOptions);
end;
But this do not want compile…
It there any way to make some kind of template function where I can pass any table as a parameter or would it be beter to create a class for every single table, with getter and setter functions?
1 Answer