SetWindowData(#Window,Value) And GetWindowData(#Window)
SetWindowData(#Window,Value) And GetWindowData(#Window)
As those functions exists for gadgets, it may be useful for window ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
-
- Addict
- Posts: 1516
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
+100000000
Why have not yet been implemented? What is the difficulty?
Why have not yet been implemented? What is the difficulty?
- Joakim Christiansen
- Addict
- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
Would be nice indeed!
Meanwhile:
Meanwhile:
Code: Select all
Global NewMap windowData()
windowData(Str(#window)) = value ;store
Debug windowData(Str(#window)) ;read
I like logic, hence I dislike humans but love computers.
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
Or this way, you can include it into your Ssurce and forget it, If it's implemented natively then the native procedures are used.
Code: Select all
CompilerIf Not Defined(GetWindowData, #PB_Function)
Global NewMap __WindowData()
Procedure GetWindowData(_Window)
ProcedureReturn __WindowData(Str(_Window))
EndProcedure
Procedure SetWindowData(_Window, _Data)
__WindowData(Str(_Window)) = (_Data)
EndProcedure
CompilerEndIf
; Test
SetWindowData(1, 20)
Debug GetWindowData(1)
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
Any news on this? It will be implemented in the new version? It would be very useful to encapsulate code.
No api it has to be CP.
No api it has to be CP.
-
- Addict
- Posts: 1516
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
Functions would be very useful.
An example of their use.
An example of their use.
Code: Select all
Structure Gadgets
Button_1.i
Button_2.i
EndStructure
Procedure OpenWin(ID, x=0, y=0, w=100, h=100, t.s="", f=0)
Protected *Gadget.Gadgets
*Gadget=AllocateMemory(SizeOf(Gadgets))
If *Gadget
If OpenWindow(ID, x, y, w, h, t, f)
*Gadget\Button_1 = ButtonGadget(#PB_Any, 20, 10, 80, 24, "Button_1")
*Gadget\Button_2 = ButtonGadget(#PB_Any, 20, 50, 80, 24, "Button_2")
SetWindowData(ID, *Gadget)
Else
FreeMemory(*Gadget)
EndIf
EndIf
EndProcedure
Procedure EventWin(Event, Window)
Protected *Gadget.Gadgets
If Event = #PB_Event_Gadget
*Gadget = GetWindowData(Window)
If *Gadget
Select EventGadget()
Case *Gadget\Button_1
MessageRequester("", "Button_1; WinID "+Window)
Case *Gadget\Button_2
MessageRequester("", "Button_2; WinID "+Window)
EndSelect
EndIf
ElseIf Event = #PB_Event_CloseWindow
*Gadget = GetWindowData(Window)
If *Gadget
FreeMemory(*Gadget) : SetWindowData(0, 0)
EndIf
CloseWindow(Window)
EndIf
EndProcedure
OpenWin(0)
OpenWin(1)
OpenWin(2)
OpenWin(3)
Repeat
Event = WaitWindowEvent()
Window= EventWindow()
EventWin(Event, Window)
Until Event = #PB_Event_CloseWindow And Window=0
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
On Windows you can use for a single value
or for more than one
But thats only windows. A little cross solution for that, is a map to handle it like this
But a native solution is the best... so I agree this wish.
Code: Select all
SetWindowLongPtr_(WindowID(#Window), #GWLP_USERDATA, Value)
Value = GetWindowLongPtr_(WindowID(#Window), #GWLP_USERDATA)
Code: Select all
SetProp_(WindowID(#Window), "MyValue", Value)
GetProp_(WindowID(#Window), "MyValue")
RemoveProp_(WindowID(#Window), "MyValue")
Code: Select all
DeclareModule Common_GUI
; --- Crossplatform Property Handling like Windows OS
; --- SetProp_(), GetProp_(), RemoveProp_()
Declare SetProp(ID, Property.s, Value) ; Set a property to an ID
Declare GetProp(ID, Property.s) ; Get a property from an ID
Declare DelProp(ID, Property.s, Flag = #False) ; If Flag = #True then Remove all properties of this object
EndDeclareModule
Module Common_GUI
Structure struct_CG_Gadget_Properties
Map Property.i()
EndStructure
Global NewMap CG_Gadget_Properties.struct_CG_Gadget_Properties()
Procedure SetProp(ID, Property.s, Value)
Protected Result = #False
CG_Gadget_Properties(Str(ID))\Property(Property) = Value
Result = #True
ProcedureReturn Result
EndProcedure
Procedure GetProp(ID, Property.s)
Protected Value = #Null
If FindMapElement(CG_Gadget_Properties(), Str(ID))
If FindMapElement(CG_Gadget_Properties(Str(ID))\Property(), Property)
Value = CG_Gadget_Properties(Str(ID))\Property(Property)
EndIf
EndIf
ProcedureReturn Value
EndProcedure
Procedure DelProp(ID, Property.s, Flag = #False)
Protected Result = #False
If FindMapElement(CG_Gadget_Properties(), Str(ID))
If Flag = #False
If FindMapElement(CG_Gadget_Properties(Str(ID))\Property(), Property)
DeleteMapElement(CG_Gadget_Properties(Str(ID))\Property(), Property)
Result = #True
EndIf
Else
DeleteMapElement(CG_Gadget_Properties(), Str(ID))
Result = #True
EndIf
EndIf
ProcedureReturn Result
EndProcedure
EndModule
UseModule Common_GUI
-
- Addict
- Posts: 1516
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
This, I know, but I need cross-platform variant.Bisonte wrote:On Windows you can use for a single value
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
What's wrong with the map method ?
-
- Addict
- Posts: 1516
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
The windows are in different modules, and use of map, will create additional difficulties.Fred wrote:What's wrong with the map method ?
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
Put it in a helper module, so you can use it in all other modules? (base by cxAlex)User_Russian wrote:The windows are in different modules, and use of map, will create additional difficulties.Fred wrote:What's wrong with the map method ?
Code: Select all
DeclareModule WindowHelper
EnableExplicit
Declare GetWindowData(window, index=0)
Declare SetWindowData(window, value, index=0)
EndDeclareModule
Module WindowHelper
Global NewMap windowData.i()
Procedure GetWindowData(window, index=0)
ProcedureReturn windowData(Str(window)+":"+Str(index))
EndProcedure
Procedure SetWindowData(window, value, index=0)
windowData(Str(window)+":"+Str(index)) = value
EndProcedure
EndModule
WindowHelper::SetWindowData(1, 12)
WindowHelper::SetWindowData(2, 30)
Debug WindowHelper::GetWindowData(1)
Debug WindowHelper::GetWindowData(2)
For index = 1 To 10
WindowHelper::SetWindowData(1, index+100, index)
Next
For index = 1 To 10
Debug WindowHelper::GetWindowData(1, index)
Next
- NicTheQuick
- Addict
- Posts: 1503
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: SetWindowData(#Window,Value) And GetWindowData(#Window)
I still would prefer a native method for this.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.