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
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
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: String; var x, y: Integer; var CanExecute: Boolean); var locline, lookup: String; TmpX, savepos, StartX, ParenCounter, TmpLocation : Integer; FoundMatch : Boolean; begin with TSynCompletionProposal(Sender).Editor do begin locLine := LineText;
TmpX := CaretX; if TmpX > length(locLine) then TmpX := length(locLine) else dec(TmpX); FoundMatch := False; TmpLocation := 0; while (TmpX > 0) and not(FoundMatch) do begin if LocLine[TmpX] = ',' then begin inc(TmpLocation); dec(TmpX); end else if LocLine[TmpX] = ')' then begin ParenCounter := 1; dec(TmpX); while (TmpX > 0) and (ParenCounter > 0) do begin if LocLine[TmpX] = ')' then inc(ParenCounter) else if LocLine[TmpX] = '(' then dec(ParenCounter); dec(TmpX); end; if TmpX > 0 then dec(TmpX); end else if locLine[TmpX] = '(' then begin StartX := TmpX; while (TmpX > 0) and not(locLine[TmpX] in TSynValidStringChars) do Dec(TmpX); if TmpX > 0 then begin SavePos := TmpX; While (TmpX > 0) and (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