Sign in Join
Wiki copytemporary

Example-TSynEdit-HTML/fi: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Example-TSynEdit-HTML/fi

OldNewLine
1+Alla olevassa esimerkissä on [[TSynEdit/fi|TSynEdit]]-komponentti, jota käytetään yhdessä [[TSynHTMLSyn/fi|TSynHTMLSyn]]-komponentin kanssa. Tulos näytetään muotoiltuna [[HTML/fi|HTML]]-tiedostona käyttäen [[TIpHtmlPanel/fi|TIpHtmlPanel]] -komponenttia.
2+
3+<figure>
4+<img src="component-TSynEdit+TIpHtmlPanel.png" title="component-TSynEdit+TIpHtmlPanel.png" />
5+<figcaption>component-TSynEdit+TIpHtmlPanel.png</figcaption>
6+</figure>
7+
8+``` pascal
9+unit TipHtmlTest;
10+
11+{$mode objfpc}{$H+}
12+
13+interface
14+
15+uses
16+ Classes, SysUtils, FileUtil, IpHtml, SynHighlighterHTML, SynHighlighterAny,
17+ SynEdit, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
18+
19+const
20+ htmfile = 'tiphtmltestdata.html';
21+
22+type
23+ TTipHtmlForm = class(TForm)
24+ IpHtmlPanel1: TIpHtmlPanel;
25+ Splitter1: TSplitter;
26+ Memo1: TSynEdit;
27+ SynHTMLSyn1: TSynHTMLSyn;
28+ procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
29+ procedure FormCreate(Sender: TObject);
30+ procedure MemoChange(Sender: TObject);
31+ protected
32+ public
33+ procedure ShowText( const txt: string );
34+ end;
35+
36+var
37+ TipHtmlForm: TTipHtmlForm;
38+
39+implementation
40+
41+{$R *.lfm}
42+
43+procedure TTipHtmlForm.FormCreate(Sender: TObject);
44+begin
45+ if FileExists( htmfile ) then
46+ Memo1.Lines.LoadFromFile( htmfile )
47+ else
48+ Memo1.Lines.Text := '<html><head><title>tipmemo</title></head><body><h1>tipmemo</h1>See <b>' +htmfile + '</b></body></html>';
49+ MemoChange( nil );
50+end;
51+
52+procedure TTipHtmlForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
53+begin
54+ Memo1.Lines.SaveToFile( htmfile );
55+end;
56+
57+procedure TTipHtmlForm.MemoChange(Sender: TObject);
58+begin
59+ ShowText( Memo1.Lines.Text );
60+end;
61+
62+procedure TTipHtmlForm.ShowText( const txt: string );
63+var
64+ fs: TStringStream;
65+ pHTML: TIpHtml;
66+begin
67+ try
68+ fs := TStringStream.Create( txt );
69+ try
70+ pHTML:=TIpHtml.Create; // Beware: Will be freed automatically by IpHtmlPanel1
71+ pHTML.LoadFromStream(fs);
72+ finally
73+ fs.Free;
74+ end;
75+ IpHtmlPanel1.SetHtml( pHTML );
76+ Caption := IpHtmlPanel1.Title;
77+ except
78+ on E: Exception do begin
79+ MessageDlg( 'Error: '+E.Message, mtError, [mbCancel], 0 );
80+ end;
81+ end;
82+end;
83+```
84+
85+<figure>
86+<img src="component-TSynEdit+TIpHtmlPanel-r.png" title="component-TSynEdit+TIpHtmlPanel-r.png" />
87+<figcaption>component-TSynEdit+TIpHtmlPanel-r.png</figcaption>
88+</figure>
89+
90+---
91+*From the Free Pascal wiki, page "Example-TSynEdit-HTML/fi", as it stood on 2019-09-12 after a change by Djzepi, out of the wiki's dump of 2024-05-26. 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](/wiki-contact).*

Back to history