Recent

Author Topic: SynFacilCompletion highlighter  (Read 18075 times)

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: SynFacilCompletion highlighter
« Reply #15 on: December 31, 2017, 04:37:19 am »
The explanation is There is not exist the attribute DIRECTIVE by default in SynFacilSyn (and SynFacilCompletion). You need to define when using.

Maybe a better error control must be included.   :-[

EDIT:
A better error control has been included in https://github.com/t-edson/SynFacilSyn
« Last Edit: December 31, 2017, 04:50:01 am by Edson »
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #16 on: December 31, 2017, 06:19:48 am »
Спасибо большое постараюсь разобраться! Но мне так и не понятно почему символ "#" вызывает ошибку?
Попробуйте просто открыть файл вписать только 1 символ # приложение при открытие такого го файла с символом вызывает ошибку.

¡Gracias grande trataré de comprender! ¿Pero y no me está claro por qué el símbolo "#" llama la falta?
Prueben simplemente abrir el fichero insertar solamente 1 símbolo # la aplicación a la apertura de tal го del fichero con el símbolo llama la falta.

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #17 on: December 31, 2017, 08:00:34 am »
The explanation is There is not exist the attribute DIRECTIVE by default in SynFacilSyn (and SynFacilCompletion). You need to define when using.

Maybe a better error control must be included.   :-[

EDIT:
A better error control has been included in https://github.com/t-edson/SynFacilSyn

Спасибо большое за ваш труд!! С наступающим 2018 годом!
And thank you for your work!! With the upcoming 2018!

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #18 on: December 31, 2017, 08:06:01 am »
I can see. But the only problem I detect is in the definition of DIRECTIVES, no about the file size.

It seems to be a bug. I need to check it more.

By the moment, you can avoid the crash, including the definition of the attribute DIRECTIVE in the XML file:

Code: XML  [Select][+][-]
  1.    <Attribute Name="DIRECTIVE" ForeCol="#a1a130"></Attribute>
  2.  

And for a better highlighter, modify the definition for DIRECTIVES:

Code: XML  [Select][+][-]
  1.   <Token Start="#" End="" Attribute='DIRECTIVE'> </Token>
  2.  

Это помогло Ура!!
It helped Cheers!! O:-)
« Last Edit: December 31, 2017, 08:10:41 am by BIT »

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: SynFacilCompletion highlighter
« Reply #19 on: December 31, 2017, 03:53:04 pm »
Спасибо большое постараюсь разобраться! Но мне так и не понятно почему символ "#" вызывает ошибку?
Попробуйте просто открыть файл вписать только 1 символ # приложение при открытие такого го файла с символом вызывает ошибку.

It's because the token definition for "#" is using the attribute DIRECTIVE and it's not defined in the XML syntax.

Спасибо большое за ваш труд!! С наступающим 2018 годом!
And thank you for your work!! With the upcoming 2018!

You're welcome.

счастливый новый год 2018, Feliz Año Nuevo 2018.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #20 on: December 31, 2017, 06:23:49 pm »
Спасибо большое постараюсь разобраться! Но мне так и не понятно почему символ "#" вызывает ошибку?
Попробуйте просто открыть файл вписать только 1 символ # приложение при открытие такого го файла с символом вызывает ошибку.

It's because the token definition for "#" is using the attribute DIRECTIVE and it's not defined in the XML syntax.

Спасибо большое за ваш труд!! С наступающим 2018 годом!
And thank you for your work!! With the upcoming 2018!

You're welcome.

счастливый новый год 2018, Feliz Año Nuevo 2018.

Еще нашел ошибку если создавать динамически SynEdit и ваш компонент при удаление наборного текст происходит ошибка
Even found a bug if you create dynamically and your SynEdit component in the removal of stacked text error occurs

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #21 on: December 31, 2017, 08:44:58 pm »
Не знаю за что отвечает но я закомментировал строку и ошибка пропала))))
I do not know what is responsible but I have commented out the line and the error was gone))))

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: SynFacilCompletion highlighter
« Reply #22 on: December 31, 2017, 10:34:41 pm »
Не знаю за что отвечает но я закомментировал строку и ошибка пропала))))
I do not know what is responsible but I have commented out the line and the error was gone))))
no you it did not you simple silenced it. Never ever ever edit the lcl units unles you know what you are doing and why. provide an example that raises the problem and we will tell you what you did wrong.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #23 on: December 31, 2017, 11:07:48 pm »
Не знаю за что отвечает но я закомментировал строку и ошибка пропала))))
I do not know what is responsible but I have commented out the line and the error was gone))))
no you it did not you simple silenced it. Never ever ever edit the lcl units unles you know what you are doing and why. provide an example that raises the problem and we will tell you what you did wrong.

