Message 1 of 9
Delphi XData Problem

Not applicable
05-18-2005
06:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am having a problem with a Delphi function that I am using to proccess any string
values that are in the xdata that is attached to the entity. There appears to be a memory leak from
using the OleVariants. It appears as though the leak is caused by SysString from the
resource SysAllocString from oleauto.dll. I call this function thousands of time,
so eventually I get an Out Of Memory error and have to close AutoCAD in order to free the memory.
Does anyone know how I can resolve this leak, or how I can free the memory that is
being lost. Anyones help or suggestions would be greatly appreciated.
Thanks in advance, Kevin
function ReadEntityXData(const Entity: IAcadEntity): Boolean;
var
> i : Integer;
> GpCodes: OleVariant;
> GpValues: OleVariant;
> LowBoundIndex, HighBoundIndex: Integer;
> MyXValue: WideString;
begin
> Result := False;
> // make sure there is extended data
> Entity.GetXData(CDS_3D_ACAD, GpCodes, GpValues);
> try
>>> if not VarIsEmpty(GpCodes) then
>>> begin
>>>>> // get the dimensions of the XData arrays (both arrays are same size)
>>>>> LowBoundIndex := varArrayLowBound(GpCodes, 1);
>>>>> HighBoundIndex := varArrayHighBound(GpCodes, 1);
>>>>> try
>>>>>>>> for i := LowBoundIndex to HighBoundIndex do
>>>>>>>> begin
>>>>>>>>>> // to compare an olevariant the variant must be a string or an
>>>>>>>>>> // exception will be triggered so check to see if MyValue is a string.
>>>>>>>>>> if VarIsStr(GpValues) then
>>>>>>>>>> begin
>>>>>>>>>>>> MyXValue := GpValues;
>>>>>>>>>>>> if ProcessStringValue(MyXValue) then
>>>>>>>>>>>> begin
>>>>>>>>>>>>>> // do something with MyXValue
>>>>>>>>>>>> end;
>>>>>>>>>> end;
>>>>>>>> end;
>>>>>>>> Result := True;
>>>>> except
>>>>>>>> On E:Exception do
>>>>>>>> {Raise Exception}
>>>>> end;
>>> end;
> finally
>>> VarClear(GpCodes);
>>> VarClear(GpValues);
> end;
end;
values that are in the xdata that is attached to the entity. There appears to be a memory leak from
using the OleVariants. It appears as though the leak is caused by SysString from the
resource SysAllocString from oleauto.dll. I call this function thousands of time,
so eventually I get an Out Of Memory error and have to close AutoCAD in order to free the memory.
Does anyone know how I can resolve this leak, or how I can free the memory that is
being lost. Anyones help or suggestions would be greatly appreciated.
Thanks in advance, Kevin
function ReadEntityXData(const Entity: IAcadEntity): Boolean;
var
> i : Integer;
> GpCodes: OleVariant;
> GpValues: OleVariant;
> LowBoundIndex, HighBoundIndex: Integer;
> MyXValue: WideString;
begin
> Result := False;
> // make sure there is extended data
> Entity.GetXData(CDS_3D_ACAD, GpCodes, GpValues);
> try
>>> if not VarIsEmpty(GpCodes) then
>>> begin
>>>>> // get the dimensions of the XData arrays (both arrays are same size)
>>>>> LowBoundIndex := varArrayLowBound(GpCodes, 1);
>>>>> HighBoundIndex := varArrayHighBound(GpCodes, 1);
>>>>> try
>>>>>>>> for i := LowBoundIndex to HighBoundIndex do
>>>>>>>> begin
>>>>>>>>>> // to compare an olevariant the variant must be a string or an
>>>>>>>>>> // exception will be triggered so check to see if MyValue is a string.
>>>>>>>>>> if VarIsStr(GpValues) then
>>>>>>>>>> begin
>>>>>>>>>>>> MyXValue := GpValues;
>>>>>>>>>>>> if ProcessStringValue(MyXValue) then
>>>>>>>>>>>> begin
>>>>>>>>>>>>>> // do something with MyXValue
>>>>>>>>>>>> end;
>>>>>>>>>> end;
>>>>>>>> end;
>>>>>>>> Result := True;
>>>>> except
>>>>>>>> On E:Exception do
>>>>>>>> {Raise Exception}
>>>>> end;
>>> end;
> finally
>>> VarClear(GpCodes);
>>> VarClear(GpValues);
> end;
end;