I have a TMemo object with about 30 lines (some text, some blank lines) of text in it representing the message body of an email I want the application to send. In the code below I'm passing the text in the TMemo object to IdMessage1.Body.Text (Indy 10), but my resulting email message body appears that it's just one continuous line wrapped. I would like to see the spacing I have that contains some blank lines. If I copy the contents from the Lines parameter of the TMemo and paste it into a text editor I can see the CR & LF at the end of the lines.
Does the CR & LF get stripped off in this translation, should I be using a different component rather than TMemo for this, or am I passing the lines in the TMemo to the IdMessage1.Body.Text incorrectly?
IdMessage1.Body.Text := EmailBodyMemo.Text;
IdMessage1.ContentType := 'text/html';
The TMemo.Text property returns the entire content as a single string without any "soft" (word-wrapping) line breaks inserted between each line, only "hard" line breaks (explicit CR/LF characters).
Use this instead:
IdMessage1.Body.Text := EmailBodyMemo.Lines.Text;
Lines.Text returns a string that has each line separated by Lines.LineBreak (CRLF by default on Windows).
Or better, use this instead:
IdMessage1.Body := EmailBodyMemo.Lines;
Which is the same as doing this:
IdMessage1.Body.Assign(EmailBodyMemo.Lines);
I was trying to detect Ctrl+V from a TEdit's OnKeyPress event and I've noticed that the Key parameter assumes an unusual value when pressing Ctrl+AnyKey.
Example:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
ShowMessage(IntToStr(Ord(Key)));
end;
It produces the following results:
Ctrl+Q 17
Ctrl+W 23
Ctrl+E 5
Ctrl+R 18
...
Ctrl+A 1
Ctrl+Z 26
Ctrl+C 3
Ctrl+V 22
Ctrl+X 24
I don't understand how keys are translated, what does these codes mean?
It seems it has nothing to do with the ASCII table:
Could anyone shed some light on this?
I don't understand how keys are translated, what does these codes mean?
The values you get with the Ctrl+AnyKey combinations are Ascii control codes.
They emanate from the need to enter non-printing (control) characters from the keyboard. The (typical) values for the control characters are below 32 plus the del character (127).
Some more information about the history behind and standards could be found here and here.
I'm having some trouble with a program. I must delete/modify certain lines in a text file. The program is like a database, it stores names, ages, and registration numbers of people. I have tried everything.
form2.info.Lines.Add('Nr. ordine ' +Inttostr(numar)+ ' ');
form2.mmo1.Lines.Add('Nr.ordine' +Inttostr(numar)+ ' ');
form2.mmo1.Lines.Add('Nume: ' +nume+ ' ');
form2.mmo1.Lines.Add('Prenume: ' +prenume+ ' ');
Each time I close my program, the registration number is always 1 and I want it to be continued from where I left it. How can I do it?
How can I modify a specific line in my text?
You will have to save your last registration number to a text file and retrieve it at startup. If you do not want to store it separately, you could load the whole file and look for the latest registration number.
To modify or read a specified line in memo you can use line index:
form2.mmo1.Lines.Strings[0] := 'This is line 0';
I would suggest you to store your 'database' in TStringGrid
I have problem with counting characters in richedit (Delphi XE).
For every new line as a result i get two characters more but in text they not exists.
Example: Here are 15 characters, but richedit gives 17 because of new line.
line zero
line one
Is there solution for this?
Remove CR/LFs and get the count of the remaining characters. An example:
NumChars := Length(StringReplace(RichEdit1.Text, sLineBreak, '', [rfReplaceAll]));
Given this line of code in C:
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
Is there a way to delete or yank from the first bold parenthesis to its matching parenthesis? I thought about df), but that only will get you to just after the 9.0.
Is there a similar way to get vim to grab everything between matching braces, regardless of newlines?
What about dib or di(.
It will delete the inner (...) block where the cursor is.
I love text-object motions and selections!
Various Motions: %
The % command jumps to the match of the item under the cursor. Position the cursor on the opening (or closing) paren and use y% for yanking or d% for deleting everything from the cursor to the matching paren.
This works because % is a "motion command", so it can be used anywhere vim expects such a command. From :help y:
["x]y{motion} Yank {motion} text [into register x]. When no
characters are to be yanked (e.g., "y0" in column 1),
this is an error when 'cpoptions' includes the 'E'
flag.
By default, "item" includes brackets, braces, parens, C-style comments and various precompiler statements (#ifdef, etc.).
There is a plugin for "extended % matching" that you can find on the Vim homepage.
You can read the documentation on % and related motion commands by entering :help various-motions in command mode.
object-select
There is another set of motion commands that you can use in Visual mode to select various text objects.
To solve your specific problem you would do the following:
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
^
Let's say your cursor is positioned at ^. Enter the following sequence to select the part you are looking for:
v2a)
First v enters Visual mode, then you specify that you want to go 2 levels of parens up. Finally the a) selects "a block". After that you can use d or x to delete, etc.
If you don't want to include the outer parens, you can use "inner block" instead:
v2i)
See :help object-select for the complete list of related commands.
To delete all that is inside a pair of parentheses, you can always issue di( and its derivatives.
Note :
As #porglezomb suggested in his comment, you can use a ("along with") instead of i ("inside") to include the parentheses. So, using da( deletes everything inside ( and ) including ( and ).
Deleting text inside the immediate outer pair of parentheses :
So, for this line of code
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
^ ^
| |
\_______\___---> Cursor range
assuming that your cursor is inside the above mentioned cursor range, you can issue the following commands :
di( --> Deletes '5.0/9.0'
ci( --> Substitutes '5.0/9.0'
yi( --> Yanks '5.0/9.0'
Deleting text inside the n-th outer pair of parentheses :
To grab everything inside the n-th outer pair of parentheses, just add n before the above command. So, with the same cursor position as above,
2di( --> Deletes '(5.0/9.0) * (fahr-32)'
2ci( --> Substitutes '(5.0/9.0) * (fahr-32)'
2yi( --> Yanks '(5.0/9.0) * (fahr-32)'
3di( --> Deletes '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
3ci( --> Substitutes '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
3yi( --> Yanks '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
You can use d% for deleting and y% for yanking.
Place your cursor on the first parenthesis, then press v%y or v%d.
Try ci[block-surrounder]
In your case, place the cursor anywhere between the 2 parenthesis that you highlighed and try the keys: ci(
As answer of David Norman says,
Place your cursor on the first parenthesis, then press v%y or v%d.
Explanation from http://vimdoc.sourceforge.net/htmldoc/vimindex.html:
tag char note action in Normal mode
------------------------------------------------------------------------------
|v| v start characterwise Visual mode
|%| % 1 find the next (curly/square) bracket on
this line and go to its match, or go to
matching comment bracket, or go to matching
|d| ["x]d{motion} 2 delete Nmove text [into buffer x]
This means it will select everything between and including the two brackets (%) while showing the selection to you visually (v) and then yank/copy y or delete/cut d it. (To the default buffer.)
You can put/paste with p.
Made this answer to "teach myself to fish".