Einzelnen Beitrag anzeigen

tomkupitz

Registriert seit: 26. Jan 2011
323 Beiträge
 
Delphi 11 Alexandria
 
#1

RichEdit Table

  Alt 29. Jun 2022, 17:40
Hallo,

ich habe hier ein Stück Quelltext gefunden. Damit möchte ich eine Tabelle in ein RichEdit einfügen. Geht auch solange rows.cCell := 1; ist. Ansonsten gibt es einen Fehler. Habt ihr einen Lösungsansatz?

Code:
unit RichEditInsertTableUnit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    procedure FormClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  _tableRowParms = record
     cbRow          : BYTE;       // Count of bytes in this structure
     cbCell         : BYTE;       // Count of bytes in TABLECELLPARMS
     cCell          : BYTE;       // Count of cells
     cRow           : BYTE;       // Count of rows
     dxCellMargin   : LONGINT;    // Cell left/right margin (\trgaph)
     dxIndent       : LONGINT;    // Row left (right if fRTL indent (similar to \trleft)
     dyHeight       : LONGINT;    // Row height (\trrh)
     nParams        : DWORD;      // 0 - 2 bits - Row alignment (like PARAFORMAT::bAlignment, 1/2/3) (\trql, trqr, \trqc)
                                    // 3 bit - Display cells in RTL order (\rtlrow)
                                    // 4 bit - Keep row together (\trkeep}
                                    // 5 bit - Keep row on same page as following row (\trkeepfollow)
                                    // 6 bit - Wrap text to right/left (depending on bAlignment) (see \tdfrmtxtLeftN, \tdfrmtxtRightN)
                                    // 7 bit - lparam points at single struct valid for all cells
     cpStartRow     : LONGINT;    // The character position that indicates where to insert table. A value of –1 indicates the character position of the selection.
     bTableLevel    : BYTE;       // The table nesting level (EM_GETTABLEPARMS only).
     iCell          : BYTE;       // The index of the cell to insert or delete (EM_SETTABLEPARMS only).
  end;
  TABLEROWPARMS = _tableRowParms;
  TTableRowParms = TABLEROWPARMS;
  PTableRowParms = ^TTableRowParms;


  _tableCellParms = record
     dxWidth        : LONGINT;    // Cell width (\cellx)
     nParams        : Word;       // 0 - 1 bits - Vertical alignment (0/1/2 = top/center/bottom) (\clvertalt (def), \clvertalc, \clvertalb)
                                    // 2 bit - Top cell for vertical merge (\clvmgf)
                                    // 3 bit - Merge with cell above (\clvmrg)
                                    // 4 bit - Display text top to bottom, right to left (\cltxtbrlv)
                                    // 5 bit - Start set of horizontally merged cells (\clmgf).
                                    // 6 bit - Merge with the previous cell (\clmrg).
     wShading      : WORD;        // Shading in .01% (\clshdng) e.g., 10000 flips fore/back
     dxBrdrLeft    : SHORT;       // Left border width (\clbrdrl\brdrwN) (in twips)
     dyBrdrTop     : SHORT;       // Top border width (\clbrdrt\brdrwN)
     dxBrdrRight   : SHORT;       // Right border width (\clbrdrr\brdrwN)
     dyBrdrBottom  : SHORT;       // Bottom border width (\clbrdrb\brdrwN)
     crBrdrLeft    : COLORREF;    // Left border color (\clbrdrl\brdrcf)
     crBrdrTop     : COLORREF;    // Top border color (\clbrdrt\brdrcf)
     crBrdrRight   : COLORREF;    // Right border color (\clbrdrr\brdrcf)
     crBrdrBottom  : COLORREF;    // Bottom border color (\clbrdrb\brdrcf)
     crBackPat     : COLORREF;    // Background color (\clcbpat)
     crForePat     : COLORREF;    // Foreground color (\clcfpat)
  end;
  TABLECELLPARMS = _tableCellParms;
  TTableCellParms = TABLECELLPARMS;
  PTableCellParms = ^TTableCellParms;

const
  EM_INSERTTABLE = WM_USER + 232;

//

procedure TForm1.FormClick(Sender: TObject);
var rows: TABLEROWPARMS;
    cells: TABLECELLPARMS;

begin
   ZeroMemory(@rows, sizeof(rows));
   rows.cbRow := sizeof(TABLEROWPARMS);
   rows.cbCell := sizeof(TABLECELLPARMS);
   rows.cCell := 1;
   rows.cRow := 3;

   ZeroMemory(@cells, sizeof(cells));
   cells.dxWidth := 1000;
   cells.crBrdrLeft := RGB(255,0,0);
   cells.crBrdrTop := RGB(0, 255, 0);
   cells.crBrdrRight := RGB(0, 0, 255);
   cells.crBrdrBottom := RGB(255, 255, 0);
   cells.crBackPat := RGB(255, 255, 255);
   cells.crForePat := RGB(128, 64, 64);

   if SendMessage(RichEdit1.Handle, EM_INSERTTABLE, WPARAM(@rows), LPARAM(@cells)) <> S_OK then
   begin
     ShowMessage('Fehler');
   end;
end;

end.
Danke und beste Grüße
  Mit Zitat antworten Zitat