Code: Pascal  [Select][+][-]
  1.   private
  2.  
  3.   public
  4.     //Вывод каталога в TreeView1
  5.     procedure FilePathToTreeNode(aTreeView: TTreeView; aRoot: TTreeNode;
  6.       Path: string; Recurse: boolean);
  7.     //Запись в INI
  8.     procedure INIWrite(FileName: string; Section: string; Key: string; Param: string);
  9.     //Чтение из INI
  10.     function INIRead(FileName: string; Section: string; Key: string;
  11.       Param: string): string;
  12.     //Создание вкладка
  13.     function NewTab(TabCaption: string): boolean;
  14.     //Команды выполнения для компонента TSynEdit и PageControl1
  15.     procedure SynEditComadeTab(Comade, Param: string);
  16.     //SynFacilComplet
  17.     procedure rKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
  18.     //SynFacilComplet
  19.     procedure rUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
  20.     //Загрузить компоненты из катологка
  21.     procedure LoadComponent();
  22.     procedure rToolButtonClick(Sender: TObject);
  23.   end;
  24.  
  25.  
  26. var
  27.   Form1: TForm1;
  28.   IniF: TINIFile;// Класс для работы с INI-файлами
  29.   {Создание вкладки с TSynEdit}
  30.   hlt: TSynFacilComplet;
  31.   Tab: TTabSheet;
  32.   rSynEdit: TSynEdit;
  33.  
  34.   {TreeView Добовляем интемы при открытие файла}
  35.   TreeViewObject: TStringList;
  36.   i: integer;
  37.   ProjectDir: string;
  38.  
  39. implementation
  40.  
  41. {$R *.lfm}
  42.  
  43. { TForm1 }
  44.  
  45. //Откроем проект через диалог - Вызываем функцию  Вывод каталога в TreeView1
  46. procedure TForm1.ToolButton1Click(Sender: TObject);
  47. begin
  48.   MenuItem12.Click;
  49. end;
  50. //Сохранить
  51. procedure TForm1.ToolButton3Click(Sender: TObject);
  52. begin
  53.   MenuItem13.Click;
  54. end;
  55.  
  56. procedure TForm1.ToolButton5Click(Sender: TObject);
  57. var
  58.   CompilT: CompilThread;
  59. begin
  60.   if GroupBox1.Visible = False then
  61.   begin
  62.     GroupBox1.Visible := True;
  63.     MenuItem10.Checked := True;
  64.   end;
  65.   Form1.SynEdit1.Color := clWhite;
  66.   MenuItem12.Enabled := False;
  67.   CompilT := CompilThread.Create(True);
  68.   CompilT.FreeOnTerminate := True;
  69.   CompilT.Priority := tpnormal;
  70.  
  71.   CompilT.Start;
  72.  
  73. end;
  74. //Отмена
  75. procedure TForm1.ToolButton7Click(Sender: TObject);
  76. begin
  77.   SynEditComadeTab('Undo', '');
  78. end;
  79. //Вернуть
  80. procedure TForm1.ToolButton8Click(Sender: TObject);
  81. begin
  82.   SynEditComadeTab('Redo', '');
  83. end;
  84.  
  85. procedure TForm1.FormCreate(Sender: TObject);
  86. begin
  87.  
  88.   //Загрузим настроки из INI приложения при старте программы
  89.   Form1.Width := StrToInt(INIRead('Otions.ini', 'Form', 'Form1.Width',
  90.     IntToStr(Form1.Width)));
  91.   Form1.Height := StrToInt(INIRead('Otions.ini', 'Form', 'Form1.Height',
  92.     IntToStr(Form1.Height)));
  93.   Form1.Left := StrToInt(INIRead('Otions.ini', 'Form', 'Form1.Left',
  94.     IntToStr(Form1.Left)));
  95.   Form1.Top := StrToInt(INIRead('Otions.ini', 'Form', 'Form1.Top', IntToStr(Form1.Top)));
  96.  
  97.   {Свойста проекта}
  98.   //Запускать ли игру Fals True
  99.   ValueListEditor1.Strings[0] := ('Запускать L.exe=True');
  100.   // ValueListEditor1.ItemProps[0].EditStyle:= esPickList;
  101.   ValueListEditor1.ItemProps[0].PickList.Add('True');
  102.   ValueListEditor1.ItemProps[0].PickList.Add('False');
  103.  
  104.   //Путь до игры
  105.   ValueListEditor1.ItemProps[1].EditStyle := esEllipsis;
  106.   ValueListEditor1.ItemProps[1].ReadOnly := True;
  107.  
  108.   //Загрузить настройки проекта при старте
  109.   ValueListEditor1.Strings[1] := ('Путь к L.exe=');
  110.  
  111.   ValueListEditor1.Refresh;
  112.   ValueListEditor1.AutoSizeColumn(0);
  113.  
  114. end;
  115.  
  116. procedure TForm1.FormDestroy(Sender: TObject);
  117. begin
  118.  
  119.     hlt.UnSelectEditor;   //release editor (only necessary if we are to call to SelectEditor(), again)
  120.   hlt.Free;  //destroy the highlighter
  121. end;
  122.  
  123. procedure TForm1.FormShow(Sender: TObject);
  124. begin
  125.   LoadComponent(); // загрузка компонентов
  126. end;
  127.  
  128. //Откроем проект через диалог - Вызываем функцию  Вывод каталога в TreeView1
  129. procedure TForm1.MenuItem12Click(Sender: TObject);
  130. var
  131.   g: integer;
  132. begin
  133.  
  134.   if OpenDialog1.Execute then
  135.     // if ExtractFileName(OpenDialog1.FileName) = 'Projects.luse' then
  136.   begin
  137.     TreeViewObject := TStringList.Create;
  138.  
  139.     for i := 0 to TreeViewObject.Count - 1 do
  140.     begin
  141.       if TreeView1.Items.Item[i].Data <> nil then
  142.         Dispose(PString(TreeView1.Items.Item[i].Data));
  143.     end;
  144.     TreeView1.Items.Clear;
  145.     FilePathToTreeNode(TreeView1, nil, ExtractFileDir(OpenDialog1.FileName) +
  146.       '\', True);
  147.     with TStringList.Create do
  148.     begin
  149.       LoadFromFile(OpenDialog1.FileName);
  150.       for g := 0 to Count - 1 do
  151.         ValueListEditor1.Cells[1, g + 1] := Strings[g];
  152.  
  153.     end;
  154.     ProjectDir := ExtractFileDir(OpenDialog1.FileName);
  155.  
  156.   end;
  157.  
  158. end;
  159. //Сохранить в файл Активный  SynEdit
  160. procedure TForm1.MenuItem13Click(Sender: TObject);
  161. begin
  162.   SynEditComadeTab('SaveFile', '');
  163. end;
  164.  
  165. //Закрыть вкладку
  166. procedure TForm1.MenuItem16Click(Sender: TObject);
  167. begin
  168.   SynEditComadeTab('CloseTab', '');
  169. end;
  170. //Удалить файл
  171. procedure TForm1.MenuItem21Click(Sender: TObject);
  172. begin
  173.   DeleteFile(string(TreeView1.Selected.Data));
  174.   TreeView1.Selected.Free;
  175. end;
  176. //Копировать
  177. procedure TForm1.MenuItem22Click(Sender: TObject);
  178. begin
  179.   SynEditComadeTab('Copy', '');
  180. end;
  181. //Вставить
  182. procedure TForm1.MenuItem23Click(Sender: TObject);
  183. begin
  184.   SynEditComadeTab('Paste', '');
  185. end;
  186. //Выделить все
  187. procedure TForm1.MenuItem24Click(Sender: TObject);
  188. begin
  189.   SynEditComadeTab('SelectAll', '');
  190. end;
  191. //Удалить выделеное
  192. procedure TForm1.MenuItem25Click(Sender: TObject);
  193. begin
  194.   SynEditComadeTab('ClearSelection', '');
  195. end;
  196.  
  197. procedure TForm1.MenuItem26Click(Sender: TObject);
  198. begin
  199.   Form2.ShowModal;
  200. end;
  201.  
  202. procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean
  203.   );
  204. begin
  205.   //(PageControl1.ActivePage.FindComponent('syed' +
  206.   //  IntToStr(PageControl1.ActivePageIndex + 1)) as TSynEdit).SetFocus;
  207. end;
  208.  
  209. procedure TForm1.PageControl1MouseDown(Sender: TObject; Button: TMouseButton;
  210.   Shift: TShiftState; X, Y: integer);
  211. var
  212.   SelectPoint: TPoint;
  213. begin
  214.   //Смысл в том, что хотим выделить таб, при нажатии на нем правой клавишей мыши (вызов меню)
  215.   SelectPoint.x := X;
  216.   SelectPoint.y := Y;
  217.   PageControl1.ActivePageIndex := PageControl1.IndexOfPageAt(SelectPoint);
  218.  
  219. end;
  220.  
  221. procedure TForm1.SynEdit1DblClick(Sender: TObject);
  222. begin
  223.     if (Trim(ExtractWord(1, SynEdit1.LineText, ['|'])) = 'Просмотр') then
  224.   begin
  225.      if PageControl1.PageCount > 0 then
  226.   for i:=0 to PageControl1.PageCount-1 do
  227.     if Trim(ExtractWord(2, SynEdit1.LineText, ['|', '('])) = Trim(PageControl1.Page[i].Hint) then
  228.     begin
  229.      PageControl1.ActivePageIndex:=i;
  230.        SynEditComadeTab('LineIndex', Trim(ExtractWord(2, SynEdit1.LineText, ['(', ')'])));
  231.    exit;
  232.     end;
  233.       if (NewTab(ExtractFileName(Trim(ExtractWord(2, SynEdit1.LineText, ['|', '('])))) =
  234.     True) then
  235.      begin
  236.     // ShowMessage(Trim(ExtractWord(2, SynEdit1.LineText, ['|','(']))); //Путь до файла
  237.     //  ShowMessage(Trim(ExtractWord(2, SynEdit1.LineText, ['(',')']))); //Номер строки
  238.     SynEditComadeTab('Hint', Trim(ExtractWord(2, SynEdit1.LineText, ['|', '('])));
  239.     SynEditComadeTab('LoadFile', Trim(ExtractWord(2, SynEdit1.LineText, ['|', '('])));
  240.       SynEditComadeTab('LineIndex', Trim(ExtractWord(2, SynEdit1.LineText, ['(', ')'])));
  241.   end;
  242.  
  243.   end;
  244. end;
  245.  
  246. // Расцветка лога
  247. procedure TForm1.SynEdit1SpecialLineColors(Sender: TObject; Line: integer;
  248.   var Special: boolean; var FG, BG: TColor);
  249.  
  250. begin
  251.   if ((line mod 1) = 0) and (SynEdit1.Lines[0] = 'Готово!') then
  252.   begin
  253.     Special := True;
  254.     BG := $0072F968;
  255.   end;
  256.   if ((line mod 1) = 0) and (SynEdit1.Lines[0] =
  257.     'Компиляция проекта: ...') then
  258.   begin
  259.     Special := True;
  260.     BG := clYellow;
  261.   end;
  262.   if ((line mod 1) = 0) and (SynEdit1.Lines[0] = 'Запуск игры...') then
  263.   begin
  264.     Special := True;
  265.     BG := clAqua;
  266.   end;
  267.  
  268.   if ((line mod 1) = 0) and (SynEdit1.Lines[0] =
  269.     'Файл скомпилирован но путь к игре не найден!')
  270.   then
  271.   begin
  272.     Special := True;
  273.     BG := $0072F968;
  274.   end;
  275. end;
  276.  
  277. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  278. begin
  279.   //Сохранить настроки в INI приложения при закрытие программы
  280.   INIWrite('Otions.ini', 'Form', 'Form1.Width', IntToStr(Form1.Width));
  281.   INIWrite('Otions.ini', 'Form', 'Form1.Height', IntToStr(Form1.Height));
  282.   INIWrite('Otions.ini', 'Form', 'Form1.Left', IntToStr(Form1.Left));
  283.   INIWrite('Otions.ini', 'Form', 'Form1.Top', IntToStr(Form1.Top));
  284. end;
  285.  
  286. procedure TForm1.TreeView1DblClick(Sender: TObject);
  287. var
  288.   i:integer;
  289. begin
  290.   // ShowMessage(string(TreeView1.Selected.Data));
  291.   {При клике на элемент в  TreeView1 загрузить файл в таб}
  292.  
  293.     if PageControl1.PageCount > 0 then
  294.   for i:=0 to PageControl1.PageCount-1 do
  295.  
  296.     if string(TreeView1.Selected.Data) = PageControl1.Page[i].Hint then
  297.     begin
  298.      PageControl1.ActivePageIndex:=i;
  299.    exit;
  300.     end;
  301.  
  302.   if (ExtractFileExt(string(TreeView1.Selected.Data)) > '') and
  303.     (NewTab(ExtractFileName(string(TreeView1.Selected.Data))) = True) then
  304.   begin
  305.  
  306.     SynEditComadeTab('Hint', string(TreeView1.Selected.Data));
  307.     SynEditComadeTab('LoadFile', string(TreeView1.Selected.Data));
  308.  
  309.  
  310.   end;
  311.  
  312. end;
  313. //Указать путь к игре в редакторе проета
  314. procedure TForm1.ValueListEditor1ButtonClick(Sender: TObject; aCol, aRow: integer);
  315. begin
  316.   if aCol = 1 then
  317.     if OpenDialog1.Execute then
  318.       if ExtractFileName(OpenDialog1.FileName) = 'L.exe' then
  319.         ValueListEditor1.Strings[1] := ('Путь к L.exe=' + OpenDialog1.FileName);
  320. end;
  321. //Вывод каталога в TreeView1 Пример:
  322. //FilePathToTreeNode(TreeView1, nil, 'Папка' + '\', True);
  323. procedure TForm1.FilePathToTreeNode(aTreeView: TTreeView; aRoot: TTreeNode;
  324.   Path: string; Recurse: boolean);
  325. var
  326.   NewNode: TTreeNode;
  327.   SRec: TSearchRec;
  328. begin
  329.  
  330.   if FindFirst(Path + '*.*', SysUtils.faAnyFile, SRec) = 0 then
  331.     repeat
  332.       if (sRec.Name = '.') or (sRec.Name = '..') then
  333.         Continue;
  334.       // if SRec.Name <> 'Projects.luse' then
  335.       //Не отоброжаем фай конфигурации
  336.       begin
  337.  
  338.         TreeViewObject.Add(PChar(Path + srec.Name));
  339.  
  340.         NewNode := aTreeView.Items.AddChildObject(aRoot, SRec.Name,
  341.           PChar(TreeViewObject.Strings[i]));
  342.         Inc(i);
  343.       end;
  344.       if Recurse and ((srec.Attr and SysUtils.faDirectory) <> 0) then
  345.       begin
  346.  
  347.         FilePathToTreeNode(aTreeView, NewNode, Path + srec.Name + '\', True);
  348.  
  349.  
  350.         //папка
  351.         NewNode.ImageIndex := 1108;
  352.         NewNode.SelectedIndex := 1108;
  353.  
  354.       end
  355.       else
  356.       begin
  357.  
  358.         // ShowMessage(PChar(NewNode.Data));
  359.         //Файл
  360.         NewNode.ImageIndex := 804;
  361.         NewNode.SelectedIndex := 785;
  362.       end;
  363.  
  364.  
  365.     until FindNext(SRec) <> 0;
  366.   FindClose(SRec);
  367. end;
  368. //Запись в INI Пример:
  369. //INIWrite('Otions.ini','Section', 'Key','тест');
  370. procedure TForm1.INIWrite(FileName: string; Section: string; Key: string;
  371.   Param: string);
  372. begin
  373.   if (FileExists(FileName)) then
  374.   begin
  375.     Inif := TINIFile.Create(FileName);
  376.     INiF.WriteString(Section, Key, Param);
  377.   end;
  378. end;
  379. //Чтение из INI Пример:
  380. //INIRead('Otions.ini','Section', 'Key','тест');
  381. function TForm1.INIRead(FileName: string; Section: string; Key: string;
  382.   Param: string): string;
  383. begin
  384.   if (FileExists(FileName)) then
  385.   begin
  386.     Inif := TINIFile.Create(FileName);
  387.     Result := INiF.ReadString(Section, Key, Param);
  388.   end;
  389. end;
  390. //Создание вкладки
  391. function TForm1.NewTab(TabCaption: string): boolean;
  392. begin
  393.   Tab := TTabSheet.Create(Self);
  394.   Tab.PageControl := PageControl1;
  395.   Tab.Caption := TabCaption;
  396.   Tab.PageControl.ActivePage := Tab;
  397.   Tab.Visible := False;
  398.  
  399.   rSynEdit := TSynEdit.Create(Tab);
  400.   rSynEdit.Parent := Tab;
  401.   rSynEdit.Align := alClient;
  402.   rSynEdit.OnUTF8KeyPress := @rUTF8KeyPress;
  403.   rSynEdit.OnKeyUp := @rKeyUp;
  404.   rSynEdit.RightEdge := 0;
  405.   rSynEdit.BorderStyle := bsNone;
  406.   rSynEdit.Color := clWhite;
  407.   rSynEdit.Font := SynEdit1.Font;
  408.   rSynEdit.MouseOptions := SynEdit1.MouseOptions;
  409.   rSynEdit.Options := SynEdit1.Options;
  410.   rSynEdit.Options2 := SynEdit1.Options2;
  411.   rSynEdit.Text := 'class NameClass' + IntToStr(PageControl1.PageCount) +
  412.     ' extends UICommonAPI;' + #13#13#13 + 'defaultproperties{}';
  413.   rSynEdit.Name := 'syed' + IntToStr(PageControl1.PageCount);
  414.   rSynEdit.PopupMenu := PopupMenu3;
  415.   SynPluginSyncroEdit1.Editor := rSynEdit;
  416.  
  417.   //configure highlighter
  418.   hlt := TSynFacilComplet.Create(Self);  //my highlighter
  419.   rSynEdit.Highlighter := hlt;  //optional if we are going to use SelectEditor()
  420.   hlt.LoadFromFile('UnrealScript.xml');  //load syntax
  421.   hlt.SelectEditor(rSynEdit);  //assign to editor
  422.   hlt.IconList := ImageList1;
  423.  
  424.   Result := True;
  425.    Tab.Visible := True;
  426. end;
  427. //Команды выполнения для компонента TSynEdit и PageControl1
  428. procedure TForm1.SynEditComadeTab(Comade, Param: string);
  429. var
  430.   syed: TSynEdit;
  431.  
  432.   x1, x2: integer;
  433. begin
  434.  
  435.   syed := (PageControl1.ActivePage.FindComponent('syed' +
  436.     IntToStr(PageControl1.ActivePageIndex + 1)) as TSynEdit);
  437.  
  438.   case Comade of
  439.     'Hint': PageControl1.ActivePage.Hint := Param; //Тут хранится путь к файлу
  440.     'Text': syed.Text := Param; //Загрузим текст
  441.     //Загрузим текст из файла
  442.     'LoadFile': syed.Lines.LoadFromFile(UTF8ToSys(Param));
  443.     //Сохраним текст в файл
  444.     'SaveFile': syed.Lines.SaveToFile(UTF8ToSys(PageControl1.ActivePage.Hint));
  445.     //Вставить текст в позицию курсора
  446.     'SelText': syed.SelText := Param;
  447.     //Перейти на Index строки
  448.     'LineIndex':
  449.     begin
  450.       syed.TopLine := StrToInt(Param);
  451.       //ShowMessage(Trim(syed.Lines[StrToInt(Param) - 1]));
  452.  
  453.       x1 := PosEx(Trim(syed.Lines[StrToInt(Param)]), Trim(syed.Text));
  454.       x2 := PosEx(Trim(syed.Lines[StrToInt(Param)]), Trim(syed.Text)) +
  455.         length(Trim(syed.Lines[StrToInt(Param)]));
  456.       syed.SelStart := x1;
  457.       syed.SelEnd := x2;
  458.  
  459.     end;
  460.     //Копировать
  461.     'Copy': syed.CopyToClipboard;
  462.     //Вставить
  463.     'Paste': syed.PasteFromClipboard;
  464.     //Вырезать
  465.     'Cut': syed.CutToClipboard;
  466.     //Выделить все
  467.     'SelectAll': syed.SelectAll;
  468.     //Удалить выделеное
  469.     'ClearSelection': syed.ClearSelection;
  470.     //Отмена
  471.     'Undo': syed.Undo;
  472.     //Вернуть
  473.     'Redo': syed.Redo;
  474.     ////Проверить существует ли TAB с таким файлом
  475.     //'EatTab': for PageControl1.TabIndex-1;
  476.     //Закрыть активную вкладку
  477.     'CloseTab': PageControl1.ActivePage.Free;
  478.  
  479.  
  480.     else
  481.       ShowMessage(Comade + 'Comade Не известнена!');
  482.   end;
  483.  
  484. end;
  485. //SynFacilComplet
  486. procedure TForm1.rKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
  487. begin
  488.   sleep(10);
  489.  hlt.KeyUp(Sender, Key, Shift);
  490.  
  491. end;
  492. //SynFacilComplet
  493. procedure TForm1.rUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
  494. begin
  495.   hlt.UTF8KeyPress(Sender, UTF8Key);
  496.  
  497. end;
  498. //Загрузить компоненты
  499. procedure TForm1.LoadComponent();
  500. var
  501.   Pic: TPortableNetworkGraphic;
  502.   i: integer;
  503.   PascalFiles, FilePathComponent: TStringList;
  504. begin
  505.   PascalFiles := TStringList.Create;
  506.   FilePathComponent := TStringList.Create;
  507.   try
  508.     FindAllFiles(PascalFiles, 'components', '*.lc', True);
  509.     //ShowMessage(PascalFiles.Text);
  510.     // ... тут читаем файл в StringList:
  511.  
  512.     for i := 0 to PascalFiles.Count - 1 do
  513.     begin
  514.       ToolBar2.ButtonList.Add(TToolButton.Create(Self));
  515.       //Ico:= TIcon.Create;
  516.       FilePathComponent.LoadFromFile(PascalFiles.Strings[i]);
  517.       Pic := TPortableNetworkGraphic.Create;
  518.       if FileExists(ExtractFilePath(PascalFiles.Strings[i]) + 'icon.png') = True then
  519.       begin
  520.         Pic.LoadFromFile(ExtractFilePath(PascalFiles.Strings[i]) + 'icon.png');
  521.         ImageList2.Add(Pic, nil);
  522.         //ShowMessage(ExtractFilePath(PascalFiles.Strings[i]) + '\icon.png');
  523.         ToolBar2.Buttons[ToolBar2.ButtonCount - 1].Hint := FilePathComponent.Strings[0];
  524.         ToolBar2.Buttons[ToolBar2.ButtonCount - 1].Caption := PascalFiles.Strings[i];
  525.         ToolBar2.Buttons[ToolBar2.ButtonCount - 1].Parent := ToolBar2;
  526.         ToolBar2.Images := ImageList2;
  527.         ToolBar2.Buttons[ToolBar2.ButtonCount - 1].ImageIndex := i;
  528.         ToolBar2.Buttons[ToolBar2.ButtonCount - 1].OnClick := @rToolButtonClick;
  529.       end;
  530.     end;
  531.   finally
  532.     PascalFiles.Free;
  533.     FilePathComponent.Free;
  534.     Pic.Free;
  535.   end;
  536. end;
  537.  
  538. procedure TForm1.rToolButtonClick(Sender: TObject);
  539. var
  540.   FilePathComponent: TStringList;
  541. begin
  542.   if PageControl1.ControlCount <> 0 then
  543.   begin
  544.     FilePathComponent := TStringList.Create;
  545.     FilePathComponent.LoadFromFile((Sender as TToolButton).Caption);
  546.     FilePathComponent.Strings[0] := '';
  547.     SynEditComadeTab('SelText', FilePathComponent.Text);
  548.  
  549.     FilePathComponent.Free;
  550.  
  551.   end;
  552. end;
  553.  
  554. end.    
« Last Edit: December 31, 2017, 11:22:53 pm by BIT »

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #24 on: December 31, 2017, 11:27:10 pm »
Не знаю за что отвечает но я закомментировал строку и ошибка пропала))))
I do not know what is responsible but I have commented out the line and the error was gone))))
no you it did not you simple silenced it. Never ever ever edit the lcl units unles you know what you are doing and why. provide an example that raises the problem and we will tell you what you did wrong.
Если я только мог допустить ошибку при создания компонента возможно что то указал в не правильной подследственности
If I only could make a mistake when you create a component it is possible that it is pointed in the right jurisdiction
Code: Pascal  [Select][+][-]
  1. //Создание вкладки
  2. function TForm1.NewTab(TabCaption: string): boolean;
  3. begin
  4.   Tab := TTabSheet.Create(Self);
  5.   Tab.PageControl := PageControl1;
  6.   Tab.Caption := TabCaption;
  7.   Tab.PageControl.ActivePage := Tab;
  8.   Tab.Visible := False;
  9.  
  10.   rSynEdit := TSynEdit.Create(Tab);
  11.   rSynEdit.Parent := Tab;
  12.   rSynEdit.Align := alClient;
  13.   rSynEdit.OnUTF8KeyPress := @rUTF8KeyPress;
  14.   rSynEdit.OnKeyUp := @rKeyUp;
  15.   rSynEdit.RightEdge := 0;
  16.   rSynEdit.BorderStyle := bsNone;
  17.   rSynEdit.Color := clWhite;
  18.   rSynEdit.Font := SynEdit1.Font;
  19.   rSynEdit.MouseOptions := SynEdit1.MouseOptions;
  20.   rSynEdit.Options := SynEdit1.Options;
  21.   rSynEdit.Options2 := SynEdit1.Options2;
  22.   rSynEdit.Text := 'class NameClass' + IntToStr(PageControl1.PageCount) +
  23.     ' extends UICommonAPI;' + #13#13#13 + 'defaultproperties{}';
  24.   rSynEdit.Name := 'syed' + IntToStr(PageControl1.PageCount);
  25.   rSynEdit.PopupMenu := PopupMenu3;
  26.   SynPluginSyncroEdit1.Editor := rSynEdit;
  27.  
  28.   //configure highlighter
  29.   hlt := TSynFacilComplet.Create(Self);  //my highlighter
  30.   rSynEdit.Highlighter := hlt;  //optional if we are going to use SelectEditor()
  31.   hlt.LoadFromFile('UnrealScript.xml');  //load syntax
  32.   hlt.SelectEditor(rSynEdit);  //assign to editor
  33.   hlt.IconList := ImageList1;
  34.  
  35.   Result := True;
  36.    Tab.Visible := True;
  37. end;                

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #25 on: January 01, 2018, 10:22:18 am »
Еще ошибка достала после завершения программы в Lazaruse ))

