Jump to content

Is there a way to define customized structs?


Shy
 Share

Recommended Posts

1. I would like to define customized structs (like in C) so I can refer to various info regarding an object.

For example, struct for Car

could have Model, Color, Weight.

Is there anyway to do it in Autoit?

2. Also, I saw that commands after . appear in blue (for example someCommand.otherCommand), I was wondering what are they used for.

Thank you in advance

Link to comment
Share on other sites

You can create your own structures, see the example.

But i think it's more easy to use an 2D-array.

; === hold structure in an array
; === 1.st value holds structure definition
Local $aCarStruct[1] = ["char model[128];char color[128];int weight"]

; === create new car
ReDim $aCarStruct[UBound($aCarStruct)+1]
$aCarStruct[UBound($aCarStruct)-1] = DllStructCreate($aCarStruct[0]) ; === create structure
DllStructSetData($aCarStruct[UBound($aCarStruct)-1], 'model', 'Jaguar') ; === set values
DllStructSetData($aCarStruct[UBound($aCarStruct)-1], 'color', 'silver')
DllStructSetData($aCarStruct[UBound($aCarStruct)-1], 'weight', 1511)

ReDim $aCarStruct[UBound($aCarStruct)+1]
$aCarStruct[UBound($aCarStruct)-1] = DllStructCreate($aCarStruct[0])
DllStructSetData($aCarStruct[UBound($aCarStruct)-1], 'model', 'Carerra GT')
DllStructSetData($aCarStruct[UBound($aCarStruct)-1], 'color', 'red')
DllStructSetData($aCarStruct[UBound($aCarStruct)-1], 'weight', 1380)


; === get value
; === searching for weight of Carerra GT
For $i = 1 To UBound($aCarStruct) -1
    If DllStructGetData($aCarStruct[$i], 'model') = 'Carerra GT' Then
        MsgBox(0, 'weight', DllStructGetData($aCarStruct[$i], 'weight'))
        ExitLoop
    EndIf
Next

Edited by BugFix

Best Regards BugFix  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...