Super Strict
BlitzMax Forums/BlitzMax Beginners Area/Super Strict
| ||
I try to use SuperStrict all the time, It helps, but for some reason.Local B:Int=1 Local Ent:Object=HandleToObject(B) That code compiles and runs in my program as expected, but with superstrict is says unable to convert INT to OBJECT. I'm confused because I thought HandletoObject takes an INT Handle and Converts it to an Object. Help. |
| ||
Well, B isnt an Handle to an Object is it? Basicly, (From my understanding) you need you use Handlefromobject, with an object, assign that to (b for eample), then convert it back when you want with HandletoObject |
| ||
SuperStrict Type TTest Field x:Int End Type Global A:TTest = New TTest A.x = 100 Global B:Int = HandleFromObject(A) Global C:TTest = TTest(HandleToObject(B)) Print C.x What H&K said |
| ||
An Integer is not an object, so could can't get a handle for it. Objects (in this meaning) are String,Object,Type. (Did I forget one?). |
| ||
Type is Object (or implicitely extends from it) But Array is missing |
| ||
I thought HandleToObject Took an integer handle and converted it to it's equivalent Object. |
| ||
It does, but thats not what you posted You posted the paramater as being a simple INT, which by shear luck might be a handle or might not, Like say if you picked 28097. What you have do, as perts code showed, was first make sure that the INT you are passing is a valid handle number, by using HandleFromObject(TheObject) |
| ||
OK ok I got you now, sorry... I put B=1 as a sample... Because The Integer handle is not known at compile time therefore the value of the integer seemed arbirtary. My problem is that my program compiles and runs properly, but when I use superstrict it complains during compilation. Regards, Eric |
| ||
Ahhh, right I see. (But I am speculating on the answer) Normaly the compiler would, when not told to cast the Object, instead pass an int handle of the object. So HandleToObject(B)Converts the handle b into the object its the handle of, but then because of the lack of cast, turns it back into a handle. (It maybe that HandleToObject(B) just returns an internal handle, but the point is the same) SuperStrict would pick this up, and stop the compilation saying that it cannot convert INT to Object AType(HandleToObject(B))would cast whatever the result is into an AType Function _HandleToType:TbbEntity (Comparisonhandle:Int) Select bbEntityClass (Comparisonhandle) Case "Pivot" Return TbbPivot (HandleToObject(bbEntityID(Comparisonhandle))) Case "Light" Return TbbLight (HandleToObject(bbEntityID(Comparisonhandle))) Case "Camera" Return TbbCamera (HandleToObject(bbEntityID(Comparisonhandle))) Case "Mirror" Return TbbMirror (HandleToObject(bbEntityID(Comparisonhandle))) Case "Listener" Return TbbListener (HandleToObject(bbEntityID(Comparisonhandle))) Case "Sprite" Return TbbSprite(HandleToObject(bbEntityID(Comparisonhandle))) Case "Terrain" Return TbbTerrain (HandleToObject(bbEntityID(Comparisonhandle))) Case "Plane" Return TbbPlane (HandleToObject(bbEntityID(Comparisonhandle))) Case "Mesh" Return TbbMesh (HandleToObject(bbEntityID(Comparisonhandle))) Case "MD2" Return TbbMD2 (HandleToObject(bbEntityID(Comparisonhandle))) Case "BSP" Return TbbBSP (HandleToObject(bbEntityID(Comparisonhandle))) End Select End FunctionThis is just a snippet that I grabed quickly, but as you can see each HandleToObject return is imediatly Cast to the type it is. (For ppl with the SDK. It doesnt work, cos bbEntityClass in the SDK hasnt been implemented properly yet, it was just the most relevent example I had at hand :-) |
| ||
Local Ent:Object=HandleToObject(pxGetBodyUserData(Body)) Here is the code.... Ugh! I'm not sure how to fix it other that to not use SuperStrict. |
| ||
DoesLocal Ent:Object=Object (HandleToObject(pxGetBodyUserData(Body)))Work? Generaly turning anything into "Object" is pointless, unless you have overridded "toString()", which you then look at, decide which specific Type Object is, and cast it into that. |
| ||
I will try that... The actual Type I use is TPhysicsObject.. So I think I have tried. Local Ent:TPhysicsObject=TPhysicsObject(HandleToObject(pxGetBodyUserData(Body))) But I will try when I get home. I guess my underlying questions is without superstrict...the program runs correctly. Meaning to me that the code is "Good" in a not strict sense..... Why? |
| ||
because non strict allows all unclean, instable and especially seriously slower B3D hacks ... running in non strict results in code slow and highly undesired (and if intend for others: inacceptable) code |
| ||
delete |
| ||
Eric, Ive had the same problem before, I was trying to cast (but without the cast), for my create methods. And it ran in normal mode, but not in SuperStrict. And someone pointed out that it was running, but not giving the right answer. Normaly I would say always use superstrict. |
| ||
The sample code in OP compiles just fine under SuperStrict. The problem is that HandleToObject() returns Null if the handle number doesn't exist. Try to use the object returned in your sample, it will give you an error. All HandleFromObject() does is hash the pointer of the BB object, store that in an array, and return the position in the array of the hash. If that hasn't been done, HandleToObject() has nothing to return from the array, so it just gives you Null. |
| ||
YeahSuperStrict Local B:Int Local Ent:Object=HandleToObject(B) Compiles firn but with the Method I have it in it does not. This is not a Run time problem currently Blueapples, it's a compile time problem. But since the code above compiles and the same code inside a my type method does not, that means there are more problems, so I REM it out and the program compiles fine in SuperStrict. Hmm..... OH crap!! I had Import "blitz3d.bmx"at the top of my program. This is for those of us that are using the B3dSDK it was at the top of a sample program and I did not delete it. The Include has this at the bottom. Function HandleToObject:Object(obj:Object) Return obj End Function Function HandleFromObject(obj:Object) Local h=HandleToObject(obj) Return h End Function I suppose this will screw you up because there are no type declarations and they don't make any sense..They both take an Object as the input parameter. AHHHH!!!!! |
| ||
http://www.blitzmax.com/Community/posts.php?topic=70163 |
| ||
Gosh ... I did a search for HandletoObject and that post didn't show up. I wish I had found that to begin with. |