diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index eb4db0c170..cce0c158e7 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -94,6 +94,8 @@ type property CodeCompleteSrcChgCache: TSourceChangeCache read ASourceChangeCache write SetCodeCompleteSrcChgCache; public + function AddPublishedVariable(const UpperClassName,VarName, VarType: string; + SourceChangeCache: TSourceChangeCache): boolean; override; function CompleteCode(CursorPos: TCodeXYPosition; var NewPos: TCodeXYPosition; var NewTopLine: integer; SourceChangeCache: TSourceChangeCache): boolean; @@ -296,6 +298,34 @@ begin or (ANodeExt.Flags=ord(ncpPrivateProcs)); end; +function TCodeCompletionCodeTool.AddPublishedVariable(const UpperClassName, + VarName, VarType: string; SourceChangeCache: TSourceChangeCache): boolean; +begin + Result:=false; + if (UpperClassName='') or (VarName='') or (VarType='') + or (SourceChangeCache=nil) or (Scanner=nil) then exit; + // find classnode + BuildTree(false); + if not EndOfSourceFound then exit; + ClassNode:=FindClassNodeInInterface(UpperClassName,true,false); + // initialize class for code completion + CodeCompleteClassNode:=ClassNode; + CodeCompleteSrcChgCache:=SourceChangeCache; + // check if variable already exists + if VarExistsInCodeCompleteClass(UpperCaseStr(VarName)) then begin + + end else begin + AddClassInsertion(nil,UpperCaseStr(VarName), + VarName+':'+VarType+';',VarName,'',ncpPublishedVars); + if not InsertAllNewClassParts then + RaiseException(ctsErrorDuringInsertingNewClassParts); + // apply the changes + if not SourceChangeCache.Apply then + RaiseException(ctsUnableToApplyChanges); + end; + Result:=true; +end; + function TCodeCompletionCodeTool.CompleteProperty( PropNode: TCodeTreeNode): boolean; { diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index f946a90d9b..59e93de4aa 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -117,7 +117,7 @@ type function FindPublishedVariable(const UpperClassName, UpperVarName: string): TCodeTreeNode; function AddPublishedVariable(const UpperClassName,VarName, VarType: string; - SourceChangeCache: TSourceChangeCache): boolean; + SourceChangeCache: TSourceChangeCache): boolean; virtual; function RemovePublishedVariable(const UpperClassName, UpperVarName: string; SourceChangeCache: TSourceChangeCache): boolean; function RenamePublishedVariable(const UpperClassName,