Getting the maximum (character) width of column

Getting the maximum (character) width of column

Post by Darius Blaszij » Tue, 09 Jan 2001 08:53:45



Hi there,

I wans wondering, is there a property or method which I can use to determine
what the maximum width of a query result (column) is?
When I have for instance a string type column (255 characters), the default
width of a DBGrid is somewhere about 1500 pixels. This is not what I mean.
What I mean is how many characters is the widest record of that column. This
question also concerns for number type and date/time type columns.

All I can think of is looping through each column and converting the
contents to string and then use the Length function.

Looking out for your ideas on this, Darius Blaszijk

 
 
 

Getting the maximum (character) width of column

Post by M.H. Avegaar » Tue, 09 Jan 2001 18:14:44


The 1500 pixels is an estimation of the actual width used by 255 characters.
There is no way to determine the maximum length of any value of a particular
field (besides looping through all values). You'll have to use your
knowledge of the contents of the field to estimate a better width (for
numbers and date/time fields you can just use the maximum witdth possible).

You can use the following procedure to determine the maximum amount of
pixels used by any value of a particular field.

var
  W, MaxW: Integer;
begin
  MaxW := 0;
  Table1.First;
  while not Table1.EOF do
  begin
    W := DBGrid1.Canvas.TextWidth(Table1.FieldByName('Field1').AsString);
    if MaxW < W then
      MaxW := W;
  end;
end;



Quote:> Hi there,

> I wans wondering, is there a property or method which I can use to
determine
> what the maximum width of a query result (column) is?
> When I have for instance a string type column (255 characters), the
default
> width of a DBGrid is somewhere about 1500 pixels. This is not what I mean.
> What I mean is how many characters is the widest record of that column.
This
> question also concerns for number type and date/time type columns.

> All I can think of is looping through each column and converting the
> contents to string and then use the Length function.

> Looking out for your ideas on this, Darius Blaszijk


 
 
 

1. Getting maximum character values in a populated column

Jorge,

What ever do you mean?

Do you want the maximum in terms of ASCII character code?
Do you want the one at the top of a dictionary sort?

Do you want the max value from the column, or from the data in the column?
In other words, if you have rows:

Hector
Isaac
Jacob

do you want Jacob?

Or if you have Hector, you want "t" because it's the 'max' character?

Need a little more to go on here.

James Hokes


2. Types of parameters in OCI

3. Getting column widths of listview

4. How to check for installed ADO

5. Query Analyser maximum characters per column

6. nvarchar and cascading deletes

7. fixed width - dynamically set column widths

8. Which DB ?

9. Maximum characters per column

10. Maximum characters per column - text file output

11. Total width of columns = Width of ListView

12. Maximum characters per column