Jump to content
Jeff Steinkamp

Include External Text Files in Output Folder

Recommended Posts

The project I am working on requires 4 external text files, 3 with SQL data and 1 with CSV data that can be read at runtime when necessary.  How do we include these into the project, so they get read into the output folder.  In Visual Studio, this was rather simple.  Include the files in the project and set the property to include them in the output folder.  I have yet to find anything similar in Delphi.

Share this post


Link to post

In RAD Studio it's so easy too!

you can add any file in your project, of course, your "EXE"/DLL/etc... it will be "bloated" depending on the type of file you will include!

in your case, I think that using "Deployment" menu will be better, because you can define where yours files will be placed, including what names it will have!

 

 other way, you can use the "events"when compiling your project... but I think that your better choice is "Deployment"

image.thumb.png.46c2399ce9f56a44a7ec5d4802811c61.png   image.png

Edited by programmerdelphi2k
  • Like 1

Share this post


Link to post

I've dropped those files into the project manager.  I see nothing that resembles the Deployment screen you show above.  I get this:

image.thumb.png.89274f89e1b2858e40d95ed49b236492.pngimage.thumb.png.fcbd68d8d1de1a13244620e8a1a5a622.png 

 

But, at this stage of the game I'm not even close to project deployment, I am barely into the development phase.  But I do need these files in the output folder for continued development.

 

I'm not sure exactly how the build events are helpful unless there are some commands that can be used to copy these files during the pre-build event.

 

Share this post


Link to post

Just for curiosity, why don't you just copy the 4 files into the output folder manually and move on?

 

 

Edited by Attila Kovacs

Share this post


Link to post

hi @Jeff Steinkamp

 

you can choice between two ways above (or any other existent on RAD Studio, of course)

  • you can use: "DEPLOYMENT"  --> indicated for your case! because you want "indicate the "TARGET folder"
  • OR....  I say "OR"
  • add your files using "Project Manager"  -- here, you cannot do it!

So, you'll have two ways to do it!!!  --> two independent ways !!!

 

Using the "COMPILING EVENTS", it's for anothers tasks... but it's possible adapt it!!!!

  • the compiler/linker can execute anothers "commands" before, pre, or after actions! 
    • then, you would can, for example, execute a ".BAT" file/EXE/COM/VBS/etc... to execute any task before/pre/after your building... you see? --> I think that it's not your case here!

 

image.thumb.png.2ebe619f57752dfaca86afb1571378eb.png

Edited by programmerdelphi2k

Share this post


Link to post
11 hours ago, Jeff Steinkamp said:

I've dropped those files into the project manager.  I see nothing that resembles the Deployment screen you show above.  I get this:

image.thumb.png.89274f89e1b2858e40d95ed49b236492.pngimage.thumb.png.fcbd68d8d1de1a13244620e8a1a5a622.png 

 

But, at this stage of the game I'm not even close to project deployment, I am barely into the development phase.  But I do need these files in the output folder for continued development.

 

I'm not sure exactly how the build events are helpful unless there are some commands that can be used to copy these files during the pre-build event.

 

Build events allow you to execute shell commands, like "copy" or "rename", using macros that get replaced with project related pathes etc.. Since the files are used by the finished program I would use the post build event for that. The deployment stuff is for non-Windows targets only if I understood that correctly.

Share this post


Link to post
2 hours ago, PeterBelow said:

The deployment stuff is for non-Windows targets only if I understood that correctly.

You misunderstood!

  • after build your project, just use "Deployment" "button" to deploy your project+any files on setup
Edited by programmerdelphi2k

Share this post


Link to post

 

here my sample to MSWindows, but works in any other platform where PAServer works!

  1. Install your PAServer in your MSWindows (same PC or PC target - does not matter, since the the PC can be seen by RAD IDE, or be, same network!!!
    1. "setup_paserver.exe" is in: C:\<<installation-dir>>\PAServer
    2. on PAServer command line type:  paserver -unrestricted -scratchdir=<<d:\MyNewScratchDirToPAServerDeployment>>    // it's ready! here it's where your new project + files will be placed
  2. run it and go back to RAD IDE!
  3. config your "Deployment" setup as above, indicating what files you need deploy together with your exe/dll
  4. now, build your project
  5. now, in "Deployment", just click "Deploy" button...
  6. as you dont have your "profile" created, the IDE ask to create it... then do it now!
    1. give a name, inform the IP where PAServer is running + password if used ... test connection!
  7. it's ready!

NOTE: PAServer show the IP/Port using command "i" and "p" in your console!

 

image.thumb.png.b532108bd4954fbbb192fcbdfee4296f.png   image.png

image.thumb.png.6ce4f5d289b6cb537b158bb5016f982d.png

Edited by programmerdelphi2k

Share this post


Link to post

Not exactly clear what you are looking for, but you can also use Resources to include files

Its possible to load them to ResourceStream like that.

procedure TForm1.Button1Click(Sender: TObject);
var
  List: TStringList;
  Stream: TResourceStream;
begin
  Stream := TResourceStream.Create(HInstance, '<Resource identifier>', RT_RCDATA);
  try
    List := TStringList.Create;
    try
      List.LoadFromStream(Stream);
      Label1.Text := List.Text;
    finally
      List.Free;
    end;
  finally
    Stream.Free;
  end;
end;

But these were fixed files, not user-loadable via dialog in the app.

Edited by Rollo62

Share this post


Link to post

@Rollo62 what he want is: transfer the 4 files (txt, cvs, scripts at general) to target app-folder to use it "on future"! not just have the "data" into app!!!

like as: "Please, sir RADStudio copy my files xxxx, because I want use it later in my app"... 🙂

Edited by programmerdelphi2k

Share this post


Link to post

Use post-build commands in your project options. Add the command to copy the required file to the destination folder. You have a bunch of macros to access many things. You can see the macros when you click the "..." to add post-build commands. For example $(OUTPUTDIR) in your command (such as copy) will be replaced by the actual output directory.

 

  • Like 1

Share this post


Link to post

Thanks for all of the suggestions and recommendations.  I have chosen to use the post-build commands as this way those files in the output folder will always be updated in the event I have to make modifications to those files during the development process.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×