[Windows] AutoComplete for StringGadgets

Share your advanced PureBasic knowledge/code with the community.
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

If someone uses the #ACO_SEARCH, how to know if user pick up this option?
As far as i can see it uses the word "Search " in the language of the user, so by this way is hard to find it.
I guess there is some correct way to find it out.

Thanks in advance
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Post by leodh »

Hi,

I have been playing aound with the autocomplete gadget and it is proving to be very handy.

I would like to know how to find out which element of the Srting$ array has been selected, as I would like to populate some other gadgets with text from an array depending on what is selected with the autocomplete.

At the moment I am using a comboboxgadget and it works but it is not as nice as the autocomplete.

Code: Select all

Case #String_6
               If GetGadgetText(#String_6)>""
                  Result = GetGadgetState(#String_6)
                  result= result+1 
                  SetGadgetText(#String_7,Supplier.s(Result,2))
                  SetGadgetText(#String_8,Supplier.s(Result,3)+" "+Supplier.s(Result,4)+" "+Supplier.s(Result,5))
                  SetGadgetText(#String_9,Supplier.s(Result,12))
                  SetGadgetText(#String_10,Supplier.s(Result,13))
                  SetGadgetText(#String_11,Supplier.s(Result,10))
                EndIf
Is there a way to find out which element was selected in the autocomplete gadget.

Thanx Leo
Regards
Leo
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Post by Arcee_uk »

Hi.

I have just found this code and while I have no idea what all the additional bits do since the first set of code (which works perfectly for me), I have a question.

Is there a way for a user to see ALL the possible options in the autocomplete list. So if you hit the down arrow you see all options in the list rather than having to press a key to see all entiries starting with that letter/number?

This would make this perfect for what I need to do if that was possible.

Thanks

Aree.
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Post by Arcee_uk »

leodh wrote:Hi,

I have been playing aound with the autocomplete gadget and it is proving to be very handy.

I would like to know how to find out which element of the Srting$ array has been selected, as I would like to populate some other gadgets with text from an array depending on what is selected with the autocomplete.

At the moment I am using a comboboxgadget and it works but it is not as nice as the autocomplete.

Code: Select all

Case #String_6
               If GetGadgetText(#String_6)>""
                  Result = GetGadgetState(#String_6)
                  result= result+1 
                  SetGadgetText(#String_7,Supplier.s(Result,2))
                  SetGadgetText(#String_8,Supplier.s(Result,3)+" "+Supplier.s(Result,4)+" "+Supplier.s(Result,5))
                  SetGadgetText(#String_9,Supplier.s(Result,12))
                  SetGadgetText(#String_10,Supplier.s(Result,13))
                  SetGadgetText(#String_11,Supplier.s(Result,10))
                EndIf
Is there a way to find out which element was selected in the autocomplete gadget.

Thanx Leo
I wondered this as I need to know this as well.

I came up with this basic (and probably overly complicated way):

Code: Select all

Result$=GetGadgetText(#String_0)
For C=0 To PeekL(Strings() - 8)-1
If Strings(C)=Result$
Element=C
Debug Str(C)+" : "+GetGadgetText(#String_0)
EndIf
Next C
Works prefectly in my tests and is quick as well.

I hope this what you wanted.

Arcee
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Ran into another problem somewhat like the one I had last summer. Different combo box, different error..

I get "Invalid memory access. (read error at address 0)

On the ProcedureReturn here :

Code: Select all

If count = celt
    ProcedureReturn #S_OK ;; error here
  Else
    ProcedureReturn #S_FALSE
  EndIf
I open the window with the autocomplete'd gadget on it, type a letter, everything works fine. Close the window. Re-open it, type a character in the autocompleted combo and the crash happens every time.

PB 4.20, threadsafe on Windows XP SP3

The full offending procedure :

Code: Select all

Procedure IEnumString_Next(*THIS.EnumString, celt, *rgelt.Long, *pceltFetched.Long)
  If *THIS\Enumerator + celt <= *THIS\StringCount
    count = celt
  Else
    count = *THIS\StringCount - *THIS\Enumerator
  EndIf
  
  For i = 0 To count-1
    *rgelt\l = *THIS\Buffer\Strings[*THIS\Enumerator + i]
    *rgelt + 4
  Next i
  
  *THIS\Enumerator + count
  
  If *pceltFetcted
    *pceltFetched\l = count
  EndIf
  
  If count = celt
    ProcedureReturn #S_OK ;; error here
  Else
    ProcedureReturn #S_FALSE
  EndIf
EndProcedure

I've used the heap validation routine that freak posted and it doesn't seem to be the same thing that happened before- the ValidatePBHeap() procedure returns all is well.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Does anyone have any ideas on this one? I'm drawing a blank.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I ran into the same problem a while ago. But i have no solution so far either.
It appears to be crashing in the AutoComplete object's code itself, after my code correctly returned the first string. I have no idea why.
quidquid Latine dictum sit altum videtur
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Thanks!

Do you know of any other way to create the end result (an auto completing, editable combo box)?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

I found another problem last night as well. Copy/paste something into a combo with this autocomplete code in any version of Vista and it crashes pretty violently :-(
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

The only other way is to code it all manually afaik.
quidquid Latine dictum sit altum videtur
Marco2007
Enthusiast
Enthusiast
Posts: 638
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

I`m a little confused: I always get an IMA at the last line when using Freak`s Code from the first post (exact the same).

The strange thing: I`m using Freak`s Code in an application without any problems. Never had problems until today....

Does anyone know, what could be? Because I want to implement that again....
PureBasic for Windows
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

IMA?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Marco2007
Enthusiast
Enthusiast
Posts: 638
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Yes, IMA (read error at address 197....).

I just run the first code. Press 'e' -> select a word -> Close the window -> IMA.

Never happened before....Could you try it, please?
I can`t believe it...
PureBasic for Windows
Marco2007
Enthusiast
Enthusiast
Posts: 638
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

I just found out, when closing the window with CloseWindow(), it works (no IMA).

Code: Select all

      Repeat 
        event=WaitWindowEvent()
        Select event
          Case #PB_Event_CloseWindow
            If EventWindow()=#window_0
            CloseWindow(#window_0)
            quit=1
            EndIf
        EndSelect
      Until quit = 1


It also doesn`t crash, when doing this:

Code: Select all

      Repeat 
        event=WaitWindowEvent()
      Until event = #PB_Event_CloseWindow
      CloseWindow(#window_0)
Image
PureBasic for Windows
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

@Marco2007
I think you or the code uses a callback without testing of existing the control.
CloseWindow is the simple way to solve this :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply