if unit need .inc file, How can I do?
YXGust opened this issue · 3 comments
like this:
unit XSuperObject;
interface
{$I XSuperObject.inc}
uses
Classes,
Variants,
SysUtils,
Character,
XSuperJSON,
how can i add file "XSuperObject.inc" in code snippet
I'm assuming you want to test compile a function or class that needs an include file?
I'd never considered the need to do this. For a simple function/procedure I can't think of a way to do this. This is because of assumptions about code format that CodeSnip makes means that the inc file gets included twice so the following won't work:
{$I Test.inc}
function XXX: Integer;
begin
// do something with content of Test.inc
end;But, if you create a class, you can do it. For example if you have a an include file Test.inc in C:\Code\Tests, here's what to do:
-
Go to the Tools | Configure Compilers menu. In the dialogue box, select the compiler you want to use for test compiling. Select the Search Paths tab and enter
C:\Code\Testsin the edit box and click Add. You need to do this for each compiler you use. Then click OK to close the dialogue box. -
Create
C:\Code\Tests\Test.inc, containing the line:const IncTest = 42;
-
Create a new snippet (Ctrl+Ins).
-
Enter the required name and description.
-
Set Kind to Class / Advanced Record.
-
Enter the following source code for the snippet:
type TC = class public function test: Integer; end; {$I Test.inc} function TC.test: Integer; begin Result := IncTest; end;
-
Hit F9 to test compile the snippet. It should work! I have Delphu XE, 11 & 12 installed but only configured Delphi 12 with
C:\Code\Testsin the search path. Here's my result, showing compile failures with XE and 11 and success with 12:
If you would like me to consider adding a facility to compile include files for all compilable snippet types, please open a new issue and ask for it.
Hope this helps.
Yes,we can use "Search Paths".
Thank you, with your guidance, I succeeded.
Glad it worked. Cheers
