@@ -40,7 +40,7 @@ TCPIncludeManager = class
4040 FMergedSource: string;
4141
4242 function ProcessFile (const AFileName: string; var ACurrentCharPos: Integer): string;
43- function ResolveIncludePath (const AIncludePath: string; const AIsAngleBracket: Boolean): string;
43+ function ResolveIncludePath (const AIncludePath: string; const AIsAngleBracket: Boolean; const ASourceFile: string; const ALineNumber: Integer ): string;
4444 function IsAlreadyIncluded (const AFileName: string): Boolean;
4545 function ValidateAngleBracketInclude (const AInclude: string): Boolean;
4646
@@ -125,7 +125,7 @@ function TCPIncludeManager.ValidateAngleBracketInclude(const AInclude: string):
125125
126126 // Must have .e extension
127127 LFileName := AInclude.ToLower();
128- if not LFileName.EndsWith(' .e ' ) then
128+ if not LFileName.EndsWith(CPSourceFileExt ) then
129129 Exit;
130130
131131 // Must be a valid filename (not empty after removing extension)
@@ -166,7 +166,7 @@ function TCPIncludeManager.ProcessFile(const AFileName: string; var ACurrentChar
166166 Result := ' ' ;
167167
168168 if not TFile.Exists(AFileName) then
169- raise ECPException.Create(' Include file not found: %s' , [AFileName]);
169+ raise ECPException.Create(' File not found: %s' , [AFileName]);
170170
171171 if IsAlreadyIncluded(AFileName) then
172172 Exit; // Prevent circular includes
@@ -207,7 +207,7 @@ function TCPIncludeManager.ProcessFile(const AFileName: string; var ACurrentChar
207207 AddIncludePath(LIncludePath);
208208 end
209209 else
210- raise ECPException.Create(' Invalid #includepath directive: path must be enclosed in quotes' );
210+ raise ECPException.Create(' Invalid #includepath directive: path must be enclosed in quotes' , [], LFullPath, LLineIndex + 1 , 1 );
211211
212212 // After includepath, prepare for next content block
213213 LContentStartPos := ACurrentCharPos;
@@ -233,7 +233,7 @@ function TCPIncludeManager.ProcessFile(const AFileName: string; var ACurrentChar
233233 begin
234234 // Quoted include - allows paths, relative resolution
235235 LIncludePath := LLine.Substring(1 , LLine.Length - 2 );
236- LIncludeFile := ResolveIncludePath(LIncludePath, False);
236+ LIncludeFile := ResolveIncludePath(LIncludePath, False, LFullPath, LLineIndex + 1 );
237237 LIncludeContent := ProcessFile(LIncludeFile, ACurrentCharPos);
238238 Result := Result + LIncludeContent;
239239 end
@@ -243,14 +243,14 @@ function TCPIncludeManager.ProcessFile(const AFileName: string; var ACurrentChar
243243 LIncludePath := LLine.Substring(1 , LLine.Length - 2 );
244244
245245 if not ValidateAngleBracketInclude(LIncludePath) then
246- raise ECPException.Create(' Invalid angle bracket include "%s": must be filename.e format only (no paths)' , [LIncludePath]);
246+ raise ECPException.Create(' Invalid angle bracket include "%s": must be filename.e format only (no paths)' , [LIncludePath], LFullPath, LLineIndex + 1 , 1 );
247247
248- LIncludeFile := ResolveIncludePath(LIncludePath, True);
248+ LIncludeFile := ResolveIncludePath(LIncludePath, True, LFullPath, LLineIndex + 1 );
249249 LIncludeContent := ProcessFile(LIncludeFile, ACurrentCharPos);
250250 Result := Result + LIncludeContent;
251251 end
252252 else
253- raise ECPException.Create(' Invalid #include directive: must be "filename" or <filename>' );
253+ raise ECPException.Create(' Invalid #include directive: must be "filename" or <filename>' , [], LFullPath, LLineIndex + 1 , 1 );
254254
255255 // After include, prepare for next content block
256256 LContentStartPos := ACurrentCharPos;
@@ -280,7 +280,7 @@ function TCPIncludeManager.ProcessFile(const AFileName: string; var ACurrentChar
280280 end ;
281281end ;
282282
283- function TCPIncludeManager.ResolveIncludePath (const AIncludePath: string; const AIsAngleBracket: Boolean): string;
283+ function TCPIncludeManager.ResolveIncludePath (const AIncludePath: string; const AIsAngleBracket: Boolean; const ASourceFile: string; const ALineNumber: Integer ): string;
284284var
285285 LSearchPaths: string;
286286 LIndex: Integer;
@@ -289,7 +289,7 @@ function TCPIncludeManager.ResolveIncludePath(const AIncludePath: string; const
289289 begin
290290 // Angle bracket include - search in include paths only
291291 if FIncludePaths.Count = 0 then
292- raise ECPException.Create(' No include paths configured for angle bracket include: <%s>' , [AIncludePath]);
292+ raise ECPException.Create(' No include paths configured for angle bracket include: <%s>' , [AIncludePath], ASourceFile, ALineNumber, 1 );
293293
294294 // Build semicolon-separated search paths for FileSearch
295295 LSearchPaths := ' ' ;
@@ -302,7 +302,7 @@ function TCPIncludeManager.ResolveIncludePath(const AIncludePath: string; const
302302
303303 Result := FileSearch(AIncludePath, LSearchPaths);
304304 if Result = ' ' then
305- raise ECPException.Create(' Cannot find angle bracket include <%s> in configured include paths' , [AIncludePath]);
305+ raise ECPException.Create(' Cannot find angle bracket include <%s> in configured include paths' , [AIncludePath], ASourceFile, ALineNumber, 1 );
306306 end
307307 else
308308 begin
@@ -319,7 +319,7 @@ function TCPIncludeManager.ResolveIncludePath(const AIncludePath: string; const
319319 Exit;
320320 end ;
321321
322- raise ECPException.Create(' Cannot resolve include path: %s' , [AIncludePath]);
322+ raise ECPException.Create(' Cannot resolve include path: %s' , [AIncludePath], ASourceFile, ALineNumber, 1 );
323323 end ;
324324end ;
325325
0 commit comments