April 26, 2024, 01:55:48 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Parent problem

Started by aurelCB, September 23, 2011, 09:02:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi all...
I have problem with dinamicaly created child window which is not child even is pointed
trough pointer that belong to parent window.
For example this small code work fine:
WINDOW win[10]

REM open the main window
OPENWINDOW win[0],0,0,350,350,@MINBOX|@MAXBOX|@SIZE,0,"Simple Window",&main
'-----------------------------------------
OPENWINDOW win[1],0,0,350,350,@MINBOX|@MAXBOX|@SIZE,win[0],"Simple Window",&main
'-----------------------
WAITUNTIL win[0] = 0
END
'-----------------------

SUB main
IF @message = @IDCLOSEWINDOW
   CLOSEWINDOW *<window>@hitwindow
ENDIF

RETURN
ENDSUB


But there is something which i do wrong:
'global seting...
'USER DEFINED WINDOWS -----------------------------------------------------------
DEF NewHwnd[10]:WINDOW
DEF Parent[10]:window
DEF WinCount:INT

'define LinkedList as WinowType *************************************************
TYPE WindowType
   STRING winName
   WINDOW  winValue
   INT     intValue
ENDTYPE
' create WINTYPE LIST
WinList=ListCreate()
POINTER winVar
SETTYPE winVar,WindowType


Then inside sub which crete windows:
IF GW2<>"" :' GW2 is first string after HWND which have variable name
winVar=ListAdd(winList,NEW(WindowType,1))
#winVar.winName = GW2
WinCount = WinCount+1
#winVar.intvalue=WinCount
#winVar.winValue = NewHwnd[WinCount]

'MESSAGEBOX 0,"WCount:"+str$(wincount),"OK"
ENDIF
IF GW3<>""
winVar=ListAdd(winList,NEW(WindowType,1))
#winVar.winName = GW3
WinCount = WinCount+1
#winVar.intvalue=WinCount
#winVar.winValue = NewHwnd[WinCount]

ENDIF


So pointers are defined like i do for other variables.
Then there is sub which must open this windows:
'findWindowName
error=1
PosInList = ListGetFirst(winList)
WHILE (PosInList <> 0)
winVar = ListGetData(PosInList)
IF #winVar.winName = arg1
wcount= #winVar.intValue
MESSAGEBOX 0,"WindowCount:"+str$(wcount),"wc"
NewHwnd[wcount] = #winVar.winValue
error=0
ENDIF
PosInList = ListGetNext(PosInList)
ENDWHILE
IF error=1
MESSAGEBOX 0,"Error: Window not found!","chp"
RETURN
ENDIF
hwndx=val(arg2)
hwndy=val(arg3)
hwndw=val(arg4)
hwndh=val(arg5)
IF arg6="0" then winstyle=@minbox
'IF arg6 = "WS_CHILD" then winstyle=WS_CHILD|@minbox

'get parent
'error=1
IF arg7 <>"0"
error=1
PosInList = ListGetFirst(winList)
WHILE (PosInList <> 0)
winVar = ListGetData(PosInList)
IF #winVar.winName = arg7
pcount = #winVar.intValue
MESSAGEBOX 0,"ParentCount:"+str$(pcount),"pc"
Parent[pcount] = #winVar.winValue
'#<window>parent=NewHwnd[pcount]
error=0
ENDIF
PosInList = ListGetNext(PosInList)
ENDWHILE
IF error=1 
MESSAGEBOX 0,"Error:Parent window not found!","chp"
RETURN
ENDIF
cap$="child"+str$(wCount)
'open new window ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
OPENWINDOW NewHwnd[wcount],hwndx,hwndy,hwndw,hwndh,winstyle,Parent[pcount],cap$,&mainsub
SETWINDOWCOLOR NewHwnd[wcount],RGB(220,220,226)
run1=1
ENDIF

IF arg7="0"
cap$="Parent"+str$(wCount)
OPENWINDOW NewHwnd[wcount],hwndx,hwndy,hwndw,hwndh,winstyle,0,cap$,&mainsub
SETWINDOWCOLOR NewHwnd[wcount],RGB(220,220,226)
run1=1
ENDIF
',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
'Clear 
GW1="":GW2="":GW3="":GW4="":GW5="":GW6="":GW7="":GW8=""
Return
ENDSUB


If someone have idea what might be wrong i would like to see ...
thanks advance.... :)

Aurel

LarryMc

SETTYPE is not global.  It will not carry over into a subroutine or another module(in a project).

