Trying to use some v1 code in v2 (with minimal changes where needed).
The v1 code has a nested class Encrypt defined inside of class Crypt, and some methods (including StrEncrypt()) defined inside of class Encrypt... see excerpt below.
User code: hash := Crypt.Encrypt.StrEncrypt(input:="123",pw:="test",CryptAlg:=5,HashAlg:=1)
Error: This value of type "Class" has no method named "StrEncrypt"
Code Excerpt (with method definition statements)
class Crypt
{
class Encrypt
{
static StrEncoding := "UTF-16"
static PassEncoding := "UTF-16"
StrDecryptToFile(EncryptedHash,pFileOut,password,CryptAlg:=1, HashAlg:=1)
...
FileEncryptToStr(pFileIn, password, CryptAlg:=1,HashAlg:=1)
...
StrEncrypt(stringArg,password,CryptAlg:=1,HashAlg:=1)
...
etc.
(Full library here: Crypt.ahk)
I'm unclear if there is a difference in the way classes and nested classes are defined between v1 and v2, or if there was possibly an implicit relationship between the class and nested class in v1, which potentially no longer exists in v2, i.e., "Nesting a class does not imply any particular relationship to the outer class." (from v2 Objects help under Nested Classes sub-topic).
I'm looking for any clues or pointers on modifications that might be needed to get the class structure working in v2 for this library.
A minimal v2 example with a nested class might also point me in the right direction... I haven't found one yet that correlates to the type of usage shown above.
Thanks in advance...
v2 Nested Class definition Topic is solved
Re: v2 Nested Class definition Topic is solved
Code: Select all
class Crypt {
class Encrypt {
; Crypt.Encrypt.Prototype.StrEncrypt()
StrEncrypt() {
MsgBox "instance method"
}
; Crypt.Encrypt.StrEncrypt()
static StrEncrypt() {
MsgBox "static Method"
}
}
}
; Instance methods are contained inside the class Prototype property.
; It can be called directly like this.
Crypt.Encrypt.Prototype.StrEncrypt()
; Normally, instance methods are called from a class instance.
inst := Crypt.Encrypt()
inst.StrEncrypt()
; Static methods can be called directly.
Crypt.Encrypt.StrEncrypt()
Re: v2 Nested Class definition
As demonstrated by ntepa, the issue is to do with instance vs. static properties, not class nesting.
The documentation explains all of the differences between v1 and v2 with regard to objects/classes (and hopefully all other topics).
https://www.autohotkey.com/docs/v2/v2-changes.htm#objects
For this script, I think there are unlikely to be any differences that matter (considering only class nesting).
The v2 documentation is generally newer, and therefore more likely to cover for misconceptions that have come up over time.
The documentation explains all of the differences between v1 and v2 with regard to objects/classes (and hopefully all other topics).
https://www.autohotkey.com/docs/v2/v2-changes.htm#objects
For this script, I think there are unlikely to be any differences that matter (considering only class nesting).
No, there was never any such implicit relationship. If there was, the change would be documented above.if there was possibly an implicit relationship between the class and nested class in v1
The v2 documentation is generally newer, and therefore more likely to cover for misconceptions that have come up over time.
-
- Posts: 204
- Joined: 24 Jun 2015, 23:38
Re: v2 Nested Class definition
Thanks both for replies. The simplified example was particularly useful and marking the classes static enabled the calling notation (in the original code, which I didn't write), to remain the same.