Checking if linked list exists

Just starting out? Need help? Post your questions and find answers here.
moricode
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 25, 2023 3:55 am

Re: Checking if linked list exists

Post by moricode »

Code: Select all

; DLL library

ProcedureDLL.i ProcessList(List wList$())
      
        If isList(wList$() )
           ; Do process List


           ProcedureReturn #Success
        Endif

       procedurereturn #ERROR
Endprocedure

; ------------------------------------


; In some one else user program 


Loadlibrary "WhatListEx.DLL"

prototype ProcessList(list a$())

newlist abc$()

; -----
skip here long program code with thousands line ...... 
may have freeList() some where .....

; ----

; not sure the list exist any more ?...

calling 

If ProcessList(abc$())   ; compile ok ; Crash when running

endif 
User avatar
Distorted Pixel
Enthusiast
Enthusiast
Posts: 303
Joined: Sun Aug 29, 2021 4:34 am

Re: Checking if linked list exists

Post by Distorted Pixel »

jacdelad wrote: Wed Nov 22, 2023 1:48 am I...think I don't understand what you want to achieve.
In your example, the list has to exist. SelectElement() creates an error or crashes if it can't be performed, but I would use ListSize() beforehand to prevent that.
ListIndex() just tells us where the pointer is set to the list (the active element). If the list is empty, it is -1, sure (no element selected). If you add elements, it can still become -1 again (by using ResetList()). So this is not a universal way to tell if a list is empty, nor that it exists.
In one window started from its own include file I have a integer variable called "English" being set to "1" when the English button is pressed and I have shared the variable at the top of the procedure. In the next window that starts from its own include file after the first window closes, I have Debug English to see if the program sees the variable and what it is set to. Debug English in the second window returns 0 so I know it doesn't see it even though it is shared. I need it to see it and return what it is set to. I have other variables also being set to "1" if their respective button is pressed. I need each variable to be seen and returned to be able to add an element to the correct list.

Here is an example, there are not 2 or 3 separate include files, but it doesn't work either, just click the "English" button

Code: Select all

Enumeration
  #window
EndEnumeration

Declare Win()

OpenWindow(#window,0,0,800,600,"Variable and list test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

CreateMenu(1,WindowID(#window))
MenuTitle("File")
MenuItem(0,"Open")
MenuTitle("Edit")

ButtonGadget(0,100,25,100,25,"English")
;ButtonGadget(1,100,60,100,25,"French")
quit=0
Repeat
  
  EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case #window
            quit=1
            CloseWindow(0)
        EndSelect


      Case #PB_Event_Gadget
        Select GadgetID
          Case 0
            English=1
            Win()
        EndSelect
    EndSelect
    
Until EventID=#PB_Event_CloseWindow


Procedure Win()
  OpenWindow(1,0,0,800,600,"Child window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered,WindowID(0))
  Debug English
  
  Repeat
    event=WaitWindowEvent()
    
  Until event=#PB_Event_CloseWindow
  
EndProcedure
[Edit:] Ok, the above example doesn't work unless the "English" variable is set to Global, but I tried that in my original program that has multiple include files and it didn't work
Last edited by Distorted Pixel on Wed Nov 22, 2023 5:10 am, edited 1 time in total.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:

No one cares how much you know until they know how much you care
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Checking if linked list exists

Post by jacdelad »

Yeah, sure. "English" is declared as "Define", so locally, by default if not declared otherwise. So it's not available in the procedure.
But what's the link to finding out whether a linked list exists or not? Do you mean, like a local defined linked list not being available in a procedure?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Distorted Pixel
Enthusiast
Enthusiast
Posts: 303
Joined: Sun Aug 29, 2021 4:34 am

Re: Checking if linked list exists

Post by Distorted Pixel »

jacdelad wrote: Wed Nov 22, 2023 5:10 am Yeah, sure. "English" is declared as "Define", so locally, by default if not declared otherwise. So it's not available in the procedure.
But what's the link to finding out whether a linked list exists or not? Do you mean, like a local defined linked list not being available in a procedure?
The linked list is created when a given button is pressed in the previous window where the user selects what type of game they want to play

button 1 is the Manager button
button 2 is the Coach button
button 3 is the Load saved game button

If the user clicks the Manager button the following procedure is called to create the list according to the button pressed and creates the list for a Manager game.

Code: Select all

Procedure ListExistCheck()
  Shared.i M_Acct, C_Acct, LS_Acct
;   Structure AcctType
;     M_Acct.s
;     C_Acct.s
;     LS_Acct.s
;   EndStructure
  
  If M_Acct=1
    Global NewList MgrAcct.s()
    Shared MgrAcct()
    AddElement(MgrAcct())
    MgrAcct()="Manager"    
  Else
    M_Acct=0
  EndIf
    
  If C_Acct=1
    Global NewList CchAcct.s()
    Shared CchAcct()
    AddElement(CchAcct())
    CchAcct()="Coach"
  Else
    C_Acct=0
  EndIf
  
  If LS_Acct=1
    Global NewList LSAcct.s()
    Shared LSAcct()
    AddElement(LSAcct())
    LSAcct()="Load Saved Game"
  Else
    LS_Acct=0
  EndIf
EndProcedure
Then the next window that opens that user selects league they want to play in
button 1 is English
button 2 is French
button 3 is German
button 4 is Italian
button 5 is Scottish
button 6 is Spanish
button 7 is Dutch

If the user selects the English league then English variable is set to 1

The next window the user selects the team they want to manage(since English is set to 1 then the English league teams are loaded into the buttons to select the team), but the "Team selection window doesn't see that English is set to 1 so it can't load the English teams. At some point in the program it will need to know what list exists, Manager, Coach or Load saved game.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:

No one cares how much you know until they know how much you care
Post Reply