| Docs Help
  AppSource  
Docs  /  NAVAX Extension Base  /  Information for Developers

 Text Editor


2023/12/28 • 6 min. to read
The Text Editor can be opened via the EditText and ShowText procedures from the NCEX Text Editor Mgt. codeunit. Several variants (or several overloads) are available for the EditText function. The ShowText function is only for displaying and not for editing a text. The following examples show different starting situations and possibilities for integrating the text editor.

Save everything in the text field

The text editor can be called e.g. with a variable of the type Text:
procedure EditText(var Text: Text; MaxLineStrLen: Integer; MaxTextLen: Integer; ReadOnly: Boolean) TextModified: Boolean

Parameter

  • Text Specifies the text to be edited.
  • MaxLineStrLen If specified, this can be used to limit the maximum number of characters per line. The text is automatically wrapped when entered in the editor if the length is exceeded. The wrap tries to leave words whole.
  • MaxTextLen If specified, this can be used to limit the maximum number of characters of the entire text.
  • ReadOnly Specifies whether to open the editor in read-only mode. In read-only mode, the text cannot be changed. However, the text can be marked and contents from it can be copied.

Scenario

  • The following example shows the integration of the editor into the Cash Register Sales Slip Text Setup. The table has a text field with a length of 1000 characters:
    ...
    field(10; "Text"; Text[1000])
    {
        DataClassification = CustomerContent;
        Caption = 'Text', Comment = 'DEU="Text"';
    }
    field(15; "Starting Date"; Date)
    {
    ...
    Since a starting date and an ending date can be added to each text line in addition to the text and the text field itself is large enough, the following simple solution was chosen here, which does not split the text into several lines. A line break in the text is still possible. It is important that the text field in the page is set to Editable = false; because in this solution the line breaks (not visible) are also stored in the text field.

Implementation

  • Table
    ...
    procedure EditText(Editable: Boolean)
    var
        NCEXTextEditorMgt: Codeunit "NCEX Text Editor Mgt.";
        TempText: Text;
    begin
        TempText := Text;
        if not NCEXTextEditorMgt.EditText(TempText, 0, MaxStrLen(Text), not Editable) then
            exit;
        Text := CopyStr(TempText, 1, MaxStrLen(Text));
    end;
    ...
    Page
    ...
    field("Text"; Rec."Text")
    {
        ApplicationArea = All;
        ToolTip = 'Specifies the text. Click on the field to edit the text.', Comment = 'DEU="Gibt den Text an. Klicken Sie auf das Feld, um den Text zu bearbeiten."';
        Editable = false;
        AssistEdit = true;
    
        trigger OnAssistEdit()
        begin
            Rec.EditText(CurrPage.Editable());
            CurrPage.Update();
        end;
    }
    ...

Split text over multiple lines

The text editor can also be called with a variable of the type RecordRef:
procedure EditText(RecordRef: RecordRef; TextFieldNo: Integer; var TempBlob: Codeunit "Temp Blob"; ReadOnly: Boolean) TextModified: Boolean

Parameter

  • RecordRef Specifies which table and which records from the table should be loaded into the text editor.

    Important

    Special care must be taken to ensure that the correct filters are set on the RecordRef.
  • TextFieldNo Indicates in which field the text is stored.

    Note

    The maximum number of characters per line (MaxLineStrLen) is determined by the length of the TextFieldNo field in this call. The text is automatically wrapped when entered in the editor if the length is exceeded. The wrap tries to leave words whole.
  • TempBlob Contains the new, edited text.
  • ReadOnly Specifies whether to open the editor in read-only mode. In read-only mode, the text cannot be changed. However, the text can be marked and contents from it can be copied.

Scenario

  • The following example shows a possible integration of the editor into the Extended Text Lines: Since the table "Extended Text Line" contains only the text and the text field with a length of 100 characters is not large enough, the following solution was chosen here, which splits the text over several lines.

Implementation

  • pageextension 50000 "NVX Extended Text Lines" extends "Extended Text Lines"
    {
        actions
        {
            addfirst(Processing)
            {
                action(NVXTextEditorAction)
                {
                    ApplicationArea = All;
                    Caption = 'Text Editor', Comment = 'DEU="Texteditor"';
                    Image = Edit;
                    ToolTip = 'Edit the text in the text editor.', Comment = 'DEU="Bearbeiten Sie den Text im Texteditor."';
    
                    trigger OnAction()
                    var
                        ExtendedTextLine: Record "Extended Text Line";
                        NCEXTextEditorMgt: Codeunit "NCEX Text Editor Mgt.";
                        TempBlob: Codeunit "Temp Blob";
                        RecordRef: RecordRef;
                        InStream: InStream;
                        NextLineNo: Integer;
                        TempText: Text;
                    begin
                        Clear(ExtendedTextLine);
                        ExtendedTextLine.SetRange("Table Name", Rec."Table Name");
                        ExtendedTextLine.SetRange("No.", Rec."No.");
                        ExtendedTextLine.SetRange("Language Code", Rec."Language Code");
                        ExtendedTextLine.SetRange("Text No.", Rec."Text No.");
                        RecordRef.GetTable(ExtendedTextLine);
                        if not NCEXTextEditorMgt.EditText(RecordRef, ExtendedTextLine.FieldNo(Text), TempBlob, not CurrPage.Editable()) then
                            exit;
    
                        ExtendedTextLine.LockTable();
                        ExtendedTextLine.DeleteAll();
                        NextLineNo := 10000;
                        TempBlob.CreateInStream(InStream);
                        while (not InStream.EOS()) do begin
                            Clear(ExtendedTextLine);
                            ExtendedTextLine."Table Name" := Rec."Table Name";
                            ExtendedTextLine."No." := Rec."No.";
                            ExtendedTextLine."Language Code" := Rec."Language Code";
                            ExtendedTextLine."Text No." := Rec."Text No.";
                            ExtendedTextLine."Line No." := NextLineNo;
                            NextLineNo += 10000;
                            InStream.ReadText(TempText);
                            ExtendedTextLine.Text := CopyStr(TempText, 1, MaxStrLen(ExtendedTextLine.Text));
                            ExtendedTextLine.Insert();
                        end;
                    end;
                }
            }
        }
    }

Store text in a blob

Calling the text editor with Codeunit "Temp Blob" without RecordRef is also possible:
procedure EditText(var TempBlob: Codeunit "Temp Blob"; MaxLineStrLen: Integer; MaxTextLen: Integer; ReadOnly: Boolean) TextModified: Boolean

Parameter

  • TempBlob Contains the text to be edited.
  • MaxLineStrLen If specified, this can be used to limit the maximum number of characters per line. The text is automatically wrapped when entered in the editor if the length is exceeded. The wrap tries to leave words whole.
  • MaxTextLen If specified, this can be used to limit the maximum number of characters of the entire text.
  • ReadOnly Specifies whether to open the editor in read-only mode. In read-only mode, the text cannot be changed. However, the text can be marked and contents from it can be copied.

Scenario

  • If the text is to be stored directly to the record (i.e. no splitting to several records) and the solution via a text field is out of question due to the limited field length (depending on the definition max. 2048 characters), the text can also be stored in a blob field. Optionally, another field can be created, which displays a preview of the blob field content. The following example shows a possible solution.

Implementation

  • Table
    ...
    field(50000; "Text Preview"; Text[250])
    {
        DataClassification = CustomerContent;
        Caption = 'Text Preview', Comment = 'DEU="Textvorschau"';
    }
    field(50001; "Text Storage"; Blob)
    {
        DataClassification = CustomerContent;
        Caption = 'Text Storage', Comment = 'DEU="Textspeicher"';
    }
    
    procedure EditText(Editable: Boolean)
    var
        NCEXTextEditorMgt: Codeunit "NCEX Text Editor Mgt.";
        TempBlob: Codeunit "Temp Blob";
        InStream: InStream;
        OutStream: OutStream;
        NewText: Text;
    begin
        CalcFields("Text Storage");
        "Text Storage".CreateInStream(InStream);
        TempBlob.CreateOutStream(OutStream);
        CopyStream(OutStream, InStream);
        if not NCEXTextEditorMgt.EditText(TempBlob, 0, 0, not Editable) then
            exit;
        TempBlob.CreateInStream(InStream);
        InStream.Read(NewText);
        SaveText(NewText);
    end;
    
    procedure SaveText(NewText: Text)
    var
        OutStream: OutStream;
    begin
        "Text Storage".CreateOutStream(OutStream);
        OutStream.Write(NewText);
        "Text Preview" := CopyStr(NewText, 1, MaxStrLen("Text Preview"));
    end;
    ...
    Page
    ...
    field("Text Preview"; Rec."Text Preview")
    {
        ApplicationArea = All;
        ToolTip = 'Specifies the text. Click on the field to edit the text.', Comment = 'DEU="Gibt den Text an. Klicken Sie auf das Feld, um den Text zu bearbeiten."';
        Editable = false;
        AssistEdit = true;
    
        trigger OnAssistEdit()
        begin
            Rec.EditText(CurrPage.Editable());
            CurrPage.Update();
        end;
    }
    ...


Submit feedback for
DE|EN Imprint
<>