Resource File Problem

I have a app that gets strings from a resource file.  The app downloads a new resource file and copies it over the old.  teh next time the app gets started, it should read from the new resource file, but it seems to still read from the old file.  Do I need to free the resource file?  Is the resource file call case sensitive?  Please help...
MichaelB98Asked:
Who is Participating?
 
jerrypslConnect With a Mentor Commented:
Resource file is linked to the executable when you build your project, thus you need to
do a full rebuild if you change your resource contents later. In D4, go to Project menu then
click on Build All Projects, for D3 i think it's something like "Rebuild Project" (not sure).

Q: After I made a change to my resource file, I pressed F9 to recompile my project, but why the application still using the old resource instead of the new one?
Ans: Although you press F9 after you change your resource contents to recompile the project, the .exe will still contain the old resources because the compiler detects no changes in your source code and thus just run the .exe without rebuilding it.

0
 
dwwangCommented:
A resource file is built into the exe, so if you load resources from it, it will always be the "old" ones.

0
 
viktornetCommented:
Oh, is that what you had in mind??? As dwwang said the RES file is build into the EXE file and even if you supply the res file it doesn't read from it... You need to use LoadResource() or whatever that is,.. It's not that easy to do what you want.... I'll try to think and probably tell you what I got tomorrow,,, You cannot free a resouce since it's freed by itself.

Regards,
Viktor Ivanov
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
LischkeCommented:
What about creating a resource DLL? Just create an empty DLL project and include your resources there. In your application you can use LoadLibrary (which hasn't necessarily to have the DLL extension) to load it. This call will return a HInstance handle, which you can use in LoadString to actually load the string. By replacing this resource DLL you can update all strings (this works also very well for other resources too, like icons, bitmaps and the like, but with different calls to load them).

procedure TMainForm.LoadRes(FileName: String);

var Handle: HInst;
    Buffer : array[0..255] of Char;

begin
  Handle:=LoadLibrary(FileName);
  if Handle > 0 then
  begin
    LoadString(Handle,ResIDOfString,Buffer,SizeOf(Buffer));
    StringList.Add(Buffer);
  end;
  FreeLibrary(Handle);
end;

See also LoadMenu, LoadBitmap, LoadAccelerator, LoadResource etc. for other types of resources.

Ciao, Mike
0
 
MichaelB98Author Commented:
My simplest solution I guess is to make it read from an ini file instead.  The onlt problwm with the dll idea, is I am letting someone make the updates for the app and now they have to have a copy of Delphi ( or another language ) AND know how to use it.  I was hoping for something easy.

Michael
0
 
LischkeCommented:
Ooops, you didn't say that some third party will create your resources. I was assuming that you are the only one who's changing them. And you have indeed a Delphi copy since you have developed the application.

For simple string updates a plain text file may do it, but for other resources you will have to find an more complex solution (like separate files for each resource type etc.).

Creating a resource DLL which contains any type of resources which are in res files is so easy, you could do that in a few minutes.

Ciao, Mike
0
All Courses

From novice to tech pro — start learning today.