Sign in to follow this  
Followers 0
cappy2112

Container Object data type

10 posts in this topic

Does AutoIt support any Container Objectrs, like a Class or Structure?

I'm not after anything fancy like C++ but would like to pass one object (or pointer) which contains

multiple values like WindowTitle, WindowText, ControlID.

I use these a lot, and would like to have a simplified way of passing them instead of having to pass 3 vars to many functions.

I Could use an Array, I just don't like it :-)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You've mentioned that you don't like arrays, however you may not have used them in the fashion below:

; Define unique constants
Global Const $Name = 0
Global Const $Address = 1
Global Const $Phone = 2
Global Const $DOB = 3

Local $Person[4]
$Person[$Name] = 'Alex'
$Person[$Address] = 'Melbourne'
$Person[$Phone] = '183 1000'
$Person[$DOB] = 'BC'

MsgBox(0x40, "Alex's address", $Person[$Address])

Edit: If you're using the beta then you may also want to check out DLLStructCreate().

Edited by LxP

Share this post


Link to post
Share on other sites

You've mentioned that you don't like arrays, however you may not have used them in the fashion below:

; Define unique constants
Global Const $Name = 0
Global Const $Address = 1
Global Const $Phone = 2
Global Const $DOB = 3

Local $Person[4]
$Person[$Name] = 'Alex'
$Person[$Address] = 'Melbourne'
$Person[$Phone] = '183 1000'
$Person[$DOB] = 'BC'

MsgBox(0x40, "Alex's address", $Person[$Address])

Edit: If you're using the beta then you may also want to check out DLLStructCreate().

Tsk tsk, Alex! You demonstrate the exact reason I added Enum to the language but you didn't use it:

Enum $NAME, $ADDRESS, $PHONE, $DOB, $MAX

Local $Person[$MAX]
$Person[$NAME]='Alex'
$Person[$ADDRESS] = 'Melbourne'
$Person[$PHONE] = '183 1000'
$Person[$DOB] = 'BC'

Share this post


Link to post
Share on other sites

A sweet anxwer Valik. Where did this Enum come from? It is indeed refreshing. No response needed :P

Share this post


Link to post
Share on other sites

A sweet anxwer Valik. Where did this Enum come from? It is indeed refreshing. No response needed :P

May I (correctly) infer from this comment that you (and presumably Alex, as well) were not aware of Enum? Or was it something you knew about but had never seen a practical example of?

Share this post


Link to post
Share on other sites

Enum seems more of a database type of of variable declaration for usage which I have little use of at majority of times so is why I have little use of remembering, but is nice to see someone bring it up at times when needed. Everybody has their own purpose and needs for different items.

Share this post


Link to post
Share on other sites

You've mentioned that you don't like arrays, however you may not have used them in the fashion below:

; Define unique constants
Global Const $Name = 0
Global Const $Address = 1
Global Const $Phone = 2
Global Const $DOB = 3

Local $Person[4]
$Person[$Name] = 'Alex'
$Person[$Address] = 'Melbourne'
$Person[$Phone] = '183 1000'
$Person[$DOB] = 'BC'

MsgBox(0x40, "Alex's address", $Person[$Address])

Edit: If you're using the beta then you may also want to check out DLLStructCreate().

You are right- as usual :-)

This usage of arrays looks like a Python dictionary (which is very cool, indeed)

This will make argument passing much better.

thanks!

Share this post


Link to post
Share on other sites

Tsk tsk, Alex! You demonstrate the exact reason I added Enum to the language but you didn't use it:

···

Actually, I'm not sure now why I didn't use Enum. I seemed to use it the last time I wrote out code for this idea (and look at how eerily similar that code is...).

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Eerie, indeed.

May I recommend in the future you also demonstrate the use of the $MAX parameter. I've found that it allows for writing much cleaner code since you can add new elements to the array without having to touch existing code.

Edit: To be clear, I mean demonstrate the usage of a parameter which is always at the tail end of the Enum which means it is perfect for use as the size of an array initialized. My above wording makes it sound too much like there is some special magical parameter or something associated with Enum which is not what I want to convey.

Edited by Valik

Share this post


Link to post
Share on other sites

I like that idea very much. I noticed that you did it in the code that you posted earlier.

Share this post


Link to post
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
Sign in to follow this  
Followers 0