Delphi memo why cursor going to the Left always [closed] - delphi

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In my VCL project, I have a TMemo with the following text (| is the caret):
| |
|Hello world | |
| |
|test |
| |
| |
When I press the Down button, the caret moves here:
| |
|Hello world |
|| |
|test |
| |
| |
What I need is for it to move here instead:
| |
|Hello world |
| | |
|test |
| |
| |

I think you would find it instructive to devise your own solution for this. The default behaviour for a TMemo responding to the Down key depends on how many characters there are on the next line. If there are at least as many on the next line as there are on the current line, the caret will stay in the same column number.
So a simple solution might be
When you detect an OnKeyDown event caused by the Down key, check the number of characters in the next line, and if it is fewer than the number of characters in the current line to the left of the caret, right-pad the line below with spaces until the numbers of characters are equal. The on-screen appearance will only exactly maintain the column position if the memo uses a fixed-point font; with a proportional font, the cursor will still "wiggle" a bit left and right because spaces are narrower than most other characters.
Of course, you would need to do this for the Up key too, and it's up to you whether you do similar for mouse clicks.
With a bit of googling you can easily find Delphi code to detect the current line and column number of the caret in a TMemo.

The TMemo in Delphi merely wraps the internal control within Windows itself - which does not natively support such functionality that you desire. It may be possible to modify it to behave in such manner, but easier to use something which is already designed for this. One largely popular control which can do this is the SynEdit which is geared towards code editors and syntax highlighting. It might do much more than you need, but it solves what you're looking for.

Related

How to insert hard line break in Quarto document

I'm working with the Quarto document preparation system to programmatically generate large documents using Python. That is I am not using the RStudio or similar editor. All text must be generated as Python strings.
I have a simple table where one cell has several lines worth of content and I figure that I can add line-breaks within the cell. I understand that simple tables cannot include standard line breaks (\n) but I'm wondering if there is a way to insert so-called "hard-line-breaks" in cells. The user manual mentions them but states that only the editor can insert them. Is it possible to do this using string operations in the markdown source text?
Barring that is there a simple way to break lines within a cell in a table?
Quarto tables generated by RStudio visual Markdown editor
There's not much magic involved when it comes to hard line breaks, just lines that end with a \.
QMD file created in RStudio with visual mode enabled, a (Grid) table with both regular and hard line breaks looks like this:
---
title: "tbl"
format: html
editor: visual
---
+-------+-------------+
| Col1 | Col2 |
+=======+=============+
| press | press\ |
| | shift+enter |
| enter | |
+-------+-------------+
| | |
+-------+-------------+
With all the whitespace and linefeeds next to rendered output:
While RStudio visual editor starts with simple pipe tables, it switches automatically to grid tables when it encounters a line break or anything else in a cell that's not supported by simple pipe tables.
Python and grid-style Markdown tables
For generating Markdown grid tables in Python, tabulate with tablefmt="grid" is quite handy. Or pandas.DataFrame.to_markdown() in case of pandas, also built on top of tabulate.
from tabulate import tabulate
td = [["press\n\nenter","press\\\nshift+enter"],["no\nbackslash","",]]
hdr = ["Col1", "Col2"]
print(tabulate(td,headers=hdr, tablefmt="grid"))
Result:
+-----------+-------------+
| Col1 | Col2 |
+===========+=============+
| press | press\ |
| | shift+enter |
| enter | |
+-----------+-------------+
| no | |
| backslash | |
+-----------+-------------+
Rendered with Quarto:
Pandoc multiline tables
For whatever reason this is not mentioned in Quarto docs, but Pandoc also supports multiline_tables and rendering it with Quarto & Pandoc that are bundled with RStudio works fine, though for hard line breaks it still needs \ before a break.
Slighty modified sample from Pandoc documentation:
-------------------------------------------------------------
Centered Default Right Left
Header Aligned Aligned Aligned
----------- ------- --------------- -------------------------
First row 12.0 Example of\
a row that
spans multiple lines.
Second row 5.0 Here's another one. Note
the blank line between
rows.
-------------------------------------------------------------
Table: Here's the caption. It, too, may span\
multiple lines.
Renders as:

