Forum > Other

Characters for Widgetset

(1/3) > >>


I have to send charakters to a TEdit-/TComboBox- Field. It seems to me, new characters (from keyboard) will be handled by the widgetset-object?.
How can I send a character without the keyboard to a text-field for showing in the field??

--- Quote ---field.Text:=field.Text + character;
--- End quote ---
doesn't work, because of the cursorposition.

--- Quote ---field.SelText:=character;
--- End quote ---
doesn't work too, because of mismatches of SelStart and SelLength...

     example:  *     Text in Field "123|45678" ( | is the cursor between 3 and 4  )
                  ->    field.SelText:='z';           overwrites 3 characters  ( maybe it is a BUG ?!  ... SelStart = 3  )
             result:    Text in Field "123z|78" ( | is the cursor )

                   is the cursor between 4 and 5, -> 4 characters will be overriten ( SelStart=4 )
                   is the cursor between 2 and 3, -> 2 characters will be overriten ( SelStart=2 )
  BUG ?!

Is there an other way to send a character to the Text-field?

I use Ubuntu 10.10  64bit and  Lazarus 0.9.30, fpc 2.4.2 -> from SourceForge

Set SelStart to the location you want to insert,SelLength to zero. And set SelText to the Char you want to insert.

  Edit1.SelStart:= 3;
  Edit1.SelLength:= 0;
  Edit1.SelText:= 'A';

If you want to overwrite one or more chars, set SelStart to the laocation to start, SelLength to the number of chars to overwrite and SelText to what you want to replace it with.

  Edit1.Text:= '123456789';
  Edit1.SelStart:= 3;
  Edit1.SelLength:= 1;
  Edit1.SelText:= 'A';

thank you!  but....

I don't know where the user set the cursor... I can't set the SelStart somewhere, because the user could set the cursor by mouse.

I want to write a Touch-Screen-Keyboard. There is no real keyboard on the pc. There are input fields, and a virtual keyboard ( a form with keys qwert... [my application] ).
On KeyClick (maybe "z"), I find out where is the cursor. no problem
BUT ... I can't send the key to this field.... I can't append ... text:=text+charakter, because I don't know, if the user had select something, or where is the cursor....
when I set the SelLength:=0 and the user had select something, he will wonder what happens

You can try, it doesn't work. ...use my example above

I haven't tried it under the conditions you are talking about, but I think if you just set SelLength to zero and SelText to what you want to insert, it will insert.  But if the user has selected something, I think that the "normal" behavior should be to overwrite what was selected.  But I don't know for sure what you are doing so maybe it isn't what you want.


[0] Message Index

[#] Next page

Go to full version