Pregunta

I have the following situation: An object is instantiated in VB6 using OCX made ​​in Delphi. when I

...
Dim x As New spdComponent
Set x = spdComponent.ConverterType (XML)
count = x.item.count
TXT = ""
...

Count receives the value of all items of the TStringList OCX correctly, but soon the line below, where TXT gets empty, the value of 'x.item.cout' is lost. When I debug in Delphi, in reality what happens is a TStringList be released from memory, but this happens without any sense (it seems that there is a conflict of interest between Delphi and VB). Searching here and on google, I saw that many commented about not using TStringList but PChar, it would be a more appropriate way of working, but the question remains as to make use of C # 2005 and the same OCX, the problem is not occurs. (as in other languages​​, only in VB 6, so far).

Well, I have evidence that the VB kills the object (TStrinList) because for him, that object is not longer necessary, but it does. One strange thing that happens is, if I

count = spdComponent.ConverterType(XML).item.count

It's work, do all the necessary processes without any error, but that first case, the error still remains.

Has anyone encountered similar problems?

Thanks guys, anyone who can give me a hand ... will be grateful

¿Fue útil?

Solución

AFAIR, VB Classic uses reference count semantics for management of memory. This means, somewhere in your code, all references to the instance created by spdComponent.ConverterType(XML) are cleared (pointing to Nothing) or got out of scope.

EDIT: in you code you're destroying the instance created by Dim x As New spdComponent when you do Set x = spdComponent.ConverterType (XML). Maybe you could test this:

 ' Removed the instantiation on the declaration
Dim x As spdComponent
Set x = spdComponent.ConverterType (XML)
count = x.item.count 

And tell us if something changed...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top