Advertisement
Advertisement
| 03.17.2008 at 01:09AM PDT, ID: 23246367 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 03.17.2008 at 01:14AM PDT, ID: 21140423 |
| 03.17.2008 at 01:14AM PDT, ID: 21140428 |
| 03.17.2008 at 01:15AM PDT, ID: 21140429 |
| 03.17.2008 at 01:29AM PDT, ID: 21140471 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: |
This tip is similar to yesterday's and added upon request. There are
several times when I need to send out a
quick printout of a TDBGrid without having to worry about writting a
report for it. There are a couple
different ways of approaching this, we will be looking at the Delphi
function AssignPrn(). Using
AssignPrn() we can write to the printer as if we are writting to a file
using WriteLn(). In this tip we will
have to change the printer font to a fixed width font so our printout
will have straight even columns. We will
be using the Delphi functions Format(), AssignPrn(), WriteLn(),
Rewrite(), and CloseFile().
For this tip we will need a TButton with a TButton.OnClick event
along with a TStringGrid
component. You can easily create these events through the Events tab
of the Object Inspector.
First we will need to make sure we add Printers to our Units uses
clause.
In our TButton.OnClick event we will first set our
TPrinter.PrinterIndex to default printer by setting
this value to -1.
Next we will be saving our printers font and resetting it to
'Courier New', a fixed width font. This will
make our columns print in a straight even line using the Format()
Delphi function.
Next we will assign our printer textfile to our printer using
AssignPrn().
After assigning our file we need to initialize it using Rewrite().
Before we loop through the TDBGrid rows, we will print out our
header and a row of dashes to
seperate the header in our printout from the rest of the rows. We
printout the DBGrid's table fieldnames
as the header.
We will use the Delphi function WriteLn() to printout each row to
our assigned printer file. To format
the rows properly we will use the Delphi function Format() and input
all our columns into a formatted
string.
Next we will loop through our TDBGrid and printout each row in the
same fashion as we did with the
header row.
Finally we will need to close the file handle we created with
AssignPrn() and rest our printer font to
its original value..
Format() returns a string formated according to arguments that you
send in. Format() can get quite
complex. Format looks to add the arguments in the order arranged
into the next position in order
according to the percent sign "%" in your format string. In other
words, you need as many arguments as
you have percent signs in your format string parameter. The number
after the percent sign indicates the
max number of characters that will display. When you add a number, a
period, and a number then this
indicates that you want to force that number of characters as
percision. In other words if you want two
characters and your argument only returns one then the return forces
in a leading character whether it be
a space for a string or a zero "0" for a numeric value. The "s" at
the end of our width and percision
indicates that our argument will be passing in a string value to be
formated into that position. Take a
look at the Delphi help file to see all the other values you can
pass in through the argument parameter.
AssignPrn() assigns a textfile variable to the printer. The only
parameter is the textfile variable.
Rewrite() creates a new file and opens it. The only parameter is the
assigned textfile variable.
WriteLn() writes a line of text to our textfile variable. The first
parameter is the string to write. The
second parameter is the textfile variable to write to.
CloseFile() gets rid of the association between our textfile and the
printer file. The only parameter is
our assigned textfile variable.
Example 1
{...}
type
TForm1 = class(TForm)
Button1: TButton;
DBGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{...}
procedure TForm1.Button1Click(Sender: TObject);
var
MyTextFile : TextFile;
tmpStr,OldFont : String;
begin
{ set to default printer }
Printer.PrinterIndex := -1;
{ save the printers old font }
OldFont := Printer.Canvas.Font.Name;
{ set the printers font name to a fixed
width font so the printout will have
even looking columns }
Printer.Canvas.Font.Name := 'Courier New';
{ assign our textfile to the printer }
AssignPrn(MyTextFile);
try
{ initialize our textfile }
Rewrite(MyTextFile);
{ format and print out our header according
to the fieldnames, I only have 2 fields in
my table..you will have to add entries to
the Format() if you have more fields }
tmpStr := Format('%-20.20s %-20.20s',
[dbGrid1.DataSource.DataSet.Fields[0].FieldName,
dbGrid1.DataSource.DataSet.Fields[1].FieldName]);
Writeln(MyTextFile, tmpStr);
{ format and print out a seperator between
the header and rows }
tmpStr := Format('%-20.20s %-20.20s',
['--------------------',
'--------------------']);
Writeln(MyTextFile, tmpStr);
{ start at the first record in the DBGrid's table }
dbGrid1.DataSource.DataSet.First;
{ loop through the DBGrid's table, if the table is
too large then you may want to filter it down }
while ( not dbGrid1.DataSource.DataSet.EOF ) do
begin
{ format each row and print them out }
tmpStr := Format('%-20.20s %-20.20s',
[dbGrid1.DataSource.DataSet.Fields[0].AsString,
dbGrid1.DataSource.DataSet.Fields[1].AsString]);
Writeln(MyTextFile, tmpStr);
{ go to the next record in the DBGrid's table }
dbGrid1.DataSource.DataSet.Next;
end;
finally
{ close our textfile }
CloseFile(MyTextFile);
{ reset the printers font name }
Printer.Canvas.Font.Name := OldFont;
end;
end;
{...}
|
| 03.17.2008 at 01:31AM PDT, ID: 21140479 |
| 03.17.2008 at 02:24AM PDT, ID: 21140681 |
| 03.17.2008 at 05:02AM PDT, ID: 21141369 |
| 03.17.2008 at 05:29AM PDT, ID: 21141508 |
| 03.17.2008 at 06:00AM PDT, ID: 21141702 |
| 03.17.2008 at 06:14AM PDT, ID: 21141805 |
| 03.18.2008 at 05:32AM PDT, ID: 21150226 |
| 03.18.2008 at 10:41PM PDT, ID: 21158762 |
| 04.18.2008 at 01:29PM PDT, ID: 21389379 |