做了一个数据导入的功能,代码如下
procedure TMAINFORM.ToolButton9Click(Sender: TObject);
Var
lExcelToTable:TExcelToTable;
lMsg,lStr: String;
begin
BeforeOpenXLS(lStr);
lMsg := '';
OpenDialog.Filter := 'Excel(*.xls)|*.xls';
if OpenDialog.Execute then
begin
lExcelToTable:=TExcelToTable.Create(self);
try
lExcelToTable.DataSource:=DataSetBrokerTargetValue;
lExcelToTable.FileName := OpenDialog.FileName;
lExcelToTable.StartRow := 1;
lExcelToTable.EndRow := 9999;
lExcelToTable.FieldMap.Add('DataSetTargetValue.FTARGETNAME=Sheet1[1,0]');
lExcelToTable.FieldMap.Add('DataSetTargetValue.FTARGETCODE=Sheet1[2,0]');
lExcelToTable.FieldMap.Add('DataSetTargetValue.FTARGETTYPECODE=Sheet1[3,0]');
lExcelToTable.FieldMap.Add('DataSetTargetValue.FUNITNAME=Sheet1[4,0]');
lExcelToTable.FieldMap.Add('DataSetTargetValue.SUBSTR(TABLE_TARGET.FENTITYCODE=Sheet1[5,0]');
lExcelToTable.FieldMap.Add('DataSetTargetValue.FVALUE=Sheet1[6,0]');
lExcelToTable.FieldMap.Add('DataSetTargetValue.FORDER=Sheet1[7,0]');
lExcelToTable.Execute(lMsg);
finally
lExcelToTable.free;
end;
end;
AfterInput(lStr);
TSQLDataSet(DataSetBrokerTargetValue.DataSet).ApplyUpdates;
DataGrid1.Refresh;
end;
遇到一个问题,每次导入后,内存占用总是增加100M左右的内存,也就是说,连续导入几次,内存就满了,死机了。。关闭窗体以后就自动释放内存了。
请斑竹给看看是什么原因。 |