Autor Beitrag
Mike_C
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: So 07.03.04 15:14 
Hi Leutz,

also an meinen letzten beiträgen merkt man sicher, dass ich mich gerade eingehend mit den SynEdit Komponenten beschäftige. Im moment versuche ich gerade eine AutoComplete Funktion zu realieren. In den Demos von SynEdit ist das auch beschrieben. naja aber so wie ich das gemacht habe (also, prinzipiell einfach kopieren und anpassen) funktioniert das ganze nicht.


Hier meine Einstellungen für die Komponente
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
object scpParams: TSynCompletionProposal
    DefaultType = ctParams
    Options = [scoLimitToMatchedText, scoUsePrettyText, scoUseBuiltInTimer]
    ClBackground = clInfoBk
    EndOfTokenChr = '()[]. '
    TriggerChars = '('
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clBtnText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = [fsBold]
    Columns = <>
    OnExecute = scpParamsExecute
    ShortCut = 24608
    Editor = seProjectSource
    TimerInterval = 1200
    Left = 500
    Top = 302
  end


und hier meine onExecute-Funktion

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
procedure TFormMain.scpParamsExecute(Kind: SynCompletionType;
  Sender: TObject; var CurrentInput: Stringvar x, y: Integer;
  var CanExecute: Boolean);
var locline, lookup: String;
    TmpX, savepos, StartX,
    ParenCounter,
    TmpLocation    : Integer;
    FoundMatch     : Boolean;
begin
  //Param Completion is different than Code Completion.  We can't just use
  //the string passed to us we have to figure out what they are looking for,
  //which is language dependant For this demo, I assume that it has to be on the
  //*same* line, then do some paren checking.  For the sake of the demo, the
  //function will be the word directly before the paren.  In other languages you
  //would want to do something like grab everything before the last end of
  //statement char (like in ObjectPascal it's the ';' char).  It *does* support
  //embedded functions (Hense the paren checking).  In this case, commas are the
  //delimiter so they are incremented accordingly.

  //Also everything is hard coded in.  You will want to have some kind of
  //structure that you are using instead of hard coding the parameters in

  with TSynCompletionProposal(Sender).Editor do
  begin
    locLine := LineText;

    //go back from the cursor and find the first open paren
    TmpX := CaretX;
    if TmpX > length(locLine) then
      TmpX := length(locLine)
    else dec(TmpX);
    FoundMatch := False;
    TmpLocation := 0;
    while (TmpX > 0and not(FoundMatch) do
    begin
      if LocLine[TmpX] = ',' then
      begin
        inc(TmpLocation);
        dec(TmpX);
      end else if LocLine[TmpX] = ')' then
      begin
        //We found a close, go till it's opening paren
        ParenCounter := 1;
        dec(TmpX);
        while (TmpX > 0and (ParenCounter > 0do
        begin
          if LocLine[TmpX] = ')' then inc(ParenCounter)
          else if LocLine[TmpX] = '(' then dec(ParenCounter);
          dec(TmpX);
        end;
        if TmpX > 0 then dec(TmpX);  //eat the open paren
      end else if locLine[TmpX] = '(' then
      begin
        //we have a valid open paren, lets see what the word before it is
        StartX := TmpX;
        while (TmpX > 0and not(locLine[TmpX] in TSynValidStringChars) do
          Dec(TmpX);
        if TmpX > 0 then
        begin
          SavePos := TmpX;
          While (TmpX > 0and (locLine[TmpX] in TSynValidStringChars) do
            dec(TmpX);
          inc(TmpX);
          lookup := Uppercase(Copy(LocLine, TmpX, SavePos - TmpX + 1));
          FoundMatch := LookupList.IndexOf(Lookup) > -1;
          if not(FoundMatch) then
          begin
            TmpX := StartX;
            dec(TmpX);
          end;
        end;
      end else dec(TmpX)
    end;
  end;

  CanExecute := FoundMatch;

  if canexecute then
  begin
    tsyncompletionproposal(sender).form.CurrentIndex := tmplocation;
    if lookup <> tsyncompletionproposal(sender).PreviousToken then
    begin
      tsyncompletionproposal(sender).ItemList.Clear;
      if lookup = 'ADDMODE' then
      begin
         tsyncompletionproposal(sender).itemlist.add('"expmode EXPORTMODE"');
      end else if lookup = 'DOEXPORT' then
      begin
         tsyncompletionproposal(sender).itemlist.add('"string FILENAME","file_ext_op EXTENSION"');
      end else if lookup = 'ADDVALUE' then
      begin
         tsyncompletionproposal(sender).itemlist.add('"string VALUE","bool PRIORITY","prmode PRIORITYMODE"');
      end;
    end;
  end else TSynCompletionProposal(Sender).ItemList.Clear;
end;


edit: ach ja! ich sollte noch erwähnen, dass alle einträge in die StringList im Konstruktor der Form eingetragen werden.

ich habe dabei nur den letzten Teil verändert!

kann mir jemand sagen, warum ich keine AutoComplet-Hinweise wie in der Demo bekomme? (für alle, die die Demos nicht haben: das ganze soll die Parameterhinweise, die auch in Delphi implementiert sind, realisieren!)

Greetz

Mike

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?
Benedikt
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 07.03.04 17:21 
Hi,

ich hab das gerade mal bei mir extra getestet (mit original deinem Code), da ging es ohne Probleme.
Hast du auch die richtigen, gleichen Funktionen wie in der Überprüfung in die Stringliste geschrieben?

Ansonsten Debug am besten mal um zu schauen wie weit er kommt...


:EDIT: Man kommt übrigens ein wenig durcheinander da du AutoComplete teilweise schreibst, weil es bei SynEdit ja auch eine AutoComplete-Kompo gibt :D