Forum > LCL

[Solved] Preserving TEdit cursor position etc.

(1/2) > >>

MarkMLl:
I've got a form with a TEdit into which I occasionally want to enter text, and a frame into which monitoring information is being written asynchronously by a background thread via Synchronize() or QueueAsyncCall().

When monitoring information is written, the focus moves away from the TEdit. I can transfer it back using the form's ActiveControl property, but at that point the cursor is placed at the left of the text being entered and I presume that other state is destroyed.

Is there any way of saving the edit state? I've tried saving and restoring CaretPos without success.

MarkMLl

winni:
Hi!

The cursor position of  a Tedit can be read and set by Edit.selStart


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var Cpos : integer;...Cpos := Edit.SelStart;...Edit.SelStart := Cpos; 
SelStart is zero based - to set the  cursor before the first char .

Winni

MarkMLl:
No change, the cursor always zips back to the left. Code looks something like this


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TFormPSTalk.MonitorHex(const message: string; sending: boolean); var  i: integer;  savedControl: TWinControl;//  savedCaret: TPoint;  savedSelStart, savedSelLength: integer; begin  savedControl := ActiveControl;  if ActiveControl = EditMessage then begin//    savedCaret := EditMessage.CaretPos;    savedSelStart := EditMessage.SelStart;//    savedSelLength := EditMessage.SelLength;  end;  for i := 1 to Length(message) do    MonitorHex(Ord(message[i]), sending); (* Crude, but ensures that the final BCC or CRC byte of a message is always     *)(* displayed immediately. In practice since no interactive facilities are being *)(* used it looks as though the cursor is never displayed, which means we don't  *)(* have to waste time turning it off (which doesn't force an update).           *)   FrameTerminalDisplay1.Cursor(true);  ActiveControl := savedControl;  if ActiveControl = EditMessage then begin//    EditMessage.CaretPos := savedCaret    EditMessage.SelStart := savedSelStart;//    EditMessage.SelLength := savedSelLength  endend { TFormPSTalk.MonitorHex } ; 
If I remove the monitoring stuff in the middle the cursor stays at the end of the text being edited.

MarkMLl

Thaddy:
Maybe TRecall?

MarkMLl:
Something like this?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  recall: TRecall;...    recall := TRecall.Create(TEdit.Create(nil), EditMessage);...    recall.Destroy 
I get a runtime "Cannot assign a TEdit to a TEdit" at the Create :-(

MarkMLl

Navigation

[0] Message Index

[#] Next page

Go to full version