Trouble with Property returning by propName = value (solved)
Re: Trouble with Property returning by propName = value (solved)
Only one indexing parameter is allowed for a get/set-Property.
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: Trouble with Property returning by propName = value (solved)
For a setter, 2 slots are allowed. Ok I never paid attention to this :)fxm wrote:Only one indexing parameter is allowed for a get/set-Property.
Does this mean that the getter index is an integer only?
Re: Trouble with Property returning by propName = value (solved)
No, the indexing parameter can be of any type.
KeyPgProperty → fxm [Added note on returning from an indexed get-Property]
KeyPgProperty → fxm [Added note on returning from an indexed get-Property]
Re: Trouble with Property returning by propName = value (solved)
Could a byref function be more versatile than property?
You can have many parameters, get and set, and the code is more readable and shorter.
You can have many parameters, get and set, and the code is more readable and shorter.
Code: Select all
#include "crt.bi"
type UDT extends OBJECT
declare function Prop() byref as integer
private:
as integer ref=1
end type
function UDT.Prop() byref as integer
Prop = ref
end function
dim as UDT uuu
? uuu.Prop
type UDT2 extends OBJECT
declare function Prop2(byval as integer=0,byref as zstring="",byref as any ptr=0) byref as integer
private:
as integer ref=2
end type
function UDT2.Prop2(byval z as integer,byref s as zstring,byref p as any ptr) byref as integer
prop2= ref
if len(s) then print s:p=@s[0]
if z then system_("pause")
end function
dim as UDT2 vvv
print vvv.Prop2
vvv.prop2=123
print vvv.prop2
dim as udt2 u
print u.prop2
dim as any ptr z
u.prop2(,"Done",z)
print *cast(zstring ptr,z)
u.prop2(1)
Re: Trouble with Property returning by propName = value (solved)
Yes, but except for:
u.prop2(1)=456
which fails when only the first parameter of the function is used.
Right syntaxes for that case:
(u.prop2(1))=456
or:
u.prop2(1)=>456
u.prop2(1)=456
which fails when only the first parameter of the function is used.
Right syntaxes for that case:
(u.prop2(1))=456
or:
u.prop2(1)=>456
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: Trouble with Property returning by propName = value (solved)
Yes I more and more think that returning byref is almost a good choice by default all the time. It's true for Cast also. As pointed out by fxm, the only disturbing detail is the patenthesis of the assignment. But I will read it as "evaluate me", so I understand that it is made to target the returnec value and I can see a logic to that. I jusy neec to take the reflex to use it mire often.dodicat wrote:Could a byref function be more versatile than property?
You can have many parameters, get and set, and the code is more readable and shorter.Code: Select all
#include "crt.bi" type UDT extends OBJECT declare function Prop() byref as integer private: as integer ref=1 end type function UDT.Prop() byref as integer Prop = ref end function dim as UDT uuu ? uuu.Prop type UDT2 extends OBJECT declare function Prop2(byval as integer=0,byref as zstring="",byref as any ptr=0) byref as integer private: as integer ref=2 end type function UDT2.Prop2(byval z as integer,byref s as zstring,byref p as any ptr) byref as integer prop2= ref if len(s) then print s:p=@s[0] if z then system_("pause") end function dim as UDT2 vvv print vvv.Prop2 vvv.prop2=123 print vvv.prop2 dim as udt2 u print u.prop2 dim as any ptr z u.prop2(,"Done",z) print *cast(zstring ptr,z) u.prop2(1)
edit: my keyboard is drunk?
By the way, dodicat, I'm using your pool game fonts in my game contest project. Thanks by advance , it will preserve sensitive eyes :)