Delphi6的TClIEntDataSet.XMLData 存在內存洩漏,當你循環調用它獲取XML文本,達到一定的循環次數後,你的程序就會報“InsufficIEnt memory for this Operation”錯誤,查看內存也是節節攀升,說明存在bug。
如何解決呢?見代碼:
type
ThcClientDataSet = class(TClIEntDataSet)
private
...
function GetXMLData: string;
procedure SetXMLData(const Value: string);
protected
...
public
...
property XMLData: string read GetXMLData write SetXMLData;
published
...
end;
...
function ThcClIEntDataSet.GetXMLData: string;
var
Stream: TStringStream;
begin
Stream := TStringStream.Create('');
try
SaveToStream(Stream, dfXML);
Result := Stream.DataString;
finally
Stream.Free;
end;
end;
procedure ThcClIEntDataSet.SetXMLData(const Value: string);
var
Stream: TStringStream;
begin
Stream := TStringStream.Create(Value);
try
LoadFromStream(Stream);
finally
Stream.Free;
end;
end;
測試證明TClientDataSet.通過Stream導入導出XML是不存在內存洩漏的,用上文繼承的ThcClIEntDataSet 重寫XMLDATA屬性,可以解決問題。