Example-TSynEdit-HTML/fi: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 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 | 2 | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 3 | + |  | |
| 7 | 4 | ||
| 8 | 5 | ``` pascal | |
| 9 | 6 | unit TipHtmlTest; | |
| 10 | 7 | ||
| 11 | 8 | {$mode objfpc}{$H+} | |
| 12 | 9 | ||
| 13 | 10 | interface | |
| 14 | 11 | ||
| 15 | 12 | uses | |
| 16 | 13 | Classes, SysUtils, FileUtil, IpHtml, SynHighlighterHTML, SynHighlighterAny, | |
| 17 | 14 | SynEdit, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; | |
| 18 | 15 | ||
| 19 | 16 | const | |
| 20 | 17 | htmfile = 'tiphtmltestdata.html'; | |
| 21 | 18 | ||
| 22 | 19 | type | |
| 23 | 20 | TTipHtmlForm = class(TForm) | |
| 24 | 21 | IpHtmlPanel1: TIpHtmlPanel; | |
| 25 | 22 | Splitter1: TSplitter; | |
| 26 | 23 | Memo1: TSynEdit; | |
| 27 | 24 | SynHTMLSyn1: TSynHTMLSyn; | |
| 28 | 25 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); | |
| 29 | 26 | procedure FormCreate(Sender: TObject); | |
| 30 | 27 | procedure MemoChange(Sender: TObject); | |
| 31 | 28 | protected | |
| 32 | 29 | public | |
| 33 | 30 | procedure ShowText( const txt: string ); | |
| 34 | 31 | end; | |
| 35 | 32 | ||
| 36 | 33 | var | |
| 37 | 34 | TipHtmlForm: TTipHtmlForm; | |
| 38 | 35 | ||
| 39 | 36 | implementation | |
| 40 | 37 | ||
| 41 | 38 | {$R *.lfm} | |
| 42 | 39 | ||
| 43 | 40 | procedure TTipHtmlForm.FormCreate(Sender: TObject); | |
| 44 | 41 | begin | |
| 45 | 42 | if FileExists( htmfile ) then | |
| 46 | 43 | Memo1.Lines.LoadFromFile( htmfile ) | |
| 47 | 44 | else | |
| 48 | 45 | Memo1.Lines.Text := '<html><head><title>tipmemo</title></head><body><h1>tipmemo</h1>See <b>' +htmfile + '</b></body></html>'; | |
| 49 | 46 | MemoChange( nil ); | |
| 50 | 47 | end; | |
| 51 | 48 | ||
| 52 | 49 | procedure TTipHtmlForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); | |
| 53 | 50 | begin | |
| 54 | 51 | Memo1.Lines.SaveToFile( htmfile ); | |
| 55 | 52 | end; | |
| 56 | 53 | ||
| 57 | 54 | procedure TTipHtmlForm.MemoChange(Sender: TObject); | |
| 58 | 55 | begin | |
| 59 | 56 | ShowText( Memo1.Lines.Text ); | |
| 60 | 57 | end; | |
| 61 | 58 | ||
| 62 | 59 | procedure TTipHtmlForm.ShowText( const txt: string ); | |
| 63 | 60 | var | |
| 64 | 61 | fs: TStringStream; | |
| 65 | 62 | pHTML: TIpHtml; | |
| 66 | 63 | begin | |
| 67 | 64 | try | |
| 68 | 65 | fs := TStringStream.Create( txt ); | |
| 69 | 66 | try | |
| 70 | 67 | pHTML:=TIpHtml.Create; // Beware: Will be freed automatically by IpHtmlPanel1 | |
| 71 | 68 | pHTML.LoadFromStream(fs); | |
| 72 | 69 | finally | |
| 73 | 70 | fs.Free; | |
| 74 | 71 | end; | |
| 75 | 72 | IpHtmlPanel1.SetHtml( pHTML ); | |
| 76 | 73 | Caption := IpHtmlPanel1.Title; | |
| 77 | 74 | except | |
| 78 | 75 | on E: Exception do begin | |
| 79 | 76 | MessageDlg( 'Error: '+E.Message, mtError, [mbCancel], 0 ); | |
| 80 | 77 | end; | |
| 81 | 78 | end; | |
| 82 | 79 | end; | |
| 83 | 80 | ``` | |
| 84 | 81 | ||
| 85 | - | ||
| 86 | - | ||
| 87 | - | ||
| 88 | - | ||
| 82 | + |  | |
| 89 | 83 | ||
| 90 | 84 | --- | |
| 91 | 85 | *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).* |
