Good day!
I have the question about table insertion into RichEdit component, representing by LMD Rich Pack.
I have custom markdown parser (maded by my own) that can parse tables and LMDRichEdit should render and display it.
LMDRTFRichEdit.pas contains `TLMDParaTableStyle` that, I gess, can be used to construct tables. I've tried to select all table-paragraph programatically by using `SelStart` and `SelLength` properties of `TLMDRichEdit` and mark it as `tsTable` in `Paragraph` property, but I doesn't take the right feedback from that.
Depending on origins of LMDRichEdit - RichEdit from WinApi, I've tried to search the solution on MSDN and finded out interesting information from here:
https://docs.microsoft.com/en-us/windows/win32/controls/em-inserttable
The quote:
`
A Microsoft Rich Edit table consists of a sequence of table rows which, in turn, consist of sequences of paragraphs. A table row starts with the special two-character delimiter paragraph U+FFF9 U+000D and ends with the two-character delimiter paragraph U+FFFB U+000D. Each cell is terminated by the cell mark U+0007, which is treated as a hard end-of-paragraph mark just as U+000D (CR) is.
`
So I splited my table-string into pices by rows framed by `&FFF9&000D` forward and `&FFFB&000D` backward and divided cells by `&0007`, then I marked `&FFF9&000D` and `&FFFB&000D` parts, as 'tsTable' cells-strings as 'tsTableRow' (and I tried switch them) but it doesn't work. Yes, it was instruction how to use EM_INSERTTABLE message, but I've tried all ways that I finded.
The question is: How I can force LMDRichEdit component render tables? LMDRTFRichEdit.pas contains such things as paragraph-tables-styles, so I looking for coresponding functionality. I belive that it can render tables but my attempts was unssuccessful.
Can you provide step-by-step solution for this question? I gess if it exists then it is kind of simple.
Example of table in markdown (of cource TLMDRichEdit couldn't convert it to table, it just the example I want to show):
```
| Тип FII | Тип Delphi | Тип C (обычно) | Ширина (в байтах) | Тип ПП |
|---------|--------------------|------------------------------|-------------------|--------|
| UInt8 | Byte | unsigned char, uing8_t | 1 | целое |
| Int8 | ShortInt | char, int8_t | 1 | целое |
| UInt16 | Word | unsigned short, uing16_t | 2 | целое |
| Int16 | SmallInt | short, int16_t | 2 | целое |
| UInt32 | LongWord, Cardinal | unsigned int, uint32_t | 4 | целое |
| Int32 | LongInt, Integer | int, int32_t | 4 | целое |
| UInt64 | UInt64 | unsigned long long, uint64_t | 8 | целое |
| Int64 | Int64 | long long, int64_t | 8 | |
| Pointer | Pointer | void* | 4 | целое |
| Single | Single | float | 4 | число |
| Double | Double | double | 8 | число |
| PChar | PChar | char* | 4 | строка |
```
Example of table I inserted in TLMDRichEdit:
```
Тип FIIТип DelphiТип C (обычно)Ширина (в байтах)Тип ПП
UInt8Byteunsigned char, uing8_t1целое
Int8ShortIntchar, int8_t1целое
UInt16Wordunsigned short, uing16_t2целое
Int16SmallIntshort, int16_t2целое
UInt32LongWord, Cardinalunsigned int, uint32_t4целое
Int32LongInt, Integerint, int32_t4целое
UInt64UInt64unsigned long long, uint64_t8целое
Int64Int64long long, int64_t8
PointerPointervoid*4целое
SingleSinglefloat4число
DoubleDoubledouble8число
PCharPCharchar*4строка
```
The example of code, thats must render the table:
pkTable: begin
richEdit.SelAttributes.Name := proportionalFont;
for i := 0 to paragraph.tContent.Count - 1 do begin
richEdit.SelStart := pos;
richEdit.SelLength := 2;
richEdit.Paragraph.TableStyle := tsTable; // FFF9 000D
Inc({var} pos, 2);
richEdit.SelStart := pos;
for j := 0 to paragraph.tContent[i].Count - 1 do begin
richEdit.SelLength :=
richEdit.SelLength +
Length(paragraph.tContent[i][j].text) + 1;
end;
richEdit.Paragraph.TableStyle := tsTableRow; // table row with cells
Inc({var} pos, richEdit.SelLength);
richEdit.SelStart := pos;
richEdit.SelLength := 2;
richEdit.Paragraph.TableStyle := tsTable; // FFFB 000D
Inc({var} pos, 2);
end;
end;
Comments
I want to avoid using RTF instead of programaticall method of filling RichEdit.