Spaceing in TMemo not matching text file [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a text file with this:
_____ _ ___ _ _
|_ _| |_ ___ / __|_ _(_)__| |
| | | ' \/ -_) | (_ | '_| / _` |
|_| |_||_\___| \___|_| |_\__,_|
When I load the file into a TMemo, it looks like this:
How can I fix this? Why is it doing this?
I'm using Delphi 10.2.
procedure TFrmMain.FormCreate(Sender: TObject);
begin
Memo2.Lines.LoadFromFile('C:\Users\user1\Desktop\demo\thegrid.txt');
end;
You're using a variable-width font to display it, and ASCII art like that only looks right when it's displayed with a fixed-width font.

How to shift table in markdown file?

I have a table in README.md file in TFS like this:
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
It's work. But I need to shift this table to the right by tab character. And if I place tab (or space character) before table rows it's not recognize as table and just print as plain text. HTML tag also doesn't work in TFS.
How I can move table?
Unfortunately shift table is not supported in Markdown.
Markdown does not provide any special syntax for tables.
Please see Syntax guidance for Markdown files, widgets, wikis, and pull request comments for details.
I can think of is that you can capture a screenshot for the table, render the captured image, check in the image, then Add image to your Markdown file.
But please note that just as Waylan mention in below comments : For screenshot of a table, the text will no longer be searchable and cannot be copy and pasted by the user. And any future edits will require recreating the entire table.

Repeating steps with different values in BDD test case

I am new to BDD specflow.
I have to write a scenario wherein after I capture an image, i have to select a value for each defined attribute for that image from a selection list
For Eg:
|Body Part |Location |Group |
| Leg | Left | Skin |
| Hand | Upper | Burn |
| Arm | Right | Ulcer |
I need a way in which i can select a different value for each attribute, every time.
Thanks in advance!
You are looking for Scenario Outline;
Scenario outlines allow us to more concisely express these examples through the use of a template with placeholders, using Scenario Outline, Examples with tables and < > delimited parameters.
Specflow takes each line in the Example table and create from the line a scenario to execute.

Scenario Outline: Placeholders with a restricted number of possible values

I am relatively new to BDD and I have a question regarding scenario outlines. When looking at samples over the internet I have the feeling that the placeholders can take any values. The number of elements in their domain is not restricted. Here is one example:
Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
The placeholder <start> for example can be any number so the number of values is infinite.
In my specs I have to deal with contracts which can have one of four states (planned, ongoing, paused, and closed). My specs say that I can edit planned contracts but I am not allowed to edit contracts which have one of the remaining three states.
I think I would write a scenario named "Updating a planned contract" and one scenario outline where the status of a contract is a placeholder.
Scenario: Update a planned contract
Given the list of contracts as follows
| name | status | some value |
| c1 | planned | 123 |
And I have edited contract c1 as follows
| field | value |
| name | c1 |
| some value | 456 |
When I save contract c1
Then the list of contracts should be as follows
| name | status | some value |
| c1 | planned | 456 |
Scenario Outline: Update contract
Given there is a <status> contract
And I have edited that contract
When I save that contract
Then I an error 'only planned contracts are allowed to change' should be displayed
Examples:
| status |
| ongoing |
| paused |
| closed |
Is that the right way? One expicit scenario and one parameterized? Or should I write the scenario outline as explicit scenarios for each possibility? I am not sure because the status of a contract is restricted by four possible values as opposed to the examples on the internet.
One thing I find that helps is to remember that Gherkin is just a syntax for Specification by Example. You are trying to provide the examples that make most sense to you in the business domains language.
As such, what you are proposing is perfectly valid. You have one example of a scenario that uses tables to define what happens when a planned contract is edited, and another set of examples that produce errors when contracts in other states. You could also do it explicitly by expanding the outline for each state. Both are valid, and you can always refactor your feature sepcifications as you would the codebase.
What you are aiming to do here however is to provide a grammar, a framework, a language, call it what you will, that you can use to have conversations with your business analysts. You want to be able to pull out this document and say "This is how the system works now, how do we change this to make it support your new feature?".
Personally, I'm avoiding tabular and outline forms in my features right now as I want to make it look as friendly as possible to all I show it to, and as yet, my features are still easy to describe.

Resources