B4R Question Using Type

el andy

New Member
Licensed User
Longtime User
Hi
when I try this (ESP32):

Sub Process_Globals
Type Type_Sys1(Serial1 As Serial)
Public Sys1 As Type_Sys1
End Sub

Private Sub AppStart
Sys1.Serial1.Initialize(115200)
Log("AppStart")
End Sub

I get a lot of errors when I run this code. Why ?

Regards, el Andy
(Sorry my english is not good)
 

el andy

New Member
Licensed User
Longtime User
Hi Mauro, here the errors.
serial_NO_OK.png
 
Last edited:
Upvote 0

el andy

New Member
Licensed User
Longtime User
Hi Mauro, this is the standard way to do it, but i like to use structures,
serial_OK.png


el Andy
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Please use [code]code here...[/code] tags when posting code.
2. Post error and code as text, not screenshots.

This code will work:
B4X:
Sub Process_Globals
   Type Type_Sys1(serial1 As Serial)
   Public Sys1 As Type_Sys1
   Private serial As Serial
End Sub

Private Sub AppStart
   Sys1.serial1 = serial
   Sys1.serial1.Initialize(115200)
   Log("AppStart")
End Sub

Sys1.serial is a pointer to a Serial object. When you declared Sys1 as a global variable, the compiler only allocated the memory required for the structure.
It didn't create a Serial object (it can't). So the only way to use custom types with non-numeric fields is by assigning them yourself in the code above.
 
Upvote 0
Top