Recent

Author Topic: Using SynEdit Questation  (Read 9417 times)

ahmetnurideniz

  • Full Member
  • ***
  • Posts: 110
  • As you sow, you shall reap.
    • Big Student Web Site
Using SynEdit Questation
« on: October 24, 2011, 11:41:21 am »
Hi, want to use SynEdit for my cnc g code generator program.
I want to learn how can I change colors for my special word. for example when language set pascal if I write"begin" color is blue otomatic. So I want to change  if the word start"#" charecter it should be red color.

my second question
I want to otomatic comple function. for example. if  have "door" variable when  ı write do and pres ctrl + space then open small menu When I select one otomatic write it. how can I do that?
thansk

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11915
  • Debugger - SynEdit - and more
    • wiki
Re: Using SynEdit Questation
« Reply #1 on: October 24, 2011, 11:49:03 am »
Please have a look into the example folder (in the Lazarus installation directory). It has 2 examples for highlighting (color) and an example for auto-completion.

As for highlighting, if you need more complex highlighting, you may need to write your own highlighter: http://wiki.lazarus.freepascal.org/SynEdit_Highlighter

LA.Center

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
Re: Using SynEdit Questation
« Reply #2 on: October 25, 2011, 09:57:15 am »
You can also use TSynAnySyn component as highligher there you can add your custom Keywords, Objects, and Constants and color them as you wish.

The words must be all UPPERCASE.

Harold

  • Newbie
  • Posts: 1
Re: Using SynEdit Questation
« Reply #3 on: October 25, 2011, 05:35:36 pm »
First Post.  Included is a CNC highlighter created by modifying ..Lazarus\components\synedit\synhighlighterunixshellscript.pas.


ahmetnurideniz

  • Full Member
  • ***
  • Posts: 110
  • As you sow, you shall reap.
    • Big Student Web Site
Re: Using SynEdit Questation
« Reply #4 on: October 26, 2011, 09:42:15 pm »
I looked the example files. but I can't success. I can't understand the auto complate system. I prepare example file. It is not work, can anyone help me. where is my mistakes?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11915
  • Debugger - SynEdit - and more
    • wiki
Re: Using SynEdit Questation
« Reply #5 on: October 26, 2011, 10:27:53 pm »
SynEdit actually has 2 different completion Modules

TSynAutoComplete (which is NOT what you want)
TSynComplete (which you need)

The example currently doesn't point that out explicitly (a readme was added, but will only be in 0.9.31 and higher)

Yet if you run the example, you will see that the left refers to TSynAutoComplete, while the right site mention TSynComplete.



TSynComplete is NOT in the component palette, you must create it in code.

I see you tried that. But you did not declare the variable.
in the form add a "protected" section (or private/public as it suits you) and add:
  protected
    SynCompletion: TSynCompletion;

The replace Synedit1 by SynMemo
Or better yet, use a SynEdit instead of a SynMemo. For 99% they are equal, but SynEdit is better tested. (It's at the end of the components in the palette)

You also haven't copied the "DoExecute" / "DoSearchPosition" methods.... so that gives another error

ahmetnurideniz

  • Full Member
  • ***
  • Posts: 110
  • As you sow, you shall reap.
    • Big Student Web Site
Re: Using SynEdit Questation
« Reply #6 on: October 27, 2011, 10:24:04 am »
Thanks for answers Now my synedit can complate. but I have a one problem
if I write Ah and pres ctrl+space then open list and I select Ahmet
But it write AhAhmet the first carecter should be delete
example file can delete it. but I can't find How I can do that?

ahmetnurideniz

  • Full Member
  • ***
  • Posts: 110
  • As you sow, you shall reap.
    • Big Student Web Site
Re: Using SynEdit Questation
« Reply #7 on: October 27, 2011, 10:31:44 am »
First Post.  Included is a CNC highlighter created by modifying ..Lazarus\components\synedit\synhighlighterunixshellscript.pas.
How can I use tha file?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11915
  • Debugger - SynEdit - and more
    • wiki
Re: Using SynEdit Questation
« Reply #8 on: October 27, 2011, 12:47:38 pm »
Thanks for answers Now my synedit can complate. but I have a one problem
if I write Ah and pres ctrl+space then open list and I select Ahmet
But it write AhAhmet the first carecter should be delete
example file can delete it. but I can't find How I can do that?

Strange.

Which version of Lazarus are you using? Make sure it is at least 0.9.30

Do you still use TSynMemo or have you switched to TSynEdit?
If you are still using TSynMemo, then try TSynEdit => there have been lots of bugs in TSynMemo => don't know if this is one of them.

If it does happen with TSynEdit, then attach a code sample please (and indicate the exact Lazarus version)

ahmetnurideniz

  • Full Member
  • ***
  • Posts: 110
  • As you sow, you shall reap.
    • Big Student Web Site
Re: Using SynEdit Questation
« Reply #9 on: October 27, 2011, 02:29:52 pm »

Strange.

Which version of Lazarus are you using? Make sure it is at least 0.9.30

I am usenig Lazarus 0.9.30
Quote
Do you still use TSynMemo or have you switched to TSynEdit?
If you are still using TSynMemo, then try TSynEdit => there have been lots of bugs in TSynMemo => don't know if this is one of them.
I am usening TSynEdit
Quote

If it does happen with TSynEdit, then attach a code sample please (and indicate the exact Lazarus version)

if I write A there is no problem
if I write # or : there is a problem


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11915
  • Debugger - SynEdit - and more
    • wiki
Re: Using SynEdit Questation
« Reply #10 on: October 27, 2011, 03:37:07 pm »
if I write A there is no problem
if I write # or : there is a problem

Ah, well that explains it.

The completion module only looks for "A" to "Z", "0" to "9" and "_", even an accented char, or any none latin letter will not work.

Yes, that all needs to be fixed. The entire completion module needs a lot of work.

Anyway, What you need to do:

Code: [Select]
YourCompletion.OnCodeCompletion := @YourCodeToCopyTheSelectedWordIntoTheText;

// As procedure of TForm1, or any other object you choose
procedure YourCodeToCopyTheSelectedWordIntoTheText
                                  (var Value: string;    // the new/selected text/value
                                   SourceValue: string;     // the text currently between the 2 points
                                   var SourceStart, SourceEnd: TPoint;  // the begin/end of the a-z word
                                   KeyChar: TUTF8Char;
                                   Shift: TShiftState) of object;

2 possibilities:

1)
Adjust SourceStart, SourceEnd (both TPoint, containing line/column) to the range which you want to be replaced.
Then the module will do the replacement with your updated coordinates.

2)
Update the SynEdit yourself, and set
  SourceStart := SourceEnd;
  Value := '';


You can also look at SynEdit.CaretXy (or LogicalCaretXY) to find out where the Caret (| text-cursor) is

SourceStart, SourceEnd  are LOGICAL

LOGICAL means the x pos is in byte, instead of screen pos.
Look at this line
xäz

x is at pos 1 (screen and logical
ä is at pos 2 and has 2 bytes in UTF8, but takes only one pos on the screen
z is at screenpos 3, BUT Logical pos 4 (because ä took 2 bytes)

similar with tabs. Tabs increase the screenpos by more than 1, but they are only 1 byte.


That probably should be added to the example.... Well if I find time...

 

TinyPortal © 2005-2018