defining a Function inside a type is just a way of associating that function with that type, and saving namespace.
For example:
is functionally the same as:
but now you can have lots of types each with a Find function, instead of making finddude, finddog, findtree etc.
Now, methods are fucntions that deal with a particular instance of a type, and allow you access to the instance's fields in the top namespace.
is the same as:
but you don't have to pass in the dude you're using as a parameter, and you can write just 'name' instead of 'd.name'.
For example:
Function finddude(name$) For d:dude=EachIn dudes If d.name=name Return d Next End Function Global dudes:TList Type dude Field name$ End Type
is functionally the same as:
Global dudes:TList Type dude Field name$ Function find(name$) For d:dude=EachIn dudes If d.name=name Return d Next End Function End Type
but now you can have lots of types each with a Find function, instead of making finddude, finddog, findtree etc.
Now, methods are fucntions that deal with a particular instance of a type, and allow you access to the instance's fields in the top namespace.
Function changedudename(d:dude,newname$) d.name=newname End Function Type dude Field name$ End Type
is the same as:
Type dude Field name$ Method changename(newname$) name=newname End Method End Type
but you don't have to pass in the dude you're using as a parameter, and you can write just 'name' instead of 'd.name'.