Is there a way to hold a structure as a constant so that you can address elements of the structure as:
MyStructure.text ' String
MyStructure.Length ' integer
etc...
JohnB
public enum ButtonProps
Left
Top
Right
Bottom
SolidColor
BorderColor
PressColor
FontColor
FontRef
BorderWidth
DownVector
UpVector
ClickVector
end
Const MyButton(13) As UShort = 78,218,78+64,219+32,clSilver,clBlue,clGray,clBlack,Arial,1,0,0,ClickLabel
MyProperty = MyButton[ButtonProps.Property]
const NumProperties = 13
public structure TButtonProps
prop(NumProperties) as ushort // properties array
Left as prop(0) // common names (alias names for properties array)
Top as prop(1)
Right as prop(2)
Bottom as prop(3)
SolidColor as prop(4)
BorderColor as prop(5)
PressColor as prop(6)
FontColor as prop(7)
FontRef as prop(8)
BorderWidth as prop(9)
DownVector as prop(10)
UpVector as prop(11)
ClickVector as prop(12)
end structure
// assign some dummy values for the constants so that the 'MyButtonDefaults' initialization statement will compile
const clSilver = 1
const clBlue = 2
const clGray = 3
const clBlack = 4
const Arial = 100
const ClickLabel = 200
// default button values
Const MyButtonDefaults(NumProperties) As UShort = {78,218,78+64,219+32,clSilver,clBlue,clGray,clBlack,Arial,1,0,0,ClickLabel}
' Declarations...
public dim button as TButtonProps
Sub Main()
// copy const array values to the structure 'prop' array (all 13 values)
button.prop = MyButtonDefaults
// access individual members using the union alias name
button.Left = 1
button.Right = button.Left + 99
button.FontColor = clBlue
End Sub
const NumProperties = 13
public structure TButtonProps
prop(NumProperties) as ushort // properties array
Left as prop(0) // common names (alias names for properties array)
Top as prop(1)
Right as prop(2)
Bottom as prop(3)
SolidColor as prop(4)
BorderColor as prop(5)
PressColor as prop(6)
FontColor as prop(7)
FontRef as prop(8)
BorderWidth as prop(9)
DownVector as prop(10)
UpVector as prop(11)
ClickVector as prop(12)
end structure
Const MyButton(NumProperties ) As UShort = 78,218,78+64,219+32,clSilver,clBlue,clGray,clBlack,Arial,1,0,0,ClickLabel
Const MySecondButton(NumProperties ) As UShort = etc...
' Call Draw button passing the Identifier in the parameter
e.g. DrawButton(MyButton)
Public DrawButton(ByRefConst BtnName As UShort)
Dim Button As TBtnProps
Button=BtnName ' will this copy the array of just the contents of the location?
Props.Left = 1
etc
...
end
' Declarations...
public dim button1 as TButtonProps
public dim button2 as TButtonProps
// copy the contents of button1 to button2 (structure to structure copy)
button2 = button1
// given a ref to a "button" object (which is actually a TButtonProps structure)
// make a local copy of it and change some of the local copy
Public sub DrawButton(ByRef pButton As TButtonProps)
Dim Button As TButtonProps // a local button
Button = pButton // copies the contents of the array pointed to by 'pButton' (ie Button1) to our local structure
Button.Left = 5 // change the contents of the local button
Button.Right = 10
// you can also just use the original pointer to the passed parameter
dim x, y as ushort
x = pButton.Left
y = pButton.Top
// since the param was passed 'byref' you can even modify the original object
// as you have a reference (ie pointer) to it
// in this case it would modify the original 'Button1' object
pButton.Left = 1000
end sub
// pass a reference to Button1 to the DrawButton routine
// (this passes the address of the button1 structure)
DrawButton(button1)
Public sub DrawButton(ByRefconst pButton() As ushort)
Dim Button As TButtonProps // a local button
Button.prop = pButton // copies the const array pointed to by 'pButton' to our local structure
Button.Left = 5 // change the contents of the local button
Button.Right = 10
// you can also just use the original pointer to the passed parameter
dim x, y as ushort
x = pButton(0)
y = pButton(1)
end sub
DrawButton(MyButton)
DrawButton(MySecondButton)
Users browsing this forum: No registered users and 1 guest