Still got error after program Lazaruse ))

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: SynFacilCompletion highlighter
« Reply #26 on: January 02, 2018, 04:38:38 am »
Hi. Would you please attach the project to review?
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #27 on: January 02, 2018, 07:49:15 am »
Hi. Would you please attach the project to review?

Прошлый раз с Яндекса не качалось положил исходник на  диск google
Last time Yandex was not swayed put the source code on google drive

https://drive.google.com/file/d/1dxSTTczP4QZIYd_gsMFsktH9NjLRQYKC/view?usp=sharing

PS: Этот проект черновик много того что не реализовано но для выявления ошибок достаточно!
PS: The draft the draft a lot of that but not implemented to detect errors enough!

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: SynFacilCompletion highlighter
« Reply #28 on: January 03, 2018, 02:47:45 am »
The problem I see is you create dinamically a SynEdit and a Highlighter:

Code: Pascal  [Select][+][-]
  1. function TForm1.NewTab(TabCaption: string): boolean;
  2. begin
  3.   ...
  4.   rSynEdit := TSynEdit.Create(Tab);
  5.   rSynEdit.Parent := Tab;
  6.   ...
  7.   hlt := TSynFacilComplet.Create(Self);  //my highlighter
  8.   rSynEdit.Highlighter := hlt;  //optional if we are going to use SelectEditor()
  9.   ...
  10. end;

