Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to embed binary data in an executable (2) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
20-Oct-02
Category
Files Operation
Language
Delphi 2.x
Views
149
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Is is possible to somehow embed an external executable file in a Delphi program? Or 
maybe another type of file for that matter like a zip file for instance. I want the 
file to be extractable from my program later on so that I can use it on another 
system.

Answer:

Here is a simple little component where you can save a file in the form file. You 
can add compression/decompression/encryption or whatever you like, but this 
demonstrates a possible storage process for data. Quick and simple to use.

1   unit Unit2;
2   
3   interface
4   
5   uses
6     Classes, Sysutils;
7   
8   type
9     TFileResourceComponent = class(TComponent)
10    private
11      FStream: TMemoryStream;
12      FFileName: TFileName;
13      procedure SetFileName(const Value: TFileName);
14      procedure ReadData(Stream: TStream);
15      procedure WriteData(Stream: TStream);
16    public
17      procedure DefineProperties(Filer: TFiler); override;
18      constructor Create(AOwner: TComponent); override;
19      destructor Destroy; override;
20    published
21      property FileName: TFileName read FFileName write SetFileName;
22    end;
23  
24  procedure register;
25  
26  implementation
27  
28  procedure register;
29  begin
30    RegisterComponents('REDSYS', [TFileResourceComponent]);
31  end;
32  
33  { TFileResourceComponent }
34  
35  constructor TFileResourceComponent.Create(AOwner: TComponent);
36  begin
37    inherited;
38    FStream := TMemoryStream.Create;
39  end;
40  
41  procedure TFileResourceComponent.DefineProperties(Filer: TFiler);
42  begin
43    inherited;
44    Filer.DefineBinaryProperty('Data', ReadData, WriteData, True);
45  end;
46  
47  destructor TFileResourceComponent.Destroy;
48  begin
49    inherited;
50    FStream.Free;
51  end;
52  
53  procedure TFileResourceComponent.ReadData(Stream: TStream);
54  begin
55    if not (csDesigning in ComponentState) then
56      FStream.CopyFrom(Stream, Stream.Size);
57  end;
58  
59  procedure TFileResourceComponent.SetFileName(const Value: TFileName);
60  begin
61    FFileName := Value;
62  end;
63  
64  procedure TFileResourceComponent.WriteData(Stream: TStream);
65  var
66    FS:
67    TMemoryStream;
68  begin
69    if FileExists(FFileName) then
70    begin
71      FS := TMemoryStream.Create;
72      try
73        FS.LoadFromFile(FFileName);
74        Stream.CopyFrom(FS, FS.Size);
75      finally
76        FS.Free;
77      end;
78    end;
79  end;
80  
81  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC