Recent

Author Topic: [SOLVED] how to highlight SQL in SynEdit  (Read 3801 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[SOLVED] how to highlight SQL in SynEdit
« on: April 23, 2021, 10:14:47 am »
I drop a SynEdit and a TSynSQLSyn on a form.
Set the SynEdit highlighter property to SynSQLSyn.
Load a file SynEdit1.Lines.LoadFromFile('q1.sql');

The file loads but is not highlighted.

What am I missing?
« Last Edit: April 23, 2021, 01:01:47 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jcmontherock

  • Full Member
  • ***
  • Posts: 234
Re: how to highlight SQL in SynEdit
« Reply #1 on: April 23, 2021, 11:24:13 am »
You have to fill the object explorer of TSQLSyn. Do not forget to fill the HighLighter in SynEdit1.
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: how to highlight SQL in SynEdit
« Reply #2 on: April 23, 2021, 11:36:45 am »
?
Any sample?

i tried this
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, SynEdit, SynHighlighterSQL, SynHighlighterPas;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     SynEdit1: TSynEdit;
  16.     SynSQLSyn1: TSynSQLSyn;
  17.     procedure FormShow(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.     procedure OpenFile(Const AFileName : String);
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.OpenFile(Const AFileName : String);
  34. var
  35.   sTEMP : string;
  36.   F: TextFile;
  37. begin
  38.   AssignFile(F, AFileName);
  39.   Reset(F);
  40.   while not EOF(F) do
  41.     begin
  42.       Readln(F, sTEMP);
  43.       SynEdit1.Lines.Add(sTEMP);
  44.     end;
  45.   CloseFile(F);
  46. end;
  47.  
  48. procedure TForm1.FormShow(Sender: TObject);
  49. begin
  50.   SynEdit1.Clear;
  51.   OpenFile('q1.sql');
  52. end;
  53.  
  54. end.
  55.  

And it still doesn't work.
« Last Edit: April 23, 2021, 12:08:17 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: how to highlight SQL in SynEdit
« Reply #3 on: April 23, 2021, 12:17:04 pm »
Offtopic. ATSynEdit component can highlight the SQL pretty fast. It needs ATSynEdit_Ex package with "lite lexer" component. Lite-lexer for SQL is present in CudaText editor.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: how to highlight SQL in SynEdit
« Reply #4 on: April 23, 2021, 12:21:31 pm »
Not much help, if i can't get the standard version to work!
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

korba812

  • Sr. Member
  • ****
  • Posts: 392
Re: how to highlight SQL in SynEdit
« Reply #5 on: April 23, 2021, 12:54:55 pm »
Make sure that:
1. You have the "SynEdit1.Highliter" property set to SynSQLSyn1.
2. You have SynSQLSyn1.Enabled : = True.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: how to highlight SQL in SynEdit
« Reply #6 on: April 23, 2021, 12:56:10 pm »
See attached demo. Note that the SQL highlighter by default is not very "colorful". In my simple example the SQL keywords are only put to bold face, by default, and maybe this is a bit hard to detect so that it looks as if the highlighter is not working. In the attached demo I did set some colors to demonstrate that the highligher works correctly.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: how to highlight SQL in SynEdit
« Reply #7 on: April 23, 2021, 01:01:10 pm »
@wp - Thanks
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: [SOLVED] how to highlight SQL in SynEdit
« Reply #8 on: April 24, 2021, 07:59:15 pm »
OK, after playing with the highlighter it became obvious of a few shortcomings.
I use MariaDB (which is not the same as MySQL), there are some datatypes and functions missing (VARCHAR, CAST, ...). So I made my own highlighter with a few changes
1. New dialect - MariaDB
2. Enabled is true by default
3. Set some reasonable default colours
4. Exposed the three strings so it's easier to add functions, keywords, and datatypes.
I have attached a package.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: [SOLVED] how to highlight SQL in SynEdit
« Reply #9 on: April 24, 2021, 11:00:28 pm »
Since this is essentially the SQLHighligher couldn't you prepare a patch for the trunk version and submit it to bugtracker so that it can be included in the official version? I think this would be a nice addition interesting to a variety of users.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: [SOLVED] how to highlight SQL in SynEdit
« Reply #10 on: April 25, 2021, 06:51:37 am »
@wp - since I don't consider myself as a programmer and I know nothing about writing patches I'll leave that to someone in the know. I only put it together as a proof of concept.
Any one is free to take the code and develop it further even write that patch  :) :) :)
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018