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
|
{
This example shows, how the the Keywords, Objects and Constants properties of
the class TSynAnySyn can be controlled at runtime.
}
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, SynMemo,
SynHighlighterAny, CheckLst, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
ButtonUncheckAll: TButton;
ButtonCheckAll: TButton;
CheckListBoxConstants: TCheckListBox;
CheckListBoxObjects: TCheckListBox;
CheckListBoxKeys: TCheckListBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
SynAnySyn: TSynAnySyn;
SynMemo: TSynMemo;
procedure ButtonCheckAllClick(Sender: TObject);
procedure ButtonUncheckAllClick(Sender: TObject);
procedure CheckListBoxHandler(Sender: TObject; Index: integer);
private
public
end;
var
Form1: TForm1;
implementation
{$R unit1.lfm}
{ TForm1 }
procedure TForm1.CheckListBoxHandler(Sender: TObject; Index: integer);
var
s: TStrings;
begin
if Sender = CheckListBoxKeys then
s:= SynAnySyn.KeyWords
else if Sender = CheckListBoxObjects then
s:= SynAnySyn.Objects
else
s:= SynAnySyn.Constants;
With Sender As TCheckListBox do begin
if Checked[Index] then
s.Add(Items[Index])
else begin
try
s.Delete(s.IndexOf(Items[Index]));
except
// it is just a demo ;-)
end;
end;
SynMemo.Refresh;
end;
end;
procedure TForm1.ButtonCheckAllClick(Sender: TObject);
var
i: Integer;
begin
for i:= 0 to 3 do begin
CheckListBoxKeys.Checked[i]:= TRUE;
CheckListBoxObjects.Checked[i]:= TRUE;
CheckListBoxConstants.Checked[i]:= TRUE;
end;
SynAnySyn.KeyWords.Clear;
SynAnySyn.KeyWords.Assign(CheckListBoxKeys.Items);
SynAnySyn.Objects.Clear;
SynAnySyn.Objects.Assign(CheckListBoxObjects.Items);
SynAnySyn.Constants.Clear;
SynAnySyn.Constants.Assign(CheckListBoxConstants.Items);
SynMemo.Refresh;
end;
procedure TForm1.ButtonUncheckAllClick(Sender: TObject);
var
i: Integer;
begin
for i:= 0 to 3 do begin
CheckListBoxKeys.Checked[i]:= FALSE;
CheckListBoxObjects.Checked[i]:= FALSE;
CheckListBoxConstants.Checked[i]:= FALSE;
end;
SynAnySyn.KeyWords.Clear;
SynAnySyn.Objects.Clear;
SynAnySyn.Constants.Clear;
SynMemo.Refresh;
end;
end.
|