Board index » delphi » Writing constant header to file

Writing constant header to file

Hi,

I have a problem that should be really easy to solve, but I just
can't figure it out. I want to make a program that outputs a file
which always look the same, except for a few bytes at the end. So
my question is: How do I include the contents of the huge file
that I want to use into my BP program, and how do I then copy it
to every file that the program creates.

Thanks for any help!

//Mattias Lindqvist

 

Re:Writing constant header to file


Quote
In article <eng96gml.46.00102...@lustudat.student.lu.se> Mattias Lindqvist wrote:
>Hi,

>I have a problem that should be really easy to solve, but I just
>can't figure it out. I want to make a program that outputs a file
>which always look the same, except for a few bytes at the end. So
>my question is: How do I include the contents of the huge file
>that I want to use into my BP program, and how do I then copy it
>to every file that the program creates.

Regardless of the file content, you can use binobj to convert
it into an OBJ and link the OBJ onto you program.  Note the
size (byte count) reported by binobj and add that as a
constant to your program.

For example, I want to write a WordPerfect 5.1 compatible
document that includes a few dozen styles in addition to the
usual header info.  My first step is to capture the header by
save an empty document.  The next step is to convert the file
Using "binobj header.w51 header.obj header".  The last step
is to put all the pieces into the program -

{$L HEADER.OBJ }

PROCEDURE Header; external;
CONST HeaderSize = 5868;

Simply use BlockWrite to write the embedded object
   BlockWrite(F, Addr(Header)^, HeaderSize);

An alternate solution if you have TP 6.0 or 7.0 is to enable
extended syntax and write to the data using a pChar.

FUNCTION CommonData; pChar; Assembler;
ASM
    call @Exit
    db 'whatever text needs to be included',13,10
    db 'more text',13,10
    { ...... }
    db 0 { <--<< nul delimiter }

@Exit:  
    push CS
    pop  DX
    pop  AX
END;

To write the data to a text file, simply use
   Write(F, CommonData);

To an untyped file use
   BlockWrite(F, CommonData^, StrLen(CommonData));

By creating the data as a function that returns the address
of the data, the routine can be included as part of an
overlay and remain compatible even if the overlay admin data  
is changed in future versions.  The rule for overlaying data
in the code segment is that once the address is taken no
subsequent statement can use overlaid code outside the
current unit to process data.  Since you didn't overlay the
system unit and nothing the system's unit uses is overlaid,
the above is acceptable.

Since you are treating the data as read-only, both techniques
are compatible with protected mode and you don't have to
worry about converting the selector.  

Both of the above examples assume that the huge file isn't so
large that it cannot be contained within the limits of a
unit or a nul terminated string.  If the data is larger, then
it would probably be easier to it as an external file and
copy it and append the new information.

Hope some of this helps.

    ...red

Other Threads