Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

"Invalid Table Handle" in background Thread

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • "Invalid Table Handle" in background Thread

    I developed a background Thread using data from a file, so as to get the logic correct before dropping into a thread which monitors port 30003.
    It worked fine using the test data thus:

    Code:
    dim MonitorArray[2000] as c
    dim MonitorModeS[2000] as c
    dim VarArray[23] as c
    dim incr as n = 1
    fp = file.open("D:\My Databases\SBS\MsgLogs\Testdata.csv",FILE_RW_SHARED)
    tbl = table.open("Logging",FILE_RW_SHARED)
    idx = tbl.index_primary_put("Mode_S")
    WHILE fp.eof() = .f.
    	bsOutput = fp.read_line()
    	bsOutput = substr(bsOutput,at("MSG",bsOutput))
    	IF left(bsOutput,3) = "MSG" THEN
    		bsOutcrlf = comma_to_crlf(bsOutput)
    		VarArray.clear()
    		dim j as n = 1
    		FOR each VarRead in bsOutcrlf
    			VarArray[j] = VarRead
    			j = j + 1
    		next
    		IF inlist(VarArray[2],"3","4","8") THEN
    			rec = tbl.fetch_find(VarArray[5])
    			checkModeS = MonitorModeS.find(VarArray[5])
    			IF rec > 0 .and. CheckModeS = 0 THEN
    				MonitorArray[incr] = padr(tbl.reg,10," ")+"["+padr(tbl.Icaotypecode	,4," ")+"]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			END IF
    			IF CheckModeS > 0 .and. VarArray[2] = "3" .and. val(VarArray[15]) <> 0 THEN
    				IF right(ut(MonitorArray[CheckModeS]),1) <> "+" THEN
    					MonitorArray[CheckModeS] = MonitorArray[CheckModeS]+"+"
    				END IF
    			END IF
    			IF rec < 0 .and. CheckModeS = 0 THEN
    				MonitorArray[incr] = padr(VarArray[5],8," ")+"[New]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			END IF
    		END IF
    	END IF
    END WHILE
    fp.flush()
    fp.close()
    tbl.close()
    I then re-wrote the code as Thread Script:

    Code:
    thread_create("TestMonitorArrayThread",<<%code%
    xbasic_error_log("d:\My Databases\SBS\MsgLogs\thread_error_log.txt")
    dim MonitorThreadRunFlag as l = .t.
    dim global MonitorArray[2000] as c
    dim global MonitorModeS[2000] as c
    dim VarArray[23] as c
    dim incr as n = 1
    dim CheckModeS as n
    dim bsOutput as c
    dim bsOutcrlf as c
    dim j as n
    dim Tbl as P
    dim rec as n
    Tbl = table.open("logging",FILE_RW_SHARED)
    idx = Tbl.index_primary_put("ModeS")
    dim bs as p = sockets.open("127.0.0.1",30003,"C")
    while MonitorThreadRunFlag
    	bsOutput = bs.readline()
    	IF left(bsOutput,3) = "MSG" THEN
    		bsOutcrlf = comma_to_crlf(bsOutput)
    		VarArray.clear()
    		j = 1
    		for each VarRead in bsOutcrlf
    			VarArray[j] = VarRead
    			j = j + 1
    		next
    		if inlist(VarArray[2],"3","4","8") then
    			rec = Tbl.fetch_find(VarArray[5])
    			CheckModeS = MonitorModeS.find(VarArray[5])
    			if rec > 0 .and. CheckModeS = 0 then
    				MonitorArray[incr] = padr(Tbl.reg,10," ")+"["+padr(Tbl.ICAOTypeCode,4," ")+"]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			end if
    			if CheckModeS > 0 .and. VarArray[2] = "3" .and. val(VarArray[15]) <> 0 then
    				if right(ut(MonitorArray[CheckModeS]),1) <> "+" then
    					MonitorArray[CheckModeS] = MonitorArray[CheckModeS]+"+"
    				end if
    			end if
    			if rec < 0 .and. CheckModeS = 0 then
    				MonitorArray[incr] = padr(VarArray[5],8," ")+"[New]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			end if
    		end if
    	end if
    end while
    bs.close()
    Tbl.close()
    %code%)
    I keep getting "Invalid Table Handle" on running the Thread (Second example above but it works ok on the first.

    Why does it work in one but not the other??
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  • #2
    Re: &quot;Invalid Table Handle&quot; in background Thread

    This is just a guess but the table.open() may require a full path and file name for the table when used in a thread.
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

    Comment


    • #3
      Re: &quot;Invalid Table Handle&quot; in background Thread

      Thanks Tim, but this command worked in a previous version of the thread:(
      --
      Support your local Search and Rescue Unit, Get Lost!

      www.westrowops.co.uk

      Comment


      • #4
        Re: &quot;Invalid Table Handle&quot; in background Thread

        OK, I think I've sorted it:-

        changed

        Code:
        rec = tbl.fetch_find(VarArray[5])
        IF rec > 0 .and. CheckModeS = 0 THEN
            MonitorArray[incr] = padr(tbl.reg,10," ")+"["+padr(tbl.ICAOTypeCode,4," ")+"]"
        to

        Code:
        tblalias = table.current()
        rec = tblalias.fetch_find(VarArray[5])
        IF rec > 0 .and. CheckModeS = 0 THEN
            MonitorArray[incr] = padr(tblalias.reg,10," ")+"["+padr(tblalias.ICAOTypeCode,4," ")+"]"
        but now I get error message from thread:

        Sun Jan 21 10:05:52 2007

        Thread: TestMonitorArrayThread
        Script: TEMPLATE
        Line: 26
        rec = tblalias.fetch_find(VarArray[5])
        Conflicting expression data types
        Execution Stack:
        0#26 rec = tblalias.fetch_find(VarArray[5])
        in the Thread Xbasic coding
        dim rec as n
        and
        dim VarArray[23] as c

        so what the heck is happening here?
        --
        Support your local Search and Rescue Unit, Get Lost!

        www.westrowops.co.uk

        Comment


        • #5
          Re: &quot;Invalid Table Handle&quot; in background Thread

          Graham,

          The function THREAD_CREATE( Thread_Name as C, Code as C [, Variables as P ] ) has an optional parameter variables.

          Why do you the opening of the tables inside the thread?

          I would place this outside the thread and pass it to the thread by the 3th parameter.

          You get something like:

          Code:
          'Create a pipe.
          hPipe = CreateNamedPipeA(lpszPipename,\
                                   PIPE_ACCESS_DUPLEX,\
                                   PIPE_TYPE_MESSAGE .OR. PIPE_READMODE_MESSAGE .OR. PIPE_WAIT,\
                                   PIPE_UNLIMITED_INSTANCES,\
                                   BUFFSIZE,\
                                   BUFFSIZE,\
                                   20000,\' Wait for connection within 20 seconds
                                   NULL)' No security structure passed.
          
          name_space = local_variables()
          
          thread_create("ServerA5P", <<%code%
          XBASIC_ERROR_LOG("c:\ServerA5P.log") 
          
          while keep_running
          
          fSuccess.b = ReadFile(\
                             name_space.hPipe,\'Handle to pipe
                             chRequest,\'buffer to recieve data
                             BUFFSIZE,\'size of the buffer
                             cbBytesRead,\'number of bytes read
                             NULL)'not overlapped I/O
          
          ' In case of error there is a soundable alarm.
          ' In threads is no graphical I/O alowed.
          
          name_space.main_loop = .F.
          chReply = "Server has stopped by Client request."
          name_space.chReply = chReply
          
          fSuccess.b = WriteFile(\
                             name_space.hPipe,\'Handle to pipe
                             chReply,\'buffer to send data from
                             cbReplyBytes,\'size of the reply string
                             cbWritten,\'number of bytes written
                             NULL)'not overlapped I/O
          
          FlushFileBuffers(name_space.hPipe)
          
          end while
          %code%, name_space)'<<<<<< By this parameter you can access the outside variables name_space.
          I do not know if this is the solution for your problem but it may help to reduce some future problems. I think you have to keep the thread code and what you are doing as small as possible.
          Last edited by Marcel Kollenaar; 01-21-2007, 08:21 AM. Reason: Editor problem, pushed the wrong button!
          Marcel

          I hear and I forget. I see and I remember. I do and I understand.
          ---- Confusius ----

          Comment


          • #6
            Re: &quot;Invalid Table Handle&quot; in background Thread

            Thanks Marcel,

            if I DIM all variables before

            Code:
            Thread_create("name",<<%code%
               do something
            %code%,NS)
            does that mean I refer to all variables with prefix NS?

            i.e. tbl = table.open("Logging",FILE_RW_SHARED)
            dim Incr as n = 1
            I would refer to them as
            ns.tbl.fetch_first()
            and
            ns.incr
            ??

            Later @ 13:00

            Tried the thread out using the variable NS as a pointer to my local.variables() all seemed to work, but it came to the same result:(

            Sun Jan 21 13:07:03 2007

            Thread: TestMonitorArrayThread
            Script: TEMPLATE
            Line: 14
            ns.rec = ns.tblalias.fetch_find(ns.VarArray[5])
            Conflicting expression data types
            Execution Stack:
            0#14 ns.rec = ns.tblalias.fetch_find(ns.VarArray[5])
            --
            Support your local Search and Rescue Unit, Get Lost!

            www.westrowops.co.uk

            Comment


            • #7
              Re: &quot;Invalid Table Handle&quot; in background Thread

              Graham,
              Try this:

              Code:
              for each VarRead in bsOutcrlf
              	VarArray[j] = VarRead.value
              	j = j + 1
              next
              I don't know if it will solve your problem but I believe t's an error in your code and may account for the invalid variable type message you're getting.

              Comment


              • #8
                Re: &quot;Invalid Table Handle&quot; in background Thread

                Originally posted by Graham Wickens View Post
                ....does that mean I refer to all variables with prefix NS?

                i.e. tbl = table.open("Logging",FILE_RW_SHARED)
                dim Incr as n = 1
                I would refer to them as
                ns.tbl.fetch_first()
                and
                ns.incr
                Yes.
                Marcel

                I hear and I forget. I see and I remember. I do and I understand.
                ---- Confusius ----

                Comment


                • #9
                  Re: &quot;Invalid Table Handle&quot; in background Thread

                  Hi Peter,
                  tried it with dot value, but still got the same error!!
                  This is getting daft, as these Thread worked in a previous existance:(
                  --
                  Support your local Search and Rescue Unit, Get Lost!

                  www.westrowops.co.uk

                  Comment


                  • #10
                    Re: &quot;Invalid Table Handle&quot; in background Thread

                    Maybe you have a character number mismatch?

                    Test with TYPEOF() the type of the variables. Write the result in variables outside the thread. You cannot use screen output.

                    Where did you create the ns.rec = ns.tblalias.fetch_find(ns.VarArray[5]) inside the thread or outside?
                    Last edited by Marcel Kollenaar; 01-21-2007, 10:51 AM. Reason: Wrong solution, tried a better one!
                    Marcel

                    I hear and I forget. I see and I remember. I do and I understand.
                    ---- Confusius ----

                    Comment


                    • #11
                      Re: &quot;Invalid Table Handle&quot; in background Thread

                      created inside thread.
                      --
                      Support your local Search and Rescue Unit, Get Lost!

                      www.westrowops.co.uk

                      Comment


                      • #12
                        Re: &quot;Invalid Table Handle&quot; in background Thread

                        What is maddening about this problem is that when I run the script that simulates the thread and reads a sequential file with 10,837 records in it, the code is identical to that in the thread, other than the While .. end while is changed to fp.eof() of the input sequential csv file it works perfectly.
                        --
                        Support your local Search and Rescue Unit, Get Lost!

                        www.westrowops.co.uk

                        Comment


                        • #13
                          Re: &quot;Invalid Table Handle&quot; in background Thread

                          You might also try

                          dim simpleVar as c=VarArray[5]
                          and then do a tbl.fetch_find(simpleVar)

                          Comment


                          • #14
                            Re: &quot;Invalid Table Handle&quot; in background Thread

                            Originally posted by Graham Wickens View Post
                            created inside thread.
                            You cannot reference the name_space from the outside first and than use a .variable - tblalias - created inside the thread IMHO.:(

                            Or and I have not tested that, the thread variables are visible from the outside?

                            Why do you want to use such construction?

                            --------------------- added --------------------------

                            Addition to Peters story:

                            had a similar problem with:

                            Code:
                            'Sources is a pointer to a list of all the installed TWAIN devices.
                            sources = tw.InstalledSources()
                            For Each devName In sources
                              ' Create a new entry in the choice list.
                              TopParent:dropdown1.choice.list.insert()
                              ' :TwainForm:dropdown1.choice.list[i].text = devName 'Results in a type mismatch error.
                              TopParent:dropdown1.choice.list[i].text = convert_type(devName,"C")
                              TopParent:dropdown1.choice.list[i].value = convert_type(devName,"C")
                              ' increment the index.
                              i = i + 1
                            Next devName
                            I had to use convert_type(devName,"C") to overcome this problem.

                            In your case it could be: ns.rec = ns.tblalias.fetch_find(convert_type(ns.VarArray[5],"C"))

                            ---------------- added 2 -----------------

                            Graham, do you have an isolated example that I can test?
                            Last edited by Marcel Kollenaar; 01-21-2007, 03:28 PM.
                            Marcel

                            I hear and I forget. I see and I remember. I do and I understand.
                            ---- Confusius ----

                            Comment


                            • #15
                              Re: &quot;Invalid Table Handle&quot; in background Thread

                              Attached Zip has both the test data and the Thread. The logic is sound in that it creates the end result I was after, must be something to do with Variable scope? You will have to change any specific filenames and directories. I've added all the test data as its a small file when zipped.
                              --
                              Support your local Search and Rescue Unit, Get Lost!

                              www.westrowops.co.uk

                              Comment

                              Working...
                              X