File: synedit1.pas

package info (click to toggle)
lazarus 0.9.28.2-12
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 93,096 kB
  • ctags: 89,312
  • sloc: pascal: 820,189; xml: 202,194; makefile: 110,323; sh: 2,460; perl: 395; sql: 174; ansic: 133
file content (140 lines) | stat: -rw-r--r-- 4,059 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{
 ***************************************************************************
 *                                                                         *
 *   This source is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This code is distributed in the hope that it will be useful, but      *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   A copy of the GNU General Public License is available on the World    *
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 *   obtain it by writing to the Free Software Foundation,                 *
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 *                                                                         *
 ***************************************************************************
}
program synedit1;

{$mode objfpc}{$H+}

uses
  Interfaces, Classes, SysUtils, FileUtil, Forms, Controls, GraphType,
  Graphics, SynEdit, SynHighlighterPas;

type
  TForm1 = class(TForm)
    SynEdit1: TSynEdit;
    PascalHighligher: TSynPasSyn;
    procedure Form1Resize(Sender: TObject);
  private
  public
    procedure LoadDefaultText;
    procedure LoadText(const Filename: string);
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
  end;

{ TForm1 }

procedure TForm1.Form1Resize(Sender: TObject);
begin
  with SynEdit1 do
    SetBounds(10,10,Parent.ClientWidth-10,Parent.ClientHeight-20);
end;

procedure TForm1.LoadDefaultText;
var
  E: String;
begin
  E:=#13#10;
  SynEdit1.Lines.Text:=
    '{'+e+
    '  SynEdit Test'+e+
    '}'+e+
    'program synedit1;'+e+
    ''+e+
    '{$mode objfpc}{$H+}'+e+
    ''+e+
    'uses'+e+
    '  Interfaces, Classes, SysUtils, Forms, Controls, GraphType, Graphics, SynEdit,'+e+
    '  SynHighlighterPas;'+e+
    ''+e+
    'type'+e+
    '  TForm1 = class(TForm)'+e+
    '    SynEdit1: TSynEdit;'+e+
    '    PascalHighligher: TSynPasSyn;'+e+
    '    procedure Form1Resize(Sender: TObject);'+e+
    '  private'+e+
    '  public'+e+
    '    procedure LoadDefaultText;'+e+
    '    procedure LoadText(const Filename: string);'+e+
    '    constructor Create(TheOwner: TComponent); override;'+e+
    '    destructor Destroy; override;'+e+
    '  end;'+e+
    ''+e+
    '{ TForm1 }'+e+
    ''+e+
    'procedure TForm1.Form1Resize(Sender: TObject);'+e+
    'begin'+e+
    '  with SynEdit1 do'+e+
    '    SetBounds(10,10,Parent.ClientWidth-10,Parent.ClientHeight-20);'+e+
    'end;'+e+
    ''+e+
    'end.'+e;
end;

procedure TForm1.LoadText(const Filename: string);
begin
  SynEdit1.Lines.LoadFromFile(Filename);
end;

constructor TForm1.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  SetBounds(10,20,980,700);
  OnResize:=@Form1Resize;
  
  SynEdit1:=TSynEdit.Create(Self);
  with SynEdit1 do begin
    Name:='SynEdit1';
    Parent:=Self;
  end;
  
  PascalHighligher:=TSynPasSyn.Create(Self);
  with PascalHighligher do begin
    Name:='PascalHighligher';
    CommentAttri.Foreground:=clBlue;
    CommentAttri.Style:=[fsBold];
    KeyAttri.Style:=[fsBold];
    StringAttri.Foreground:=clBlue;
    SymbolAttri.Foreground:=clRed;
  end;
  
  SynEdit1.Highlighter:=PascalHighligher;
 
  if ParamCount > 0 then
    LoadText(ParamStrUTF8(1))
  else
    LoadDefaultText;
  OnResize(nil);
end;

destructor TForm1.Destroy;
begin
  inherited Destroy;
end;

var
  Form1: TForm1;

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.