Forum > General

TMemo box cursor position

(1/2) > >>

captian jaster:

--- Code: ---procedure TMainForm.AddRootItemClick(Sender: TObject);
Var
USerString:String;
Counter:Integer;
begin
  IF(RootIsAdded = True)Then ShowMessage('Root Was added already')Else
  IF(FileIsOPen = False)Then ShowMessage('You have to start a new XML files or open a current one')Else
  begin
    UserString := InputBox('Root Name','Enter the name of your root.','');
    IF(UserString <> '')Then
    begin
      XMLBox.Append('<'+UserString+'>');
      For Counter := 1 to 6 Do
      begin
        XMLBox.Append('');
      end;
      XMLBox.Append('</'+UserString+'>');
      RootIsAdded := True;
    end;
  end;
end;     

--- End code ---

I want to put the cursor up at the first XMLBox.Append. How can i do that

eny:
Maybe this works:


--- Quote from: captian jaster on June 07, 2010, 09:55:44 am ---
--- Code: ---procedure TMainForm.AddRootItemClick(Sender: TObject);
Var
USerString:String;
Counter:Integer;
CursorPos: integer;
begin
  IF(RootIsAdded = True)Then ShowMessage('Root Was added already')Else
  IF(FileIsOPen = False)Then ShowMessage('You have to start a new XML files or open a current one')Else
  begin
    UserString := InputBox('Root Name','Enter the name of your root.','');
    IF(UserString <> '')Then
    begin
      XMLBox.Append('<'+UserString+'>');
      CursorPos := length(XMLBox.Text);
      For Counter := 1 to 6 Do
      begin
        XMLBox.Append('');
      end;
      XMLBox.Append('</'+UserString+'>');
      XMLBox.SelStart := CursorPos;
      RootIsAdded := True;
    end;
  end;
end;     

--- End code ---

I want to put the cursor up at the first XMLBox.Append. How can i do that

--- End quote ---

captian jaster:
That works :D
Thnx eny

captian jaster:
Now im having a second problem. i thought by putting the cursor there using the Append code would append it to the cursor position.. its not..

--- Code: ---procedure TMainForm.AddParentItemClick(Sender: TObject);
Var
USerString:String;
CursorPos,Counter:Integer;
begin
  IF(ParentisAdded = True)Then ShowMessage('Parent Was Already added!')Else
  IF(FIleIsOpen = False)Then ShowMessage(FileOPenInfo)Else
  begin
    UserString := InputBox('Parent Name','Enter the name of your parent','');
    IF(UserString <> '')Then
    begin
      XMLBox.Append('<'+UserString+'>');
      CursorPos := length(XMLBox.Text);
      For Counter := 1 to 3 Do
      begin
        XMLBox.Append('');
      end;
      XMLBox.Append('</'+UserString+'>');
      XMLBox.SelStart := CursorPos;
      ParentIsAdded := True;
    end;
  end;
end;     

--- End code ---
This is to add the parent.

This is my problem the parent wont go at the cursor position

eny:
Please read the run-time library and search for TStrings (p.350).

The big white box with the small blinking vertical line and text in it (TMemo) is just a graphical presentation of the text you've assembled (Memo.Lines).
If you directly manipulate the text of the memo (XMLBox.Append, XMLBox.Insert and what not) you'll have to do your own administration regarding the insertion point of the text. The blinking cursor is just the insertion point for when you start typing on the keyboard.

BTW: you'll need XMLBox.Insert().
Your next questions regarding this subject will be answered in the section of the rtl as mentioned above.

Navigation

[0] Message Index

[#] Next page

Go to full version