Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make caret go to the end of the line??? 1

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
Hi guys,

How can I make a caret go to the end of the line ???
Here is my code so far:
Code:
procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
PrevLine, CurrLine: Integer;
NeededPos: Integer;
bs: integer;
MyString: String;
begin

if Key = Word(VkKeyScan(#13)) then  // scan for pressing enter key
        begin
        PrevLine := Memo1.CaretPos_V - 1;
        CurrLine := Memo1.CaretPos_V;
        MyString := Memo1.Lines.Strings[PrevLine];
        NeededPos := Length(MyString) - Length(TrimLeft(MyString));
        Memo1.Lines[CurrLine]:= StringOfChar(' ',NeededPos);
        /* Code for going to end of CurrLine */
        end;
end;
BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com

&quot;<beer brand> is like making love in a cano...
it's <f-word + ing> close to water !!!&quot;
- Monty Python's Flying Circus, 1969/70
 
This code puts the same amount of white spaces as in the last line so if the previous line has 10 white spaces
so will the next one when you hit enter.

Its for formating code.

So first it reads the caretpos_v (this is only in gsmemo
in normal memos its &quot;memo1.caretpos.y;&quot;) giving you the
current line number and minus 1 for the previous line number. Then it gets the string of the previous line and
makes neededpos the value that results from the full string length - the lefttrimmed (trimleft removes all spaces on the left side before the first non-space character) length.
Then it write the current line with stringofchar (stringofchar makes a string of 1 char times the number stated, so &quot;StringOfChar('A',5)&quot; would result in 'AAAAA'.)
and pastes that in the memo. This is all done OnKeyUp,
and only if the key pressed was the enter key.

Hope this helps, BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com

&quot;<beer brand> is like making love in a cano...
it's <f-word + ing> close to water !!!&quot;
- Monty Python's Flying Circus, 1969/70
 
By the way,

I think I'm a little further now, because I found this
function: SetCaretPos(X,Y);. But how do I make it work
for my Memo??? Because it's not a part of it??? This
function can be found when you CTRL-[Spacebar] and just
type it in (you dont need GSMemo as I stated above).

Im using Delphi 5 Enterprise.

Thanx allot, BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com

&quot;<beer brand> is like making love in a cano...
it's <f-word + ing> close to water !!!&quot;
- Monty Python's Flying Circus, 1969/70
 
Do you need to use a GSMemo? That code works fine with a TMemo.
 
Hi mikeEd,

Yes, in this case unfortunatly i do. I need GSMemo for
making a gutter (for showing line numbers) and a dropdown list (for inserting code like in Delphi). Also search and
replace is way better implemented. And there is more.
Its a really good component.

It works in GSMemo as well, only the caret doesnt go to the
end of the line. The SetCaretPos(x,y) doesnt work either.
Do you know how to simulate a key press ??? I tried
Memo1KeyPress(Sender, VK_END);
to simulate the pressing
of the end key which makes it go to the end of the line.
But for some reason I'm not allowed to use VK_END.



BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com

&quot;<beer brand> is like making love in a cano...
it's <f-word + ing> close to water !!!&quot;
- Monty Python's Flying Circus, 1969/70
 
To simlulate pressing of the End key, you just need to send the appropriate message to your GSMemo component. Add this line to that block:
Code:
SendMessage(Memo1.Handle, WM_KEYDOWN, VK_END, 0)
 
Hi mikeEd,

That works great!!! Thank you very much! BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com

&quot;<beer brand> is like making love in a cano...
it's <f-word + ing> close to water !!!&quot;
- Monty Python's Flying Circus, 1969/70
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top