Solved

pack a file...

Posted on 2003-11-08
3
191 Views
Last Modified: 2010-04-05
how can i pack a file within my application and on button click extract it to a certain path and run it (and close my app.)....
I have a screensaver that would like to send to a friend but she does not now how to put it into C:\Windows\System32
and run it ...
So I tought to send her an app to do it for her.
(windmill.scr)
Help appreciated...
Is it possible to use rxlib file storage thing ?
0
Comment
Question by:senad
  • 2
3 Comments
 

Expert Comment

by:Karamja
ID: 9708397
Hello,

Making RC File:
In notepad,
ScreenSaver RCDATA "FullPathToScreenSaver"
Save As ScreenSaver.rc
------
.RC To .RES:
In run box type,
Brcc32 "PathToRCFile"
------
In Project:

Var
ResStream : TResourceStream;
FileStream : TFileStream;

{$r ScreenSaver.RES}

Add this to button to unpack screensaver,

ResStream := TResourceStream.Create(0, 'ScreenSaver', RT_RCDATA);
try
FileStream := TFileStream.Create('C:\Windows\System32\windmill.scr', fmCreate);
try
FileStream.CopyFrom(ResStream, 0);
finally
FileStream.Free;
end;
finally
ResStream.Free;
end;
0
 
LVL 2

Expert Comment

by:SaLz
ID: 9710164
Make a Folder Called RC in "C:\RC\"

Put the file you are wanting to add into your program for extraction.

for example, you put a image in the folder, called home.jpg

now once you have put your file into the folder, open up a notepad.

in the notepad type this in.

HOME RCDATA "C:\rc\home.jpg"

now save as any name you want, call it home.rc but make sure you rename the txt file as .rc
home.txt should be home.rc

Now Open up Command Prompt.
Type "brcc32 C:\RC\home.rc" (with out brackets)
Press Enter...
Now it has complied you the res as home.res.

Now Move the home.res to your projects folder.

Now open your project,
where you see {$R *.dfm} put your home.res below that like this

{$R *.dfm}
{$R home.res}

now when you compile your project it will me inside your exe, now you want to extract it to a location.

procedure TForm1.Button1Click(Sender: TObject);
begin
ResStream := TResourceStream.Create(0, 'Details', RT_RCDATA);
try
FileStream := TFileStream.Create('C:\rc\HomeExtracted.txt', fmCreate);
try
FileStream.CopyFrom(ResStream, 0);
finally
FileStream.Free;
end;
finally
ResStream.Free;
end;
end;
0
 
LVL 2

Accepted Solution

by:
SaLz earned 250 total points
ID: 9710174
it should be home than details my bad english.

procedure TForm1.Button1Click(Sender: TObject);
begin
ResStream := TResourceStream.Create(0, 'home', RT_RCDATA);
try
FileStream := TFileStream.Create('C:\rc\HomeExtracted.jpg', fmCreate);
try
FileStream.CopyFrom(ResStream, 0);
finally
FileStream.Free;
end;
finally
ResStream.Free;
end;
end;
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now