Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Getting the longest
Thu, Sep 22 2011 11:35 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

I'm working on the fromt end for user reporting - the back end is FastReport.

What I do is extract the required data from the main files and stuff the result in a memory table. The user is then allowed to select the columns they want from this. Currently I generate a query showing the maximum characters in each column and then use

cTest.Canvas.TextWidth(StringOfChar('W', LineChars));

to work out the width of each column. I loop round testing font sizes from 12 down to 7 to try and fit it onto a single page width flipping from portrait to landscape if necessary.

My problem is I can't find a character or string that I'm sure will generate a width wide enough but not too wide (W is too wide, c isn't wide enough). What I'd like to do is get the longest string for each column. I can do this in a loop getting the string for each column in turn but I'd like to do it in one hit. I could cheat and have a select statement that is a load of select statements but I might as well use a loop (I'm guessing).

Can anyone come up with a suggestion?


Roy Lambert
Fri, Sep 23 2011 6:56 AMPermanent Link

Michael Riley

ZilchWorks

Avatar

>>
cTest.Canvas.TextWidth(StringOfChar('W', LineChars));

to work out the width of each column. I loop round testing font sizes
from 12 down to 7 to try and fit it onto a single page width flipping
from portrait to landscape if necessary.

My problem is I can't find a character or string that I'm sure will
generate a width wide enough but not too wide (W is too wide, c isn't
wide enough). What I'd like to do is get the longest string for each
column. I can do this in a loop getting the string for each column in
turn but I'd like to do it in one hit. I could cheat and have a
select statement that is a load of select statements but I might as
well use a loop (I'm guessing).

Can anyone come up with a suggestion?
<<

Courier or Courier New are both fixed width fonts. You could set the
initial size based on those fonts.

Why can't you use Landscape?

--
Michael Riley
GySgt USMC Retired
www.zilchworks.com
Fri, Sep 23 2011 7:26 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Michael


>Courier or Courier New are both fixed width fonts. You could set the
>initial size based on those fonts.

I could use those but I don't think the users would be very happy.

>Why can't you use Landscape?

I do. Try portrait first and if to big for that try landscape.

Roy Lambert


Fri, Sep 23 2011 3:53 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< My problem is I can't find a character or string that I'm sure will
generate a width wide enough but not too wide (W is too wide, c isn't wide
enough). What I'd like to do is get the longest string for each column. I
can do this in a loop getting the string for each column in turn but I'd
like to do it in one hit. I could cheat and have a select statement that is
a load of select statements but I might as well use a loop (I'm guessing).
>>

Well, without testing the *exact* characters being used, there really isn't
any guaranteed way of coming up with the optimal answer.  What you could do
is just loop through the alphanumeric characters before running the report,
and average their character widths using the selected font/size/style.
You'll then have an average character size, which will be about as good as
you can get, but will still suffer a bit if someone types in "Mmmmmm....".

--
Tim Young
Elevate Software
www.elevatesoft.com

Image