Code: Select all
buf := Buffer(1)
MsgBox 'IsObject: ' . IsObject(buf) . '`n' ; true
. 'Has Clone() method: ' . buf.HasMethod('Clone') ; true
newVar := buf.Clone() ; <———— "Type mismatch" error
Code: Select all
buf := Buffer(1)
MsgBox 'IsObject: ' . IsObject(buf) . '`n' ; true
. 'Has Clone() method: ' . buf.HasMethod('Clone') ; true
newVar := buf.Clone() ; <———— "Type mismatch" error
"Must"? Are you sure about that?teadrinker wrote: ↑12 Feb 2024, 17:33Buffer extends Object and must inherit all of its methods and properties, including the Clone() method.
Nowhere does it say that not all methods are inherited, or any of them are overridden.Buffer Object wrote:In addition to the methods and property inherited from Object, Buffer objects have the following predefined properties.
This may be true but that it "must inherit" all the methods and properties is not correct as far as I know.. semantics.teadrinker wrote: ↑13 Feb 2024, 02:38Nowhere does it say that not all methods are inherited, or any of them are overridden.Buffer Object wrote:In addition to the methods and property inherited from Object, Buffer objects have the following predefined properties.
just me wrote: ↑13 Feb 2024, 04:22What would you do with a cloned buffer?
Clone creates a shallow copy of an object, i.e. 'each property or method owned by the object is copied into the clone'. The Buffer object has two special properties, Ptr and Size. The memory block assigned to the buffer doesn't seem to be an own property. So cloning a buffer most probably would generate two buffer objects pointing to the same memory block. Would it make sense?
Code: Select all
Error: Type mismatch.
002: FO := FileOpen(A_ScriptFullPath, "r")
▶ 003: FO2 := FO.Clone()
004: FO.Close()
005: Exit
Show call stack »
But is it forbidden? Let's check it out:
Code: Select all
memBlock := 'someString'
MyBuffer := {}
MyBuffer.ptr := StrPtr(memBlock)
MyBuffer.size := StrLen(memBlock) * 2 + 2
MsgBox 'ptr: ' . MyBuffer.ptr . '`n'
. 'size: ' . MyBuffer.size
NewBuffer := MyBuffer.Clone()
MsgBox 'ptr: ' . NewBuffer.ptr . '`n'
. 'size: ' . NewBuffer.size
Basically every built-in class is a "native type", with the exception that Error and Class objects are the same as Object.If assigning the new base would change the native type of the object, an exception is thrown. An object's native type is decided by the nearest prototype object belonging to a built-in class, such as Object.Prototype or Array.Prototype. For example, an instance of Array must always derive from Array.Prototype, either directly or indirectly.
Source: Object - Methods & Properties | AutoHotkey v2
Users browsing this forum: No registered users and 29 guests