Page 1 of 1
How to distinguish between many types of object?
Posted: 16 Feb 2020, 08:16
by arcticir
Type () can be used to distinguish obj-map_arr, but I don't know how to classify some special objects, such as class. Does the class object have any characteristics that can be used to judge?
for i,n in type(t)="object"?t.OwnProps():t
The current solution is to create a list of all possible occurrence types, and if it is not in the list, it is a class.
Re: How to distinguish between many types of object?
Posted: 16 Feb 2020, 08:58
by HotKeyIt
Code: Select all
Class test{
}
MsgBox Type(test) ;Class
MsgBox test.prototype.__Class ;test
Re: How to distinguish between many types of object?
Posted: 16 Feb 2020, 09:12
by arcticir
such?
Code: Select all
Class test{
}
t:=test.new()
MsgBox Type(t) ;Class
MsgBox t.prototype.__Class ;test
Re: How to distinguish between many types of object?
Posted: 16 Feb 2020, 11:34
by HotKeyIt
Code: Select all
Class test{
}
t:=test.new()
MsgBox t.base.base.__Class ;Object
MsgBox Type(t) ;test
Re: How to distinguish between many types of object?
Posted: 16 Feb 2020, 12:20
by arcticir
Code: Select all
MsgBox [].base.base.__Class ;Object
So you have no characteristics.
In fact, there is only one place I need to judge its exact type:
for k,v in obj ;--->> obj? or obj.OwnProps()?
Re: How to distinguish between many types of object?
Posted: 16 Feb 2020, 13:43
by HotKeyIt
Probably:
Code: Select all
Class test{
}
t:=test.new()
t.1:=1
t.a:=2
for k, v in (t.hasMethod("__Enum")?t:t.OwnProps())
MsgBox k "`n" v
EDIT: fixed code
Re: How to distinguish between many types of object?
Posted: 16 Feb 2020, 15:37
by HotKeyIt
Actualy it is easier to add __Enum to object class:
Code: Select all
Class test{
__Enum(*) => this.OwnProps()
}
t:=test.new()
t.1:=1
t.a:=2
for k, v in t
MsgBox k "`n" v
Re: How to distinguish between many types of object?
Posted: 16 Feb 2020, 15:49
by arcticir
Thank you. We should consider that the source of many classes is unknown.
Re: How to distinguish between many types of object?
Posted: 18 Feb 2020, 10:15
by arcticir
Struct does not have hasMethod, hasMethod("__Enum ") does not seem to be the perfect solution.
Re: How to distinguish between many types of object?
Posted: 18 Feb 2020, 16:53
by HotKeyIt
I have added HasMethod to Struct.
Note that not all objects (COM) will support __Enum/for loop.
Re: How to distinguish between many types of object?
Posted: 19 Feb 2020, 00:19
by arcticir
Thank you.
Re: How to distinguish between many types of object?
Posted: 20 Feb 2020, 12:43
by Helgef
Hi
.
You might find
is useful.
Cheers.
Edit, you are correct
.
Re: How to distinguish between many types of object?
Posted: 21 Feb 2020, 05:22
by arcticir
It does not help judge the two:
obj.__Enum or obj.OwnProps()