JMB Active Member Licensed User Longtime User Sep 28, 2019 #1 Hi there. I've created a Type like this: Code: Copy Type FlightWaypoint(Name as String, Position as Location) The problem is that I have to do two Initialize calls... Code: Copy Dim FW as FlightWaypoint FW.Initialize FW.Position.Initialize Aside from creating a class, is there a way of avoiding this double initialize requirement? Thanks, JMB
Hi there. I've created a Type like this: Code: Copy Type FlightWaypoint(Name as String, Position as Location) The problem is that I have to do two Initialize calls... Code: Copy Dim FW as FlightWaypoint FW.Initialize FW.Position.Initialize Aside from creating a class, is there a way of avoiding this double initialize requirement? Thanks, JMB
E emexes Expert Licensed User Longtime User Sep 28, 2019 #2 JMB said: Aside from creating a class Click to expand... I wondered this early on too, but not as deeply as you. I think you may have answered your own question. But it's not all bad. About half of the time, I end up adding methods or extra fields that need non-blank initializing to the "type"... at which point I'm like: how lucky was that?!?! Last edited: Sep 28, 2019 Upvote 0
JMB said: Aside from creating a class Click to expand... I wondered this early on too, but not as deeply as you. I think you may have answered your own question. But it's not all bad. About half of the time, I end up adding methods or extra fields that need non-blank initializing to the "type"... at which point I'm like: how lucky was that?!?!
klaus Expert Licensed User Longtime User Sep 28, 2019 #3 What you do to you need FW.Position.Initialize? When you set a location, which must be initialized no need to initialize FW.Position. I tried the code below without FW.Position.Initialize. Code: Copy Private FW As FlightWaypoint FW.Initialize FW.Name = "MyPoint" Private loc As Location loc.Initialize2(45.0, 7.5) FW.Position = loc Log(FW.Position.Latitude) Or am I missing something? Upvote 0
What you do to you need FW.Position.Initialize? When you set a location, which must be initialized no need to initialize FW.Position. I tried the code below without FW.Position.Initialize. Code: Copy Private FW As FlightWaypoint FW.Initialize FW.Name = "MyPoint" Private loc As Location loc.Initialize2(45.0, 7.5) FW.Position = loc Log(FW.Position.Latitude) Or am I missing something?
LucaMs Expert Licensed User Longtime User Sep 28, 2019 #4 It is obvious that if a Type contains objects they must be initialized. In this case Klaus's answer is correct, in my opinion. Upvote 0
It is obvious that if a Type contains objects they must be initialized. In this case Klaus's answer is correct, in my opinion.
agraham Expert Licensed User Longtime User Sep 28, 2019 #5 When the FlightWaypoint Type is instantiated by Dim it contains an instance of a Location as its Position item. If, as in Klaus' case, you are immediately going to overwrite that with a different instance of a Location then you do not need to Initialize it. On the other hand if you are going to use the pre-provided instance you will need to Initialize it otherwise you will get a run-time NotInitialized error. One way or another you will need to always Initialize each instance of a Location, B4A will not do it for you. Upvote 0
When the FlightWaypoint Type is instantiated by Dim it contains an instance of a Location as its Position item. If, as in Klaus' case, you are immediately going to overwrite that with a different instance of a Location then you do not need to Initialize it. On the other hand if you are going to use the pre-provided instance you will need to Initialize it otherwise you will get a run-time NotInitialized error. One way or another you will need to always Initialize each instance of a Location, B4A will not do it for you.
JMB Active Member Licensed User Longtime User Sep 28, 2019 #6 Thank you all once again for that information - that has resulted in much greater understanding. JMB Upvote 0