Link to home
Start Free TrialLog in
Avatar of lefodnes
lefodnes

asked on

Include sql text files into resource of Delphi XE project at compile time

I need help figuring out how to include text files into my Delphi XE Project, into the EXE file. The text files are actually sql files that can look like this:
declare @a int set @a=5
declare @b int set @b=2
/*--*/
select @a + @b as sum

Open in new window

I use this format because this .sql file can be opened in MS SQL Server Management Studio, to be edited and tested there.
I want to be able to save the file, and compile the Delphi XE Project and run the program. I want the Delphi XE to read the .sql file into the EXE at compile time. At run time, the program will read out the .sql file, remove whatever is above "/*--*/" and replace all '@' with ':', so that parameters can be supplied in an TADOQuery.

I'm hoping maybe to use resource files to do this. RC files? If that will work, how to compile it into .RES file and include into .EXE at project compile time?
ASKER CERTIFIED SOLUTION
Avatar of Thommy
Thommy
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lefodnes
lefodnes

ASKER

Thanks Thommy. Good links.
For the use with TADOParameter, I wrote the .sql files like this:

declare int @a set @a = /*:a*/1
declare int @b set @b = /*:b*/2

select @a+@b as sum

Open in new window



In Delphi code, I need to take away comments on the declare lines and remove all after the last "*/", before putting the SQL into TADOQuery, and adding parameters. If colon-parameters are used more than once, they have to be added multiple times. Refer to : http://stackoverflow.com/questions/7613832/how-do-i-use-tadoquery-parameters-with-integer-parameter-types-that-have-to-be-p