the _Create-function is (as _Destroy or _Get and _Set) developed not to be called. They are invoked internally in certain moments and act as events.<br><br>to initialize your types you can create a function named as "Init" or "AfterCreation" / whatever as long it starts with an alphabet char. <br>Underscore might be defined as word/char (\w) in regex but is actually not [A-Za-z]<br>when you want to use a technique as Overloading parameters - its difficult for type-functions to develop but for "normal functions" you can use different approaches to pass different parameter-types either byref or byval to a function that will check what is passed to it and call the dedicated function for the received count and type of parameters. <br>Your friends are keywords as <br><br>Optional<br>As Variant<br>As AnyType <br>...(Any) As ...<br><br>for headline of the function that "borrows" the common shared name to the different functions.<br><br>What you have to decide in advance is if are all parameters to pass byval or all byRef / will you need one byref always or 2 - are they optional or not and haw many will be byval - for the function that uses the less parameters then you can plan how to order these. Alike all child-functions will receive 1 byref parameter always and one optional byref and all will have at least 2 parameters byval and one optional byval ... of course the optional parameters are to pass at the end and non-optional before. <br>ByRef means it works with some memory address that could be passed byval as well if the function knows the type to deal with. And Variants allow to receive different variable types and you can sort them by VariantVT to use either Variant$ and take it as String or Variant# wich will whatever the parameter contains in numeric way. <br><br><br>If its like homogennous parameters in a row consider the use of variadic parameters that will receive an infinite bunch of same type in a row and hold the value as you know from any array. So if there is a parameter that is always present, but it differs how many of those are up to come then this can be a variadic parameter.<br>the actual functions that shall share the same name for the user are still different functions and the main-function - Lets name it DoSomething() will call the correct one depending what the user has passed.<br><br>
<br><br>Function Do something(ByRef anObject As AnyType,<br> Byval position(ANY) as PointApi,<br> Byval vParam1 as Variant, <br> optional byval vParam2 as Variant,<br> Byref pOtherObject As myUDTVar Ptr [,...]) As String<br> <br>' the function seperates now what to process under the name "DoSomething" where depending on the parameters differnt things will be done. this function "knows" the name of itself:<br><br>string thisFunc=FunctionName<br>long passedParametersCount =Function_CParams <br>
<br> it could determine typeOf(anObject) or just pass it further byref<br> the position can be different amount but at least 1 must be given. The variadic parameters must be <br> passed inbetween parenthesis as <br><br>
<br>Long X=DoSomething(W as tWindow, (P1, P7, P5, P3), "wash")<br>
<br>and <br>
<br>String IcanSee = DoSomething(B as tButton, (p1,p2), 5, "push") <br>
<br><br>Depending on what TypeOf(anObject)<br>and the CountOf(position)<br>[ Select Case] VariantVT(vParam1) <br> Case %VT_Asciiz, 8 ' we have a string<br> sValue = Variant$(vParam1) <br> Case %VT_Ext ' we have a number<br>...<br>Function_cParams tells how many altogether were passed.<br>when this function passes the received result of the function that it called depending on parameters<br>back to the caller in form of a string/ thinbasic "knows" what the caller expects and even if is a byte or an udt that he might expect - it will be the sequence of bytes that you can hand over in a dynamic string.<br><br>You can not only decide by the count and kind of parameters but as well with the content of some.<br>lets say you make the last non-optional parameter and the ones before to be variants and depending if it is a string-variant-type your delegation-call can be as simple as<br><br><span style="color:#0000cd;"><span style="font-family:courier new;"><strong>Call_IfExists "" & Replace$(Function_Name, "TH", Variant$(vParam1)) (anObject, position )<br></strong><span style="font-family:arial;"><br>and it would call something as DoSomeWashing or DoSomePushing from here</span><strong> <br></strong><span style="font-family:arial;">The double double-quote will preven it from misinterpreting maybe a string or its own function-name in front but bame sure to use the literal string content to create a functions name...i hope contains some ideas for you
soorry the second time today it does that. i am not in the mood to remove the mess made by some strange html bug na
Bookmarks