iOS Question Problem with Struct

jcesar

Active Member
Licensed User
Longtime User
Hi

Im declare a user Type in Process_Globals:

B4X:
Type Rodovias(Nome As String,NumRodovia As String, Cameras As String,Telefone As String,Imagem As String,act As String)

So, i create a array of this type

B4X:
Public arrRodovias(5) As Rodovias

when i try insert some values in this array i get the error below:

B4X:
rrRodovias(0).Nome = "Rodovia dos Tamoios"   
    arrRodovias(0).Cameras = "7"
    arrRodovias(0).NumRodovia = "SP-99"
    arrRodovias(0).Telefone = "0800-055-5510"
    arrRodovias(0).Imagem = "img_tamoios.png"
    arrRodovias(0).act = "Tamoios2"


B4i line: 48
arrRodovias(0).Nome = \
property 'Nome' not found on object of type 'NSObject *'

Out: Build settings from command line:
ARCHS = armv7
CODE_SIGN_IDENTITY = iPhone
CONFIGURATION_BUILD_DIR = /Users/administrator/Documents/UploadedProjects/ah48dh8/Payload
OTHER_CODE_SIGN_FLAGS = --keychain ah48dh8
PRODUCT_NAME = B4i Example
PROVISIONING_PROFILE = 1d0981bb-65b7-4435-aa0a-ea2be859787e
 

moster67

Expert
Licensed User
Longtime User
I got the same error the first time I tried to compile it. I also got an error indicating Error: security: SecKeychainDelete: The specified keychain could not be found.

Then I got it to work using your code but I don't remember what changes I did :(. When it worked. iterating the array, I got the following output:
B4X:
output:

[IsInitialized=0, Nome=Rodovia dos Tamoios, NumRodovia=SP-99
, Cameras=7, Telefone=0800-055-5510, Imagem=img_tamoios.png
, act=Tamoios2]

I tried again but it would not work any more. Weird: Unsure what I did to get it to work. I tried both on Remote Server and Local MAC.

Anyway, the following code seems to work:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Type Rodovias(Nome As String,NumRodovia As String, Cameras As String,Telefone As String,Imagem As String,act As String)

End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    Dim MyTypeArray() As Rodovias = Array As Rodovias(CreateMyType("Rodovia dos Tamoios","7","SP-99","0800-055-5510","img_tamoios.png", "Tamoios2"))

    For x = 0 To MyTypeArray.Length -1
        Log(MyTypeArray(x))
    Next

End Sub

Sub CreateMyType (Nome1 As String,NumRodovia2 As String, Cameras3 As String,Telefone4 As String,Imagem5 As String,act6 As String) As Rodovias
Dim arrRodovias As Rodovias
arrRodovias.Initialize
arrRodovias.Nome = Nome1
arrRodovias.Cameras = NumRodovia2
arrRodovias.NumRodovia = Cameras3
arrRodovias.Telefone = Telefone4
arrRodovias.Imagem = Imagem5
arrRodovias.act = act6
Return arrRodovias
End Sub

This time the output is:
B4X:
[IsInitialized=1, Nome=Rodovia dos Tamoios, NumRodovia=SP-99
, Cameras=7, Telefone=0800-055-5510, Imagem=img_tamoios.png
, act=Tamoios2]

Take note that with the first code IsInitialized=0 but this time it is IsInitialized=1

PS: Erel, I couldn't find any B4i-documentation for Type
 
Last edited:
Upvote 0

jcesar

Active Member
Licensed User
Longtime User
Thanks for your reply.

I will try this code.

I think the problem is something with Initialize method
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
If you want to add more items to your array, you can probably use (not tested):
B4X:
Dim MyTypeArray() As Rodovias = Array As Rodovias (CreateMYType(...), CreateMyType(...), ...)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hi

Im declare a user Type in Process_Globals:

B4X:
Type Rodovias(Nome As String,NumRodovia As String, Cameras As String,Telefone As String,Imagem As String,act As String)

So, i create a array of this type

B4X:
Public arrRodovias(5) As Rodovias

when i try insert some values in this array i get the error below:

B4X:
rrRodovias(0).Nome = "Rodovia dos Tamoios"  
    arrRodovias(0).Cameras = "7"
    arrRodovias(0).NumRodovia = "SP-99"
    arrRodovias(0).Telefone = "0800-055-5510"
    arrRodovias(0).Imagem = "img_tamoios.png"
    arrRodovias(0).act = "Tamoios2"


I think the initialization misses.
 
Upvote 0
Top