Sign in Join
Wiki copytemporary

Example-TSynEdit-HTML/pl

English · Polski · Suomi

W poniższym przykładzie pokazano TSynEdit użyte z TSynHTMLSyn. Wyniki są wyświetlane w formacie HTML przy użyciu TIpHtmlPanel.

component-TSynEdit+TIpHtmlPanel.png

pascal
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; // Uwaga: zostanie automatycznie zwolniony przez 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


From the Free Pascal wiki, page "Example-TSynEdit-HTML/pl", as the Internet Archive kept it on 2024-09-20, last changed on 2023-11-07. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 3, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.