Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine Significant Trailing Spaces in controls
Message
From
03/08/2007 03:49:13
 
 
To
02/08/2007 21:14:30
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01245320
Message ID:
01245734
Views:
22
>I think I agree with Sergey on the END key and various combinations. It might also be confusing if the user uses the cursor key to the right and then finds "spaces" when they expected to find the end. So far I have the following solution -- so far it works with the exception of handling text that is inserted from the clipboard.
>
>Basically I have a custom combo-dropdown class that has a custom property defined:
>
>
>Space = =CHR(168)     && This is the space replacement character
>
>
>Then I have the following methods defined:
>
>
>Procedure KeyPress
>LPARAMETERS nKeyCode, nShiftAltCtrl
>LOCAL lcBegText, lcEndText
>DO CASE
>  CASE nKeyCode = 7     && Delete key
>    DO CASE
>      CASE this.SelLength >= LEN(this.Tag) .AND. this.SelStart = 0
>        lcBegText = ""
>        lcEndText = ""
>      CASE this.SelLength > 0 .AND. this.SelLength < LEN(this.Tag)
>        lcBegText = LEFT(this.Tag,this.SelStart)
>        lcEndText = SUBSTR(this.Tag,this.SelStart+this.SelLength+1)
>      OTHERWISE
>        lcBegText = LEFT(this.Tag,this.SelStart)
>        lcEndText = SUBSTR(this.Tag,this.SelStart+2)
>    ENDCASE
>    this.Tag = lcBegText + lcEndText
>
>  CASE nKeyCode = 127   && Backspace key
>    IF this.SelLength = 0
>      lcBegText = IIF(this.SelStart>1,LEFT(this.Tag,this.SelStart-1),"")
>      lcEndText = SUBSTR(this.Tag,this.SelStart+1)
>    ELSE
>      lcBegText = IIF(this.SelStart>1,LEFT(this.Tag,this.SelStart),"")
>      lcEndText = SUBSTR(this.Tag,this.SelStart+this.SelLength+1)
>    ENDIF
>    this.Tag = lcBegText + lcEndText
>
>  CASE BETWEEN(nKeyCode,32,126)   && Printable key
>    DO CASE
>*-*   Inserting character end of text
>      CASE this.SelStart = LEN(this.Tag) .AND. this.SelLength = 0
>        lcBegText = this.Tag
>        lcEndText = ""
>
>*-*   Inserting character in mid text
>      CASE this.SelStart < LEN(this.Tag) .AND. this.SelLength = 0
>        lcBegText = LEFT(this.Tag,this.SelStart)
>        lcEndText = SUBSTR(this.Tag,this.SelStart+1)
>
>*-*   Replacing character(s)
>      CASE this.SelStart < LEN(this.Tag) .AND. this.SelLength > 0
>        lcBegText = LEFT(this.Tag,this.SelStart)
>        lcEndText = SUBSTR(this.Tag,this.SelStart+this.SelLength+1)
>      OTHERWISE
>        WAIT WINDOW "ERROR: Unhandled Keyboard Entry"
>        lcBegText = this.Tag
>        lcEndText = ""
>    ENDCASE
>    this.Tag = lcBegText + CHR(nKeyCode) + lcEndText
>ENDCASE
>this.Tag = STRTRAN(this.Tag,CHR(32),this.Space)
>EndProc
>
>
>Procedure GotFocus
>this.DisplayValue = this.Tag
>EndProc
>
>
>I initialize the Tag property with the initial value for display. This way if the user had trailing spaces in the initial text, they will be preserved. The space is replaced in the Tag property with the Space property value. I have set the Space property to the value Ascii 168 which seemed to be the least offensive. I tried using 160 (which for the Arial font is blank) but the dropdown combo would still trim it from the display value.
>
>Right now the above code works with the exception of the instance where the user can paste a text into the display. I am still working on that.
>
>It might be better to instead use the textbox laid on top of a dropdown combo and then use the method from the previous thread. But I am still trying to keep it to the combobox. If this is used then I also need to handle the tab key (auto-advance past the combobox from the textbox) and always set focus back to the textbox on selection from the combobox dropdown.

Greg,

I confess that my solution was very old, in fact I created it in FPD26, and only added a few changes when I later converted the application to VFP. The application is no longer in use. After some thought I realize that this could most likely be done much easier if you simply let keypress change spaces into some other character, like chr(168) as you suggest. Something like this in keypress should do the trick:
If nKeyCOde=32
  NoDefault 
  DoDefault(168, nShiftAltCtrl)
EndIf
BTW, are you aware that chr(255) looks just like chr(32) with many fonts?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform