按《让fpc/lazarus支持中文变量/过程/函数/中文控件名称》增加中文变量支持后,lazarus使用中文变量等代码补全时,列表框没对应的中文变量的:
找到procedure InitCharTable;(lazarus 3.4在63行)
解决方法:
要修改以下3个文件,打开相应文件,添加红字代码,修改后重新编译lazarus就可以。
找到procedure InitCharTable;(lazarus 3.4在63行)
procedure InitCharTable; var c:char; begin for c:=low(char) to high(char) do case c of 'a'..'z','A'..'Z','_',#$80..#$FF:CharTable[c]:=ctWordBegin; '0'..'9':CharTable[c]:=ctWord; else CharTable[c]:=ctNone; end; end;
2、\lazarus\ide\sourceeditor.pp
找到procedure TSourceEditor.StartWordCompletionBox;(lazarus 3.4在5420行)
procedure TSourceEditor.StartWordCompletionBox; var TextS: String; LogCaret: TPoint; i: Integer; TextS2: String; Completion: TSourceEditCompletion; begin if (FEditor.ReadOnly) then exit; Completion := Manager.DefaultCompletionForm; if (Completion.CurrentCompletionType<>ctNone) then exit; Completion.CurrentCompletionType:=ctWordCompletion; TextS := FEditor.LineText; LogCaret:=FEditor.LogicalCaretXY; Completion.Editor:=FEditor; i := LogCaret.X - 1; if i > length(TextS) then TextS2 := '' else begin while (i > 0) and (TextS[i] in ['a'..'z','A'..'Z','0'..'9','_',#$80..#$FF]) do dec(i); TextS2 := Trim(copy(TextS, i + 1, LogCaret.X - i - 1)); end; Completion.Execute (TextS2, Manager.GetScreenRectForToken(FEditor, FEditor.CaretX-length(TextS2), FEditor.CaretY, FEditor.CaretX-1)); end;
3、\lazarus\components\synedit\syncompletion.pas
找到function IsIdentifierChar(p: PChar): boolean; inline;(lazarus 3.4在481行),在对应的位置添加红色代码
function IsIdentifierChar(p: PChar): boolean; inline; {$IF FPC_FULLVERSION >= 20701} var u: UnicodeString; i: Integer; L: SizeUInt; {$ENDIF} begin Result := p^ in ['a'..'z','A'..'Z','0'..'9','_',#$80..#$FF]; if Result then exit; {$IF FPC_FULLVERSION >= 20701} if p^ <= #127 then exit; i := UTF8CodepointSize(p); SetLength(u, i); // wide chars of UTF-16 <= bytes of UTF-8 string if ConvertUTF8ToUTF16(PWideChar(u), i + 1, p, i, [toInvalidCharToSymbol], L) = trNoError then begin SetLength(u, L - 1); if L > 1 then Result := TCharacter.IsLetterOrDigit(u, 1); end; {$ENDIF} end;
修改后中文也可以使用代码补全功能(Ctrl+W):