Recent

Author Topic: Synedit, Synmemo  (Read 12681 times)

tatamata

  • Hero Member
  • *****
  • Posts: 693
    • ZMSQL - SQL enhanced in-memory database
Synedit, Synmemo
« on: July 23, 2011, 11:23:12 pm »
Have few questions:
1. What is actual difference between TsynEdit and TSynMemo?
2. How can I wrap text in TSynMemo in order not to allow extending text out of the size of control? I don't want to allow the text to spreading  more than actual control size, but rather to continue in next line.
3. How can I add some token to be recognized in a highliter?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Synedit, Synmemo
« Reply #1 on: July 23, 2011, 11:32:30 pm »
1) for all good purpose they are identical, and you should use TSynEdit.

TSynMemo has some extra functions, that emulate what a memo does, e.g accessing the cursor pos, as offset in chars from text-strat rather than x/y

2) Neither of them has text wrapping. Been on the todo list for a long time...
You would have to break lines yourself on every resize, not very effective.

3) There are examples  fro the 2 configurable highlighters, in the Lazarus examples/synedit folder
All other info on highlighter can be found here: http://wiki.lazarus.freepascal.org/SynEdit_Highlighter

There is also TSynUniSyn, I haven't ever touched it yet. No idea.

tatamata

  • Hero Member
  • *****
  • Posts: 693
    • ZMSQL - SQL enhanced in-memory database
Re: Synedit, Synmemo
« Reply #2 on: July 24, 2011, 10:30:50 am »
Martin,
I want to use   TSynAutoComplete, but I don't get it...
I have two Dbf tables ("Tables" and "Fields") containing information about tables and fields in my project.
Then I have TSynEdit and TSynSQLSyn highlighter and also TSynAutoComplete.
I populate AutoCompleteList with following code, in order to get list
 of table.field items:

Code: [Select]
procedure TFormMain.UpdateAutocompleteList;
var
  vBookmark1:TBookmark;
  vBookmark2:TBookmark;
begin
  vBookmark1:=Tables.GetBookmark;
  vBookmark2:=Fields.GetBookmark;
  try
    Tables.DisableControls;
    Fields.DisableControls;
    Tables.First;
    SynAutoComplete1.AutoCompleteList.Text:='';
    while not Tables.EOF do begin
      Fields.First;
      while not Fields.EOF do begin
        SynAutoComplete1.AutoCompleteList.Append(Tables.FieldByName('TABLENAME').AsString+'.'+Fields.FieldByName('FIELDNAME').AsString);
        Fields.Next;
      end;
      Tables.Next;
    end;
  finally
    Tables.GotoBookmark(vBookmark1);
    Tables.FreeBookmark(vBookmark1);
    Fields.GotoBookmark(vBookmark2);
    Fields.FreeBookmark(vBookmark2);
    Tables.EnableControls;
    Fields.EnableControls;
  end;
end;               

I hoped it will enable auto-completion when you, for example type "ordrs." that it will be able to see a pop-up list of all possible fields, like "ordrs.ordr, ordrs.cmpnt, etc.".
How to enable autocompletion in this way? What have I missunderstood?
Basically, I want to do what all DBMS usually do - when you type a table identifier and dot, it gives you list of all fields belonging to the table...
« Last Edit: July 24, 2011, 10:34:46 am by tatamata »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Synedit, Synmemo
« Reply #3 on: July 24, 2011, 11:54:38 am »
TSynAutoComplet does not do the popup. TSynComplete (or similar) does.

You need to create it in code, it is not in the component palette.

Again look in the example folder, there is an example featuring both.

tatamata

  • Hero Member
  • *****
  • Posts: 693
    • ZMSQL - SQL enhanced in-memory database
Re: Synedit, Synmemo
« Reply #4 on: July 24, 2011, 05:05:56 pm »
Martin, thanks, it works now.
When I enter some leading chars, then press Ctrl+Space, a drop-down list appears with first item that satisfies criteria selected by default.
However, other items matching searching criteria are not at grasp, since all other items are present in list by order in is which they were added to the ItemList...This means that only the first item matching search criteria can be selected, while others are not reachable. because the list is not filtered by search criteria...

So, is there a way to filter the ItemList by search criteria, so that only items matching the pattern are showned?


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Synedit, Synmemo
« Reply #5 on: July 24, 2011, 05:51:05 pm »
Look at the example, it shows how to implement the filter.

You must change the list yourself, which means you must store the complete list outside the syncompletion, and then copy the required entries in the current list

  SynCompletion.OnExecute := @DoExecute;
  SynCompletion.OnSearchPosition := @DoSearchPosition;

tatamata

  • Hero Member
  • *****
  • Posts: 693
    • ZMSQL - SQL enhanced in-memory database
Re: Synedit, Synmemo
« Reply #6 on: July 24, 2011, 09:29:06 pm »
OK, thanks, it works now, I have TStringList for the whole list and then it is filtrated for actual SynComplate list...

However, I still don't understand why redundant code is needed in both @DoExecute and @DoSearchPosition? Are they both neccessary? What is difference?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Synedit, Synmemo
« Reply #7 on: July 24, 2011, 09:47:43 pm »
You can put tjhe code in one, and call the it from the other.

DoExecute is called, when the completion is invoked (it provides the intial list). So depending on the application it may do more work (load from db, or in the IDE codetools parsing the unit...)

DoSearchPosition is called whenever the "CurrentString" changes. Again it depends on the goal of the application. (Some apps, may want to keep all entries, but change selection only...)

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Re: Synedit, Synmemo
« Reply #8 on: August 01, 2011, 06:26:06 pm »
Hi all,
  I remember that I asked the same questions are you tatamata, right Martin ?
Well, these are few helpful links:

http://www.lazarus.freepascal.org/index.php/topic,11064.0.html
http://www.lazarus.freepascal.org/index.php/topic,1777.0.html
http://www.lazarus.freepascal.org/index.php/topic,7879.0.html
http://www.lazarus.freepascal.org/index.php/topic,7338.0.html
http://lazarus.freepascal.org/index.php/topic,10294.msg50838.html

enjoy coding :)
Martin, no need to thank me xD i know that you get bored by answering to same questions every day :O xD
cheers,,
KingXerXes
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.