: Anyone can help me? I want to add a caracter in a Memo at cursor Position... thanx a lot!.. : The code below will add the text to the memo at the cursor position. [code] Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced. Memo1.SelText:='The character'; // Adding the text [/code]
: : Anyone can help me? I want to add a caracter in a Memo at cursor Position... thanx a lot!.. : : : The code below will add the text to the memo at the cursor position. : [code] : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced. : Memo1.SelText:='The character'; // Adding the text : [/code] :
thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why?
: : : Anyone can help me? I want to add a caracter in a Memo at cursor Position... thanx a lot!.. : : : : : The code below will add the text to the memo at the cursor position. : : [code] : : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced. : : Memo1.SelText:='The character'; // Adding the text : : [/code] : : : : thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why? : : It probably takes the values from DefAttributes and uses those to format the added text. You could try to change them. Or you could try to set the SelAttributes just after you set the SelText.
: : : : Anyone can help me? I want to add a caracter in a Memo at cursor Position... thanx a lot!.. : : : : : : : The code below will add the text to the memo at the cursor position. : : : [code] : : : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced. : : : Memo1.SelText:='The character'; // Adding the text : : : [/code] : : : : : : : thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why? : : : : : It probably takes the values from DefAttributes and uses those to format the added text. You could try to change them. Or you could try to set the SelAttributes just after you set the SelText.
hmm I tried with selattributes before and after the seltext and doesn't work too. I tried with DefAttributes and doesn't work too.. any other propositions?
: : : : : Anyone can help me? I want to add a caracter in a Memo at cursor Position... thanx a lot!.. : : : : : : : : : The code below will add the text to the memo at the cursor position. : : : : [code] : : : : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced. : : : : Memo1.SelText:='The character'; // Adding the text : : : : [/code] : : : : : : : : : : thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why? : : : : : : : : It probably takes the values from DefAttributes and uses those to format the added text. You could try to change them. Or you could try to set the SelAttributes just after you set the SelText. : : hmm I tried with selattributes before and after the seltext and doesn't work too. I tried with DefAttributes and doesn't work too.. any other propositions? : : I have here a succesfully tested code, which does what you want: [code] procedure TForm1.Button1Click(Sender: TObject); var OldPos:integer; begin RichEdit1.SelLength:=0; // Unselect any previous selections OldPos:=RichEdit1.SelStart; // Remember the cursor position RichEdit1.SelText:='The character'; // Add the text RichEdit1.SelStart:=OldPos; // Go back to the original position RichEdit1.SelLength:=length('The character'); // select the text RichEdit1.SelAttributes.Color:=clRed; // change the attributes RichEdit1.SelLength:=0; // remove the selection end; [/code] The reason for the OldPos is that delphi moves the cursor to the last character of the new text. So if you don't jump back to the original position, you will change the text after the inserted text, not the inserted text itself.
: : : : : : Anyone can help me? I want to add a caracter in a Memo at cursor Position... thanx a lot!.. : : : : : : : : : : : The code below will add the text to the memo at the cursor position. : : : : : [code] : : : : : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced. : : : : : Memo1.SelText:='The character'; // Adding the text : : : : : [/code] : : : : : : : : : : : : : thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why? : : : : : : : : : : : It probably takes the values from DefAttributes and uses those to format the added text. You could try to change them. Or you could try to set the SelAttributes just after you set the SelText. : : : : hmm I tried with selattributes before and after the seltext and doesn't work too. I tried with DefAttributes and doesn't work too.. any other propositions? : : : : : I have here a succesfully tested code, which does what you want: : [code] : procedure TForm1.Button1Click(Sender: TObject); : var : OldPos:integer; : begin : RichEdit1.SelLength:=0; // Unselect any previous selections : OldPos:=RichEdit1.SelStart; // Remember the cursor position : RichEdit1.SelText:='The character'; // Add the text : RichEdit1.SelStart:=OldPos; // Go back to the original position : RichEdit1.SelLength:=length('The character'); // select the text : RichEdit1.SelAttributes.Color:=clRed; // change the attributes : RichEdit1.SelLength:=0; // remove the selection : end; : [/code] : The reason for the OldPos is that delphi moves the cursor to the last character of the new text. So if you don't jump back to the original position, you will change the text after the inserted text, not the inserted text itself.
I have tried your way but richedit change font when I try to entre a caracter like . try it with the caracter #0176 and keep the Terminal font.
Comments
:
The code below will add the text to the memo at the cursor position.
[code]
Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced.
Memo1.SelText:='The character'; // Adding the text
[/code]
: :
: The code below will add the text to the memo at the cursor position.
: [code]
: Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced.
: Memo1.SelText:='The character'; // Adding the text
: [/code]
:
thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why?
: : :
: : The code below will add the text to the memo at the cursor position.
: : [code]
: : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced.
: : Memo1.SelText:='The character'; // Adding the text
: : [/code]
: :
:
: thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why?
:
:
It probably takes the values from DefAttributes and uses those to format the added text. You could try to change them. Or you could try to set the SelAttributes just after you set the SelText.
: : : :
: : : The code below will add the text to the memo at the cursor position.
: : : [code]
: : : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced.
: : : Memo1.SelText:='The character'; // Adding the text
: : : [/code]
: : :
: :
: : thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why?
: :
: :
: It probably takes the values from DefAttributes and uses those to format the added text. You could try to change them. Or you could try to set the SelAttributes just after you set the SelText.
hmm I tried with selattributes before and after the seltext and doesn't work too. I tried with DefAttributes and doesn't work too.. any other propositions?
: : : : :
: : : : The code below will add the text to the memo at the cursor position.
: : : : [code]
: : : : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced.
: : : : Memo1.SelText:='The character'; // Adding the text
: : : : [/code]
: : : :
: : :
: : : thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why?
: : :
: : :
: : It probably takes the values from DefAttributes and uses those to format the added text. You could try to change them. Or you could try to set the SelAttributes just after you set the SelText.
:
: hmm I tried with selattributes before and after the seltext and doesn't work too. I tried with DefAttributes and doesn't work too.. any other propositions?
:
:
I have here a succesfully tested code, which does what you want:
[code]
procedure TForm1.Button1Click(Sender: TObject);
var
OldPos:integer;
begin
RichEdit1.SelLength:=0; // Unselect any previous selections
OldPos:=RichEdit1.SelStart; // Remember the cursor position
RichEdit1.SelText:='The character'; // Add the text
RichEdit1.SelStart:=OldPos; // Go back to the original position
RichEdit1.SelLength:=length('The character'); // select the text
RichEdit1.SelAttributes.Color:=clRed; // change the attributes
RichEdit1.SelLength:=0; // remove the selection
end;
[/code]
The reason for the OldPos is that delphi moves the cursor to the last character of the new text. So if you don't jump back to the original position, you will change the text after the inserted text, not the inserted text itself.
: : : : : :
: : : : : The code below will add the text to the memo at the cursor position.
: : : : : [code]
: : : : : Memo1.SelLength:=0; // make sure no text is selected, otherwise it is replaced.
: : : : : Memo1.SelText:='The character'; // Adding the text
: : : : : [/code]
: : : : :
: : : :
: : : : thanx a lot .. now I tried with a richedit and works fine too but change the font of the caracter.. do you know why?
: : : :
: : : :
: : : It probably takes the values from DefAttributes and uses those to format the added text. You could try to change them. Or you could try to set the SelAttributes just after you set the SelText.
: :
: : hmm I tried with selattributes before and after the seltext and doesn't work too. I tried with DefAttributes and doesn't work too.. any other propositions?
: :
: :
: I have here a succesfully tested code, which does what you want:
: [code]
: procedure TForm1.Button1Click(Sender: TObject);
: var
: OldPos:integer;
: begin
: RichEdit1.SelLength:=0; // Unselect any previous selections
: OldPos:=RichEdit1.SelStart; // Remember the cursor position
: RichEdit1.SelText:='The character'; // Add the text
: RichEdit1.SelStart:=OldPos; // Go back to the original position
: RichEdit1.SelLength:=length('The character'); // select the text
: RichEdit1.SelAttributes.Color:=clRed; // change the attributes
: RichEdit1.SelLength:=0; // remove the selection
: end;
: [/code]
: The reason for the OldPos is that delphi moves the cursor to the last character of the new text. So if you don't jump back to the original position, you will change the text after the inserted text, not the inserted text itself.
I have tried your way but richedit change font when I try to entre a caracter like . try it with the caracter #0176 and keep the Terminal font.