But you only destroy a highlighter using the global variable hlt:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDestroy(Sender: TObject);
  2. begin
  3.   hlt.UnSelectEditor;   //release editor (only necessary if we are to call to SelectEditor(), again)
  4.   hlt.Free;  //destroy the highlighter
  5. end;
  6.  

Logically if you create several highlighters, you need to destroy each one. The SynEdit is destroyed because have a parent so no need to destroy manually.

The quick solution is just to comment the lines:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDestroy(Sender: TObject);
  2. begin
  3.   //hlt.UnSelectEditor;   //release editor (only necessary if we are to call to SelectEditor(), again)
  4.   //hlt.Free;  //destroy the highlighter
  5. end;
  6.  

This will leave some leaks but will work.

The best solution is to implement a routine to Free the highlighter every time a SynEdit is destroyed.

Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

BIT

  • Full Member
  • ***
  • Posts: 158
Re: SynFacilCompletion highlighter
« Reply #29 on: January 03, 2018, 08:10:47 am »
The problem I see is you create dinamically a SynEdit and a Highlighter:

Code: Pascal  [Select][+][-]
  1. function TForm1.NewTab(TabCaption: string): boolean;
  2. begin
  3.   ...
  4.   rSynEdit := TSynEdit.Create(Tab);
  5.   rSynEdit.Parent := Tab;
  6.   ...
  7.   hlt := TSynFacilComplet.Create(Self);  //my highlighter
  8.   rSynEdit.Highlighter := hlt;  //optional if we are going to use SelectEditor()
  9.   ...
  10. end;

