Board index » delphi » converting: Array [] of Char -> PChar

converting: Array [] of Char -> PChar

How can I convert an Array [1..8192] of Char to a PChar?

I am writing a utility to read a file and send its contents to the
printer.  The file can be anything, including binary, and so strings are
not appropriate, because of their size restriction.

I am using the BlockRead function, with a buffer size of 8192 to read
the file.  Unfortunately there is no equivalent function for printing so
I am using 'write' to send the stuff to the printer.  However,
write(Myprinter, CharArray) does not work (could it be made to?) so I am
iterating through each character- takes an eternity.

I would like to convert the CharArray to PChar and then print the PChar.
How?

I'm using 16-bit delphi, BTW.

Thanks for any help

Olly Morgan
Scottish Agricultural College

 

Re:converting: Array [] of Char -> PChar


Quote
o...@tattoo.ed.ac.uk (O Morgan) wrote:
>How can I convert an Array [1..8192] of Char to a PChar?

>I am writing a utility to read a file and send its contents to the
>printer.  The file can be anything, including binary, and so strings are
>not appropriate, because of their size restriction.

If the file can be _anything_, a PChar won't be apropriate either
because the first #0 byte will be taken as the terminator and
nothing after that will be sent to the printer.

Quote
>I am using the BlockRead function, with a buffer size of 8192 to read
>the file.  Unfortunately there is no equivalent function for printing so
>I am using 'write' to send the stuff to the printer.  However,
>write(Myprinter, CharArray) does not work (could it be made to?) so I am
>iterating through each character- takes an eternity.

Presumably Myprinter is a printer disguised as a text file rather than
a TPrinter. You could reduce the number of times through the loop
by sending up to 255 bytes at a time as a string; in fact Write()
will output more than one variable per call so you can do better still.

Quote

>I would like to convert the CharArray to PChar and then print the PChar.
>How?

>I'm using 16-bit delphi, BTW.

>Thanks for any help

>Olly Morgan
>Scottish Agricultural College

--
Best wishes

John Nurick

e-mail: j.nur...@dial.pipex.com
v-mail: <+44|0> 191 281 1306

Re:converting: Array [] of Char -> PChar


In article <4pjboj$...@scotsman.ed.ac.uk>, O Morgan
<o...@tattoo.ed.ac.uk> writes

Quote
>How can I convert an Array [1..8192] of Char to a PChar?

>I am writing a utility to read a file and send its contents to the
>printer.  The file can be anything, including binary, and so strings are
>not appropriate, because of their size restriction.

>I am using the BlockRead function, with a buffer size of 8192 to read
>the file.  Unfortunately there is no equivalent function for printing so
>I am using 'write' to send the stuff to the printer.  However,
>write(Myprinter, CharArray) does not work (could it be made to?) so I am
>iterating through each character- takes an eternity.

>I would like to convert the CharArray to PChar and then print the PChar.
>How?

Start your array index from 0 to 8192

Array [0..8192] of Char - now its a PChar;

HTH
--
Nicholas Robinson

Re:converting: Array [] of Char -> PChar


Quote
Nicholas Robinson <NRo...@demon.com> wrote:
>Start your array index from 0 to 8192
>Array [0..8192] of Char - now its a PChar;

Just make sure the last byte has a null character to identify the end
of the string.
-------------------------------
Thomas Paul
TOMG...@Pipeline.Com
Dean Witter, Discover & Co.
New York City, NY USA
----------------------------------

Re:converting: Array [] of Char -> PChar


In article <4q4gld$...@news1.t1.usa.pipeline.com>, Thomas Paul
<TOMG...@PIPELINE.COM> writes

Quote
>Nicholas Robinson <NRo...@demon.com> wrote:

>>Start your array index from 0 to 8192

>>Array [0..8192] of Char - now its a PChar;

>Just make sure the last byte has a null character to identify the end
>of the string.

Although I use this and have never had any problems I can see that it is
logical to place the #0 byte at the end.  I did actually think that
Delphi checked the begining index and if 0 placed its one null char.

Anyway, thanks for the tip and I will use it from now on - just to make
sure.
--
Nicholas Robinson

Other Threads