Difference between revisions of "TSynEdit"

From Lazarus wiki
Jump to navigationJump to search
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''TSynEdit''' is a component that provides the display-part of syntax-highlighting editing. It is part of the [[SynEdit]] package and is available under the 'SynEdit' tab of the [[Component Palette]].  
+
{{TSynEdit}}
 +
 
 +
'''TSynEdit''' [[image:tsynedit.png]] is a text editor component that provides, among other things, the display-part of [[Syntax highlighting|syntax-highlighting]] editing. It is part of the [[SynEdit]] package and is available under the [[SynEdit tab]] of the [[Component Palette]].  
  
 
TSynEdit is used in conjunction with a specific syntax highlighter that is connected through the ''Highlighter'' property of the TSynEdit.
 
TSynEdit is used in conjunction with a specific syntax highlighter that is connected through the ''Highlighter'' property of the TSynEdit.
  
[[File:component-TSynEdit+TIpHtmlPanel.png]]
+
== Example ==
 
+
{{:Example-TSynEdit-HTML}}
<syntaxhighlight>
 
unit TipHtmlTest;
 
 
 
{$mode objfpc}{$H+}
 
 
 
interface
 
 
 
uses
 
  Classes, SysUtils, FileUtil, IpHtml, SynHighlighterHTML, SynHighlighterAny,
 
  SynEdit, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
 
 
 
const
 
  htmfile = 'tiphtmltestdata.html';
 
 
 
type
 
  TTipHtmlForm = class(TForm)
 
    IpHtmlPanel1: TIpHtmlPanel;
 
    Splitter1: TSplitter;
 
    Memo1: TSynEdit;
 
    SynHTMLSyn1: TSynHTMLSyn;
 
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
 
    procedure FormCreate(Sender: TObject);
 
    procedure MemoChange(Sender: TObject);
 
  protected
 
  public
 
    procedure ShowText( const txt: string );
 
  end;
 
 
 
var
 
  TipHtmlForm: TTipHtmlForm;
 
 
 
implementation
 
 
 
{$R *.lfm}
 
  
procedure TTipHtmlForm.FormCreate(Sender: TObject);
 
begin
 
  if FileExists( htmfile ) then
 
    Memo1.Lines.LoadFromFile( htmfile )
 
  else
 
    Memo1.Lines.Text := '<html><head><title>tipmemo</title></head><body><h1>tipmemo</h1>See <b>' +htmfile + '</b></body></html>';
 
  MemoChange( nil );
 
end;
 
 
 
procedure TTipHtmlForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
 
begin
 
  Memo1.Lines.SaveToFile( htmfile );
 
end;
 
 
 
procedure TTipHtmlForm.MemoChange(Sender: TObject);
 
begin
 
  ShowText( Memo1.Lines.Text );
 
end;
 
 
 
procedure TTipHtmlForm.ShowText( const txt: string );
 
var
 
  fs: TStringStream;
 
  pHTML: TIpHtml;
 
begin
 
  try
 
    fs := TStringStream.Create( txt );
 
    try
 
      pHTML:=TIpHtml.Create; // Beware: Will be freed automatically by IpHtmlPanel1
 
      pHTML.LoadFromStream(fs);
 
    finally
 
      fs.Free;
 
    end;
 
    IpHtmlPanel1.SetHtml( pHTML );
 
    Caption := IpHtmlPanel1.Title;
 
  except
 
    on E: Exception do begin
 
      MessageDlg( 'Error: '+E.Message, mtError, [mbCancel], 0 );
 
    end;
 
  end;
 
end;       
 
</syntaxhighlight>
 
 
[[File:component-TSynEdit+TIpHtmlPanel-r.png]]
 
  
 
{{LCL Components}}
 
{{LCL Components}}
 
[[Category:Components]]
 
[[Category:SynEdit]]
 

Latest revision as of 19:37, 12 September 2019

English (en) suomi (fi) français (fr) русский (ru)

TSynEdit tsynedit.png is a text editor component that provides, among other things, the display-part of syntax-highlighting editing. It is part of the SynEdit package and is available under the SynEdit tab of the Component Palette.

TSynEdit is used in conjunction with a specific syntax highlighter that is connected through the Highlighter property of the TSynEdit.

Example

In the example below is a TSynEdit used with a TSynHTMLSyn. The results are displayed as formatted HTML using a TIpHtmlPanel.

component-TSynEdit+TIpHtmlPanel.png

unit TipHtmlTest;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, IpHtml, SynHighlighterHTML, SynHighlighterAny,
  SynEdit, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;

const
  htmfile = 'tiphtmltestdata.html';

type
  TTipHtmlForm = class(TForm)
    IpHtmlPanel1: TIpHtmlPanel;
    Splitter1: TSplitter;
    Memo1: TSynEdit;
    SynHTMLSyn1: TSynHTMLSyn;
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure MemoChange(Sender: TObject);
  protected
  public
    procedure ShowText( const txt: string );
  end;

var
  TipHtmlForm: TTipHtmlForm;

implementation

{$R *.lfm}

procedure TTipHtmlForm.FormCreate(Sender: TObject);
begin
  if FileExists( htmfile ) then
    Memo1.Lines.LoadFromFile( htmfile )
  else
    Memo1.Lines.Text := '<html><head><title>tipmemo</title></head><body><h1>tipmemo</h1>See <b>' +htmfile + '</b></body></html>';
  MemoChange( nil );
end;


procedure TTipHtmlForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  Memo1.Lines.SaveToFile( htmfile );
end;


procedure TTipHtmlForm.MemoChange(Sender: TObject);
begin
  ShowText( Memo1.Lines.Text );
end;


procedure TTipHtmlForm.ShowText( const txt: string );
var
  fs: TStringStream;
  pHTML: TIpHtml;
begin
  try
    fs := TStringStream.Create( txt );
    try
      pHTML:=TIpHtml.Create; // Beware: Will be freed automatically by IpHtmlPanel1
      pHTML.LoadFromStream(fs);
    finally
      fs.Free;
    end;
    IpHtmlPanel1.SetHtml( pHTML );
    Caption := IpHtmlPanel1.Title;
  except
    on E: Exception do begin
      MessageDlg( 'Error: '+E.Message, mtError, [mbCancel], 0 );
    end;
  end;
end;

component-TSynEdit+TIpHtmlPanel-r.png



LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu