VB6 Object and Data Types

I understand that the Object class is at the top of the hiearchy class in object-oriented langauge programming, such as Java. I also understand that you have reference types and value types in .NET. I also understand type definitions in C.

Despite this; I'm struggling to understand what an object is in VB6 ( http://msdn.microsoft.com/en-us/library/aa338034%28v=vs.60%29.aspx ) and which option. What is an option? and how is the object implemented in VB6?

+6
source share
2 answers

All objects used by VB6 are COM objects. A COM object is a variable-length data structure whose header length contains any number of 32-bit pointers to VTables, and daily bytes contain object instance data. For instance,

Bytes 0-3 VTable1 pointer 4-7 VTable2 pointer 8-11 VTable3 pointer ... Instance data 

. VTable is an array of 32-bit function pointers, all of which are passed by the pointer to an instance of "this".

 Bytes 0-3 Func1(this, ..., ...) 4-7 Func2(this, ..., ...) 8-11 Func3(this, ..., ...) ... 

The only other specification is that all VTables MUST inherit from IUnknown, i.e. The first three functions should be:

 QueryInterface() AddRef() Release() 

Essentially, QueryInterface () lets you know if a COM object supports a specific interface (which is represented by a UUID). AddRef () allows the author of the object to increase the internal reference count. Release () allows the author of the object to decrease the reference count, destroying the object when the counter is zero. You never call these methods in VB - the compiler adds these calls to you (one of the advantages of VB6).

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms680509(v=vs.85).aspx for more details.

The VB type β€œObject” is a reference to an object that supports the IDispatch interface (see http://msdn.microsoft.com/en-us/library/windows/desktop/dd318520(v=vs.85).aspx ). This allows you to do late binding in VB and VBScript. All objects written in VB6 automatically implement an interface that inherits from IDispatch. This is called a dual interface because it supports early and late binding.

Note that there is no direct type embedded system in COM. However, you can choose to support the ITypeInfo interface, which allows users of your object to access the information you want to add about the object (it is easier to use the default implementation, which uses type libraries to store this information).

The Variant type, as Bob Rimersma mentioned, is actually a 16-byte structure that has a 2-byte integer (vt) that indicates which type of automation is encapsulated, and the last 8 bytes can be used to store value types up to 8 bytes or a 32-bit pointer to another type. VB performs all necessary conversions between VB types and variants, using its internal functions, as well as all necessary memory allocations and freeing memory. Variants can contain references to COM objects by copying a pointer to an object in Variant and calling the AddRef () method of the object.

+9
source

Let me break this down into separate questions:

First, VB6 is not VB.Net and does not use the .NET Framework, but instead uses the older COM environment. (I can’t say if you know this).

Secondly, what your link points to is really Classes built into VB6. Although, yes, he calls them "Objects." Careless terminology on their part.

Third, and, most importantly, in VB6, everything is not an object, and objects are not even a standard or dominant category of data types. What is it, something like .Net value types, but much smaller (most did not even have run-time type containers, only addresses in memory).

Thus, most data elements were not objects, therefore they did not have classes, therefore they did not have any inheritance, therefore they were not received from anything else, and therefore did not have a "type hierarchy", and therefore could not be all at the "top "their type hierarchies (although things that were classes / objects had it all). Thus, you did not have a base / root data type that you could use for any other data type, which would be a problem for all cases of passing parameters, etc. Situations.

The options were a kind of preliminary solution to this problem, which in earlier versions of VB were implemented (before objects in VB) to solve this problem. A variant is simply a dynamic descriptor that wraps another element of any data type. When you use it, it (as a rule) acts as if you are directly using what it contains, but you really go through the option to get some type of data item that it currently contains.

Variant itself keeps track of what type of content data it is and invokes the VB code to access it differently / appropriately (a primitive kind of polymorphism).

If that sounds like his shreds and there was a lot of overhead, well, that was it. But at the time, it was the best solution available when you needed to process "any type of data."

+5
source

Source: https://habr.com/ru/post/912883/


All Articles