Recent

Author Topic: All Things SynEdit/Highlighter - Lyrics Editor  (Read 7063 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #30 on: May 08, 2019, 10:26:51 pm »
Okay... On this lines...

Code: Pascal  [Select][+][-]
  1.  
  2. case UpperCase(copy(FLineText, FTokenPos+1, i - FTokenPos - 1)) of 'DM', 'BB','F','C':
  3.  
  4.  

You have some-hardcoded chords in there. When I run the app there are still some that do not highlight/bold red.

I can add the strings in that I can see are't effected, to the string, but that means I will have to enter every possible chord; around 100+ combinations.

That is fine if that is the only thing I can do, but how can this be done dynamically, because the user can enter in their own custom chords.

Thanks
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #31 on: May 08, 2019, 10:52:33 pm »
The question is, do you need some check on a correct chord? (And so far I assumed chords must end on the same line, that they begin, no linebreak)

I mean should [silly] be a highlighted as a chord? Or [two words] ?

Is it based on a pattern of some sort?
Or based on a list (which the user specifies).

If you do not mind the highlight of [invalid] chords, then just always assume a valid chord after an opening [.

Otherwise if it is a variable list, you can load the list in some structure.
If speed is no concern (I.e you expect no more than at most 1000 to 2000 lines) then load them into a stringlist and use "indexof() >= 0"
Maybe it will work for more lines, depends on many factors. For starters use a sorted stringlist.

For faster checks fpc has various "hash" classes. Those are in fpc. You need to ask someone else.

There are other options, but they become very expert (there are certain tree types that can be used for this.

---
btw the
s:=....
line.
Left over from debugging.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #32 on: May 08, 2019, 11:01:23 pm »
The question is, do you need some check on a correct chord? (And so far I assumed chords must end on the same line, that they begin, no linebreak)

I mean should [silly] be a highlighted as a chord? Or [two words] ?

Is it based on a pattern of some sort?
Or based on a list (which the user specifies).

If you do not mind the highlight of [invalid] chords, then just always assume a valid chord after an opening [.

Otherwise if it is a variable list, you can load the list in some structure.
If speed is no concern (I.e you expect no more than at most 1000 to 2000 lines) then load them into a stringlist and use "indexof() >= 0"
Maybe it will work for more lines, depends on many factors. For starters use a sorted stringlist.

For faster checks fpc has various "hash" classes. Those are in fpc. You need to ask someone else.

There are other options, but they become very expert (there are certain tree types that can be used for this.

---
btw the
s:=....
line.
Left over from debugging.

Thanks

All chords should be on the line over a verse sentence
In my example, no chords are on the same line as a sentence.
The ones that don't highlight are not on that line (per above code)

Their placement is correct. Example... [Csus] or [Bb/F] don't highlight, unless I add them to the list.

A chord could be from 2 char to 10 char

So, I will have to figure out how to use the string-list for this app. I have done string-list before, so I am familiar with it. I think it is handy.

Thanks... I will try to work something out.
« Last Edit: May 08, 2019, 11:10:59 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #33 on: May 08, 2019, 11:10:04 pm »
Another issue, it's simple, but its not working for me, must be missing something
All this code does is parse each character looking for the "Key" (of the chord) which is located toward the top of the text,
Finding the text works fine.

My problem is, if there is an invalid character, I raise a message box.
However, all I want to do is display that invalid char in the message box string, but it don't like me.

I get this error....
Error: Incompatible type for arg no. 1: Got "AnsiString", expected "PChar"

I have tried lots of ways to convert the PChar to a String,, but can't seem to get it right.

Can somebody see something I am missing??

There may be an easier way to do this, but this is what my basic knowledge came up with, albeit it may be wrong :)

CODE:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.getKey(Sender: TObject);
  3. const
  4.   n = ['1'..'9','C','D','E','F','G','A','B','a','b','d','f','g','i','j','l','m','s','t','u','/','#','?']; //valid chord characters
  5.  
  6. var
  7.   C: Char;
  8.   i: integer;
  9.   bStart: Boolean = False;
  10.   extractstr: String;
  11.   p: String;
  12.  
  13. begin
  14.  
  15.   for i := 1 to  length(synEdit.text) do
  16.       If synEdit.text[i] = '[' Then
  17.         {skip}
  18.         bStart:=True
  19.       else If synEdit.text[i] = ']' Then
  20.          begin
  21.            Break;
  22.          end
  23.       else
  24.           begin
  25.             if bStart=True Then
  26.                begin
  27.                  c:=synEdit.text[i];
  28.                  p:=c;
  29.                  if c in n Then
  30.                     extractstr := extractstr + c
  31.                  else
  32.                    begin
  33.                       Application.MessageBox('There is an invalid character ( ' + p + ' ) in the "Key:" signature. Please correct the key to a valid key character.', 'Invalid Key Character', MB_ICONERROR);
  34.                    end
  35.                end
  36.             else
  37.                {skip}
  38.           end;
  39.  
  40. lbKey.Caption:=extractstr;
  41.  
  42. end;
  43.  
  44.  

Like I said, everything works except the PChar to String issue in the message box string.
« Last Edit: May 08, 2019, 11:13:18 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #34 on: May 09, 2019, 12:08:38 am »
IIRC, just type cast it
pchar('text text');

If not, then
s := 'text';
MessageBox(@s[1],...)

Edson

  • Hero Member
  • *****
  • Posts: 1324
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #35 on: May 09, 2019, 02:27:16 am »
Just curious.

@piselink What's the problem with using SynFacilSyn as highlighter?
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #36 on: May 09, 2019, 01:21:13 pm »
Just curious.

@piselink What's the problem with using SynFacilSyn as highlighter?

I haven't gotten around to checking it out yet, that's all.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #37 on: May 09, 2019, 01:40:32 pm »
IIRC, just type cast it
pchar('text text');

If not, then
s := 'text';
MessageBox(@s[1],...)

Really weird...
casting it to PChar(p) works in an Application Message box if its all by itself.
But, If I put string text in front and back of the cast I get this error...

Error: Incompatible type for arg no. 1: Got "AnsiString", expected "PChar"

Code: Pascal  [Select][+][-]
  1. var
  2.  p: String;
  3.  
  4. begin
  5.     p := c;
  6.     //Application.MessageBox(PChar(p), 'Test', MB_ICONERROR);
  7.     Application.MessageBox('text before ( ' + PChar(p) + ' )  text after', 'Invalid Key Character', MB_ICONERROR);
  8. end;
  9.  
  10.  


I usually don't have problems with these, but the usual is not working for this message box.

Remember,

The PChar is coming from text in the SynEdit control.
I am returning just one character through "for next loop (w/ integer number)"
See code above

In my application I can pass the synedit string to a label on the form no problem.
Why the issue with Message box??
« Last Edit: May 09, 2019, 01:43:01 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #38 on: May 09, 2019, 01:52:24 pm »
Tried martin's second possible solution.
It doesn't work either

Error: Operator is not overloaded: "Constant String" + "Pointer"

Code: Pascal  [Select][+][-]
  1. var
  2. p: String;
  3.  
  4. p := c;
  5. Application.MessageBox('text before' + @p[1] + ' text after', 'Test', MB_ICONERROR);
  6.  
  7.  

Trying to figure this out now.


Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #39 on: May 09, 2019, 02:07:19 pm »
Who complains about wanting a pchar? THe "+" or the MessageBox?

So do you need to cast just one operand, or the whole result?

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #40 on: May 09, 2019, 02:11:38 pm »
Who complains about wanting a pchar? THe "+" or the MessageBox?

So do you need to cast just one operand, or the whole result?

Like I said... the message box complains ONLY IF I HAVE text before and after the @p[1] or PChar(p) tags

If I use message box WITHOUT text before and after  "@p[1] or PChar(p) tags" it works fine.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #41 on: May 09, 2019, 02:15:23 pm »
I already knew something about PChar and the fact that it is actually a pointer type
Even, though the below article didn't directly address my issue, I did find this article very informative for newbies.

READ IT HERE:
http://rvelthuis.de/articles/articles-pchars.html
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #42 on: May 09, 2019, 02:36:25 pm »
This is a string:
Code: Pascal  [Select][+][-]
  1. 'foo bar'
This is a string too:
Code: Pascal  [Select][+][-]
  1. 'var s: string;
  2. 'foo bar' + s + 'abc'

The + operator works on only on strings (at least the way you want to use it, all else does not matter here)

MessageBox get the result of the entire expression
Code: Pascal  [Select][+][-]
  1. 'foo bar' + s + 'abc'
But that is a string....

And MessageBox wants a pchar.

Casting just the "s" does no good. (besides the fact that the + can not work on it).
But even if the + would work, the rest would still be strings.

You can NOT cast one or more parts of the expression, because then the + no longer concatenates the parts (for that they must be string => "s" must be a string).

So what do you need to cast? What (in its entire) is given to MessageBox?


Sorry, I am trying to leave that, with some challenge to learn.
If you rather have the result without any ado, then say so.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #43 on: May 09, 2019, 02:42:01 pm »
Here is a dumbed-down project just to test the error.

This project works on using ...

Code: Pascal  [Select][+][-]
  1.  
  2. Application.MessageBox(PChar(p), 'Test', MB_ICONERROR);
  3.  
  4.  


BUT... in the project (which I commented out) I want this to work. (or using PChar(p))

Code: Pascal  [Select][+][-]
  1.  
  2. Application.MessageBox('There is an invalid character ( ' + @p[1] + ' ) in the "Key:" signature. Please correct the key to a valid key character.', 'Invalid Key Character', MB_ICONERROR);
  3.  
  4.  

DOWNLOAD PROJECT
« Last Edit: May 09, 2019, 02:45:44 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #44 on: May 09, 2019, 02:46:43 pm »
As I said
Code: Pascal  [Select][+][-]
  1.      'There is an invalid character ( ' + p + ' ) in the "Key:" signature. Please correct the key to a valid key character.'    
Is an expression.

You need to cast the result
Code: Pascal  [Select][+][-]
  1.          Application.MessageBox(PCHAR( 'There is an invalid character ( ' + p + ' ) in the "Key:" signature. Please correct the key to a valid key character.' ) , 'Invalid Key Character', MB_ICONERROR);    

Assuming, that "p" is a string.

 

TinyPortal © 2005-2018