Answer the question
In order to leave comments, you need to log in
How to set a variable number of arguments for someone else's function?
Please help, there is a lot of boilerplate code when you execute ExecSQLEx, for example:
if not DataModule1.UniConnection1.InTransaction then
DataModule1.UniConnection1.StartTransaction;
try
//тут выполняемый запрос
DataModule1.UniConnection1.ExecSQLEx('UPDATE ...','parametr1', parametr1, 'parametr2', parametr2,'parametr3', parametr3 ...);
DataModule1.UniConnection1.Commit;
except on E: Exception do
begin
DataModule1.UniConnection1.Rollback;
end;
end;
...
class function upd<T> (SQL:string; params: array of T): T; static;
...
function TForm1.upd<T> (SQL:string; params: array of T): T;
begin
if not DataModule1.UniConnection1.InTransaction then
DataModule1.UniConnection1.StartTransaction;
try
DataModule1.UniConnection1.ExecSQLEx(SQL, params[i]) //как здесь перечислить в цикле и указать входящие аргументы?
DataModule1.UniConnection1.Commit;
except on E: Exception do
begin
DataModule1.UniConnection1.Rollback;
ShowMessage('Ошибка: '+ E.Message)
end;
end;
end;
Answer the question
In order to leave comments, you need to log in
probably something like this:
class function upd<T>(SQL: string; params: array of Variant): Variant; static;
...
function TForm1.upd<T>(SQL: string; params: array of Variant): Variant;
begin
...
DataModule1.UniConnection1.ExecSQLEx(SQL, params);
DataModule1.UniConnection1.Commit;
...
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question