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:
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?
declare @a int set @a=5
declare @b int set @b=2
/*--*/
select @a + @b as sum
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Thommy. Good links.
For the use with TADOParameter, I wrote the .sql files like this:
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
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
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
Inside the (Delphi) EXE
embedded file into delphi exe application (not as a separate file from the appliaction)