I've searched and haven't found an answer to this, so apologies if it's been answered and I missed it:
I've set up a custom type and set two variables as the type:
curPet is the current info entered for the pet. changePet is info entered into a form. I initially set them equal to each other then on field changes in the form, set the values for changePet. I normally just use maps for this but thought a custom type would be a bit more elegant and easier to trace back through. Do I have to iterate through each value in the type and compare them or can I just compare the two variables? It's looking like I have to iterate but I want to make sure I'm not missing something. My goal is to compare curPet to changePet to determine if the user needs to save changes to the DB or not when they navigate away from the form. I'm currently testing with a button on the form:
This always shows the "No Changes" message. If I instead do
It works properly but doesn't really seem to be any more efficient than just using a couple of maps. Is there a way to get them to compare without iterating through each value?
I've set up a custom type and set two variables as the type:
B4X:
Sub Process_Globals
Type Pet(Name as String, Species as String, Breed as String, _
Notes as string, Photo as Image)
.
.
.
End Sub
Sub AppStart
Dim curPet, changePet as Pet
init_pet(curPet)
init_pet(changePet)
.
.
.
End Sub
Sub init_pet(p as pet)
p.Name = ""
p.Species = ""
p.Breed = ""
p.Notes = ""
p.Photo.initialize(FileAssets, "blank.jpg")
End Sub
curPet is the current info entered for the pet. changePet is info entered into a form. I initially set them equal to each other then on field changes in the form, set the values for changePet. I normally just use maps for this but thought a custom type would be a bit more elegant and easier to trace back through. Do I have to iterate through each value in the type and compare them or can I just compare the two variables? It's looking like I have to iterate but I want to make sure I'm not missing something. My goal is to compare curPet to changePet to determine if the user needs to save changes to the DB or not when they navigate away from the form. I'm currently testing with a button on the form:
B4X:
Sub btnTest_Click
curPet.Name = "Fluffy"
changePet.Name = "Whiskers"
if curPet = changePet then
msgbox.show("No Changes", "Test")
else
msgbox.show("Info Changed", "Test")
end if
End Sub
This always shows the "No Changes" message. If I instead do
B4X:
If curPet.Name = changePet.Name Then