Writing/Reading User-Defined settings in app.config file - configuration

I am trying to read and write into app.config file of user-settings. I found a snippet of a code for working with confige file. I finally got it compiling and running, but it absolutely seems to be doing nothing to the App.config file.
Here is the code:
Method MainForm1.Button1.Click(sender: System.Object; e: System.EventArgs);
var
config : System.Configuration.Configuration;
begin
config:=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add('PreferenceToRemember','value1');
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection('appSettings');
end;
It is compiling without any errors, but I don't know if it is doing anything.
Is there anything wrong with the code? I need to be able to write/read a section and write/read a key/value. Thanks in advance.
UPDATE: Instead of using ConfigurationManager, I simply use Properties.Settings.Default. However, I am having bit of a problem writing into it and reading back from it, although program complies with without any errors and the code seems simple.
How do you read and write to Properties.Settings.Default from within your code?

Maybe you're looking at the wrong file?
The app.config you have in your solution will be copied to YourProgramFile.exe.config in the bin/Debug or bin/Release folder. When running your program it will update this file, not the app.config file in your solution.
Then perhaps you also should check write permissions on your application folder. Normally (Win Vista, Win 7) the User executing an application does not have write permissions in the Program Files folder where your application should reside, so updating the .config will most probably fail due to the lack of write permissions. This is even more true for Linux/Unix systems.
You should try to separate the elements you need to write and write an additional config file in a user-specific folder. You can take the defaults from the normal application config for that initially and just update the user-specific config file, this way you are not hindered by file permissions and every user can update their settings specifically.

Related

Compiling a program on a server

I'm new to servers and programming in general, and I have a question regarding remote acces to a server, and how much I can actually do on it.
The thin is I have a working program on a linux server, which I acces with my windows machine using mobaxterm. I can acces the server, I see folders and a cmd line, where I can compile a makefile. Everything runs well, however when I run the makefile it just compiles, and doesn't do anything. No error messages, but also no opening of a program. I don't understand anything. Is it a delimitation of the servers structure, that it can only store files on it?
When you compile under linux using a make, it produces an executable but does not run it. Make builds executable objects, but it does not run them. You should include your makefile in the question (reduced to a minimum if it is large). Inside it, you will see that it generates a executable file with a specific name. To run it, you need to invoke this from the command line.
To find out what it is building, a quick way is to type "make clean" (press enter of course) to clean up any built objects. Then type the "ls" command to see what is in your directory.
Next, build the program with the "make" command, then type "ls" to see what has been added. Ignore any new files that end in .o or .a or .so and look for any new files. These are the files built by make and at least one of them is the program you built.
Assuming you found a new file called "myprogram". To run it, type:
./myprogram

FireDac error 314 - but DLLs are in program directory

I am getting when trying to access a MySql database :
[FireDac][Phys][MySQL]-314. Cannot load vendor library [libmysql.dll
or libmysqlld.dll]
This did not previously happen with this (unchanged) code, however, I have upgraded to Windows 10 and had to reinstall Delphi XE8, so it is obviously a system configuration matter.
In order to try to solve the problem, I copied both of those files into c:\windows\sysytem32.
When that did not seem to work, I copied them into \win32\debug, which is where the generated .EXE resides.
I imagine that I am doing something rather stupid, but can't see what.
The proper solution is to place the driver file (eg., libmysql.dll) in your application's folder, or to place the installation location in your FDDrivers.ini file:
[MySQL]
Vendor=<folder>\libmysql.dll
(Recent versions of the documentation seem to use VendorLib instead of Vendor in the INI file.)
See the RAD Studio documentation topics Configuring Drivers (FireDAC) and Connect to MySQL Server (FireDAC) for more information.
Let me to answer in two point.
Developing, live database connection!
Hope you have on your data module an "TFDPhysMySQLDriverLink" component.
Click this component and browse your LibMySQL.DLL into VendorLib. Should be work. But only in design time.
Runtime. Hopefully your DM created firstly in your project.
In the DM's OnCreate event, you have to disconnect your library (I always ran my project with no database connection) and replace your "TFDPhysMySQLDriverLink"'s Vendorlib to LibMySQL.DLL (which is copied your which is copied where the generated .EXE resided)
Have a nice day!

caffe: libglog.so.0 missing (error while loading shared libraries)

I've installed caffe on a server a while ago, and back then it worked properly.
Now I'm following the LeNet MNIST tutorial again (http://caffe.berkeleyvision.org/gathered/examples/mnist.html), and running
./examples/mnist/create_mnist.sh
returns
build/examples/mnist/convert_mnist_data.bin: error while loading shared libraries: libglog.so.0: cannot open shared object file: No such file or directory
I've noticed that liibglog.so.0 is not in /lib which might be the reason for it, but I'm not allowed to copy that file into /lib directory, since I'm not a root user.
Is there workaround for this?
The easiest way to work around the lack of shared libraries in system directories is to use LD_LIBRARY_PATH with the directory where the shared library lives.
Before running the the command that requires a library, run the following in the following the same shell.
export LD_LIBRARY_PATH=~/local/lib
You can also stick this in your .bashrc for convenience.
An alternate solution is to use the following command line flag while compiling, but that requires mucking with other people's build scripts.
-Wl,-rpath,$(DEFAULT_LIB_INSTALL_PATH)

c# program how to open file with double click

I have a C# program which works with files created by itself. The file can be opened by running the program and then accessing it via the GUI.
How can I open the file without having to run the program explicitly and just by double clicking on the concerned file?
You have to add registry entries in your installer to associate your program's file extension with your application.
Here is an article in MSDN that will tell you what you need to know about file associations: How File Associations Work
Typically you'd do this with your install, if you're not using an installer or ClickOnce, then you can do it from code, but you have to muck about in the registry: http://mel-green.com/2009/04/c-set-file-type-association/
You're asking how to associate a file type with your application. You can do this by adding entries to the registry using C#.

How to copy the contents of an FTP directory to a shared network path?

I have the need to copy the entire contents of a directory on a FTP location onto a shared networked location. FTP Task has you specify the exact file name (not a directory) and File System Task does not allow accessing a FTP location.
EDIT: I ended up writing a script task.
Nothing like reviving a really old thread... but there is a solution to this.
To copy the all files from a directory then specify your remote path to be /[directory name]/*
Or for just files and not directories /[directory name]/.
Or specific file types; /[directory name]/*.csv
I've had some similar issues with the FTP task before. In my case, the file names changed based on the date and some other criteria. I ended up using a Script Task to perform the FTP operation.
It looks like this is what you ended up doing as well. I'd be curious if anyone else can come up with a better way to use the FTP task. It's nice to have...but VERY limited.
When I need to do this sort of thing I use a batch file to call FTP on the command line and use the mget command. Then I call the batch from the DTS/DTSX package.