For the record I am living off the Delphi manuals at this
point and I must say they are extremely difficult to glean
good infomation from. I certainly plan on hitting the
bookstore soon.
In the interim, I'm just working on my first Delphi
utility. It's not very glorious, but it has given my
Delphi mind a workout. It's a small utility to generate
pages of simple math problems for my 5 yr. old. Eek, I
hate having to think up 36 math problems by hand... so....
I've gotten everything working, but getting the generated
problems to print correctly. I must admit that I don't
completely understand strings and char arrays in pascal,
and this sure makes printing them extremely difficult. Be
assured I have played with this for hours and I've tried
almost every possible combinations and options I've been
able to concieve. But I do have a couple of questions I'd
like to pose to anyone who can advise.
1: Strings. Is there a way to identify the end of the
string. Like '\0' in a C style array? I think I'm running
into problems, not accessing indexes directly, but when I
print strings of say string[80] but I've only used the
first 50 chars what identifies the end of my 50 char
string?
I realize the indexing runs from 1 to length and I've been
able to verify a particular string that I do use and index
on and it works as expected. But I'm indexing directly
and never printing the string as a whole. In fact it is
declared as string[4] but may only have 2 characters
stored in it.... and I'm using Length(identifier) to
find the lenght and it's been correct so far. But I read
somewhere, or got the impression anyway that changing the
[0] index might not be the best way to constrain the length
of the string. Is it simply ok to say set String[0]:=50 in
my example above?
2: I just do not understand printing output. I've been up
and down the TPrinter and TCanvas online documentation and
here is what I've come up with.
Printer.Canvas.TextOut(0, LineCount, Line1Out);
LineCount := LineCount + 1;
Printer.Canvas.TextOut(0, LineCount, Line2Out);
LineCount := LineCount + 1;
{Printer.Canvas.TextOut(0, LineCount, Line3Out);}
LineCount := LineCount + 4;
What I'm doing is generating randomly 4 problems and then
printing them across the page like for example:
3 5 10 23
-2 +2 + 5 -12
--- --- --- ---
If I remember correctly from pascal, I used to do something
like:
var
Printer: Text;
begin
writeln(Printer, "Hello");
But this does not seem to work... so I hit upon using
TextOut. The way I figure it I do all the "painting" on
the canvas before the Printer.EndDoc; but I am still
insuring that I print linearly to the printer. I don't
know if you can print on row 24 then to row 5 and have
things turn out correctly. One might expect you could
since the impression of the canvas would seem to work that
way. But, either way... the X, Y parameters in the TextOut
call seem to have no effect. I've made them constants...
no brainers like 0,0 and then 5,5... but the only line that
prints is the last call to TextOut. And it prints clear..
there is no layering of print.
Now there sure may be a better way to do this but to build
the LineXOut I'm simply doing it like:
Line1Out := ' ' + IntToStr(Operand1A) + ' ' +
IntToStr(Operand1B) + ' ' +
IntToStr(Operand1C) + ' ' +
IntToStr(Operand1D);
I did try:
Line2Out := Format('%s %d %s %d %s %d %s %d',
[OperatorString[OperatorA], Operand2A,
OperatorString[OperatorB], Operand2B,
OperatorString[OperatorC], Operand2C,
OperatorString[OperatorD], Operand2D]);
but I kept getting strange scratches at the end and above
the printed string.
My biggest concern is why do successive calls to TextOut
with different strings with different X,Y coordinates only
print the last call?
I've always found printing formatted strings directly to
the print to be a real pain in my side. I realize this may
be a lot to cover, but ANY insights are greatly
appreciated... and may just save the rest of my hair!!
TIA,
--
-- Jim Burns
Technology Dynamics
Pearland, Texas