When you use a pointer inside a subroutine you either have to use the SETTYPE command or
you have to use #<window>winVar.blah in the subroutine

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Larry this time you are in wrong, because if i use this:
Parent[pcount] = #<WINDOW>winVar.winValue
then i recive whole bunch of errors like this:
QuoteFile: C:\Program Files\EBDev\projects\AOne7.eba (828) undefined variable - winValue
File: C:\Program Files\EBDev\projects\AOne7.eba (828) undefined variable
File: C:\Program Files\EBDev\projects\AOne7.eba (828) invalid assignment - different types

So from what i see SETTYPE work as global and has effect on subroutine..
Hmm im not sure what might be problem because all other things logical to me
Ok i will check code again....

Aurel

LarryMc

What I said about SETTYPE not crossing subroutine boundaries is TRUE; when the pointer is passed as a parameter. 
From the IWBasic User's Guide:
Quote
Pointers in IWBASIC are generic and don't generally point to a specific type of data.When using NEW the pointers type will be set to any built in variable type however UDT's will need to use SETTYPE or typecasting.  A pointer defined as a parameter in a subroutine always needs to be explicitly set to a type with SETTYPE or always use typecasting. Either method produces the same output code.
The reason this didn't work:
Parent[pcount] = #<WINDOW>winVar.winValue
was because
#<WINDOW>should have been
#<WindowType>

This code works:
openconsole

'define LinkedList as WindowType *************************************************
TYPE WindowType
   STRING winName
   WINDOW  winValue
   INT     intValue
ENDTYPE
' create WINTYPE LIST
WinList=ListCreate()
POINTER winVar
SETTYPE winVar,WindowType

winVar=ListAdd(winList,NEW(WindowType,1))
#winVar.winName = "GW2"
winVar=ListAdd(winList,NEW(WindowType,1))
#winVar.winName = "AZ1"

PosInList = ListGetFirst(winList)
WHILE (PosInList <> 0)
winVar = ListGetData(PosInList)
print #winVar.winName
PosInList = ListGetNext(PosInList)
wend

TestSub()

end

sub TestSub()
PosInList2 = ListGetFirst(winList)
WHILE (PosInList2 <> 0)
winVar = ListGetData(PosInList2)
print #winVar.winName
PosInList2 = ListGetNext(PosInList2)
wend
return
endsub


But that isn't really your problem.
If you will give me a complete stripped-down source file I'll look at it for you.

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Uff ...yes Larry you are right ,i dont know how i miss this thing.
And yes real problem is in becose when i try to open new window as child  this new window is not a child
window.
Ok i will send you complet code then you will see what i do wrong.

LarryMc

'Create the parentwindow
Def main:window
OPENWINDOW main,100,100,380,340,@size|@MINBOX|@maxbox,0,"Parent Window", &MainRoutine

'Create the childwindow
Def child:window
OPENWINDOW child,5,5,150,300,0,main,"Child Window", &ChildRoutine
SETWINDOWCOLOR child, RGB(255,0,0)

run=1
WAITUNTIL run = 0
CLOSEWINDOW Main
END
'________________________________________
SUB MainRoutine
   select @MESSAGE
      case @IDCLOSEWINDOW
         if iswindowclosed(child) =0 then closewindow child
         run=0   :'closes the window
   endselect
   RETURN
ENDSUB
'________________________________________
SUB ChildRoutine
   select @MESSAGE
       case @IDCLOSEWINDOW
           closewindow child
   endselect
   RETURN
ENDSUB


Based upon what you sent me.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Because of unknown reason( unknown to me of course ::))
When you try create window dinamicly like i do from typed pointer
from linked list ,this pointer is not accepted like window pointer.
(LarryMc say about that in this topic)
So because i have counter for defined new windows i use same counter to retrieve
number of this parent window.
And finaly work. :)
I also use global pointer pw to try to see if pointer varible can hold window varible.
So code now look like this:
PosInList = ListGetFirst(winList)
WHILE (PosInList <> 0)
winVar = ListGetData(PosInList)
IF #winVar.winName = arg7
pcount = #winVar.intValue
MESSAGEBOX 0,"ParentCount:"+str$(pcount),"pc"
Parent[pcount]= NewHwnd[pcount]
pw = parent[pcount]
error=0
ENDIF
PosInList = ListGetNext(PosInList)
ENDWHILE

Who knows maby someone of you sometimess need something like that.... ;)
Cheers...

Aurel

LarryMc

Glad ou got it figured out!

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library