Incorrect TMSSQL.Assign() method
Incorrect TMSSQL.Assign() method
After calling the TMSSQL.Assign() method both instances (source and destination) has an own Params collection, but contents of this collection is the same.
Example:
procedure TForm1.Button1Click;
var
cmd: TMSSQL;
begin
cmd := TMSSQL.Create(Self);
// cmdTemplate here is a TMSSQL Component on my TForm1, it is a Template object, that I'm using in diffrent places.
cmd.Assign(cmdTemplate);
cmd.ParamByName('AParamName').Value := 'AnyValue';
// After that my cmdTemplate's param 'AParamValue' also have value 'AValue'.
if cmd.ParamByName('AParamName').AsString = cmdTemplate.ParamByName('AParamName').AsString then
ShowMessage('AssigneError');
end;
So that I must to set values for all params in TMSSQL each time I using it, because I don't now who was used my cmdTemplate early.
Example:
procedure TForm1.Button1Click;
var
cmd: TMSSQL;
begin
cmd := TMSSQL.Create(Self);
// cmdTemplate here is a TMSSQL Component on my TForm1, it is a Template object, that I'm using in diffrent places.
cmd.Assign(cmdTemplate);
cmd.ParamByName('AParamName').Value := 'AnyValue';
// After that my cmdTemplate's param 'AParamValue' also have value 'AValue'.
if cmd.ParamByName('AParamName').AsString = cmdTemplate.ParamByName('AParamName').AsString then
ShowMessage('AssigneError');
end;
So that I must to set values for all params in TMSSQL each time I using it, because I don't now who was used my cmdTemplate early.
On assigning blob parameters only reference to Blob object is copied. It's done to prevent copying of large memory amounts for blob objects.
To create new objects for blob parameters you can use the following code:
To create new objects for blob parameters you can use the following code:
Code: Select all
MSSQL2.Assign(MSSQL1);
for i := 0 to MSSQL2.Params.Count - 1 do begin
if MSSQL2.Params[i].DataType in [ftMemo{$IFDEF VER10P}, ftWideMemo{$ENDIF}, ftBlob] then begin
MSSQL2.Params[i].DataType := ftUnknown;
MSSQL2.Params[i].DataType := MSSQL1.Params[i].DataType;
MSSQL2.Params[i].Value := MSSQL1.Params[i].Value;
end;
end;