Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TPrinter and Column Names

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I am trying to create a report using the TPrinter object. The report shows the dates and times all the people in a group participated. There is a max of 10 days that the people could show up, but it could be less than that. I have created a TStringList to hold the unique dates that I need in the header of the report:

DateString:
2/22/06
2/23/06
2/24/06
2/27/06
2/28/06
3/2/06
3/6/06

I have created a set of constants that align to the columns on the page I am trying to print:
const
column0 = 3.75;
column1 = 4.375;
column2 = 5.0;
column3 = 5.625;
column4 = 6.25;
column5 = 6.875;
column6 = 7.5;
column7 = 8.1875;
column8 = 8.75;
column9 = 9.4375;
column10 = 10.0;

I would like to loop through the DateString and fill in only the ones that have a corresponding date. So in this example, only columns 0 - 6 need a date at the top. However, I can't seem to get the syntax correct for the loop to substitute 'i' for the last part of the column name. I have tried:

Code:
for i := 0 to DateString.Count - 1  do
  Printer.Canvas.TextOut((trunc([b](Column + IntToStr(i))[/b] * PixPerInX) - OffsetX), trunc((topmargin * PixPerInY) - OffsetY), DateString[i]);
    end;

I would expect the bold section above to return Column0 which correlates to the const Column0, but that didn't work. So I tried declaring ColumnName as a variant, but that bombed too.

Code:
for i := 0 to DateString.Count - 1  do
begin
  ColumnName := 'Column' + IntToStr(i);
  Printer.Canvas.TextOut((trunc([b]ColumnName[/b] * PixPerInX) - OffsetX), trunc((topmargin * PixPerInY) - OffsetY), DateString[i]);
end;

Does anyone know how I can accomplish this?

Thanks!

leslie
 
I figured it out!!!

I used a constant array:
Code:
Columns: array[0..9] of Double = (3.75, 4.375, 5.0, 5.625, 6.25, 6.875, 7.5, 8.1875, 8.75, 9.4375);

for i := 0 to DateString.Count - 1 do
      Printer.Canvas.TextOut((trunc(Columns[i] * PixPerInX) - OffsetX), trunc((topmargin * PixPerInY) - OffsetY), DateString[i]);

worked like a charm!
 
What you are trying to do is to assemble a constant name ("column0") at run-time, having the compiler interpreting it and using the value you assigned to it.

That is not possible.

In the way, you are trying to trunc a string, producing a type error.

Load your constants in an array instead and use MyArray.

Please, remember PASCAL is a compiled language, the compiler can't solve entity names at run time.

buho (A).


 
I think that's what I ended up doing, right?
 
Sorry, your second message was not there when I started to write mine one.

buho (A).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top