1procedure CreateResourceFile(
2 DataFile, ResFile: string;
3 ResID: Integer
4);
5var
6 FS, RS: TFileStream;
7 FileHeader, ResHeader: TResHeader;
8 Padding: array[0..SizeOf(DWORD)-1] of Byte;
9begin
10
11
12 FS := TFileStream.Create(
13 DataFile, fmOpenRead);
14 RS := TFileStream.Create(
15 ResFile, fmCreate);
16
17
18
19 FillChar(FileHeader, SizeOf(FileHeader), #0);
20 FileHeader.HeaderSize := SizeOf(FileHeader);
21 FileHeader.ResId := $0000FFFF;
22 FileHeader.ResType := $0000FFFF;
23
24
25
26
27
28 FillChar(ResHeader, SizeOf(ResHeader), #0);
29 ResHeader.HeaderSize := SizeOf(ResHeader);
30
31 ResHeader.ResId := $0000FFFF or (ResId shl 16);
32
33 ResHeader.ResType := $0000FFFF
34 or (WORD(RT_RCDATA) shl 16);
35
36 ResHeader.DataSize := FS.Size;
37
38 ResHeader.MemoryFlags := $0030;
39
40
41 RS.WriteBuffer(FileHeader, SizeOf(FileHeader));
42 RS.WriteBuffer(ResHeader, SizeOf(ResHeader));
43
44
45 RS.CopyFrom(FS, FS.Size);
46
47
48
49 if FS.Size mod SizeOf(DWORD) <> 0 then
50 RS.WriteBuffer(Padding, SizeOf(DWORD) -
51 FS.Size mod SizeOf(DWORD));
52
53
54 FS.Free;
55 RS.Free;
56end;