But you only destroy a highlighter using the global variable hlt:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDestroy(Sender: TObject);
  2. begin
  3.   hlt.UnSelectEditor;   //release editor (only necessary if we are to call to SelectEditor(), again)
  4.   hlt.Free;  //destroy the highlighter
  5. end;
  6.  

Logically if you create several highlighters, you need to destroy each one. The SynEdit is destroyed because have a parent so no need to destroy manually.

The quick solution is just to comment the lines:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDestroy(Sender: TObject);
  2. begin
  3.   //hlt.UnSelectEditor;   //release editor (only necessary if we are to call to SelectEditor(), again)
  4.   //hlt.Free;  //destroy the highlighter
  5. end;
  6.  

This will leave some leaks but will work.

The best solution is to implement a routine to Free the highlighter every time a SynEdit is destroyed.

С этим понятно!

Меня больше интересует этот вопрос с ошибкой.
Возможно я не понятно объяснил что происходит. При наборе текста в SynEdit через некоторое время происходит ошибка которая на картинки.
Если отключить   hlt.KeyUp(Sender, Key, Shift);   и   hlt.UTF8KeyPress(Sender, UTF8Key);    Все работает отлично никаких ошибок подсветка работает.

With this clear!

I'm more interested in this question with the error.
I may not have clearly explained what was going on. When typing text in the SynEdit after some time an error occurs which pictures.
If you disable hlt.KeyUp(Sender, Key, Shift); and hlt.UTF8KeyPress(Sender, UTF8Key); Everything works fine no errors the backlight works.
« Last Edit: January 03, 2018, 09:56:32 am by BIT »

 

TinyPortal © 2005-2018