[DUG] Rave printing
Willie Juson
willie.juson at satara.co.nz
Wed Oct 13 09:31:00 NZDT 2010
Hi,
Really Ugly suggestion No 1
Put in a try.. except around the offending code and do nothing in the exception handling part of the construct i.e. it should still cause an exception but you'll "handle" it invisibly and it won't raise, at least not at runtime, debugging is still a pain though.
I think this is generally considered bad coding practice so I'll probably get shot down in flames for suggesting it
Alternately check the corresponding field's datatype, something along the lines of....
ThisField:=lDBGrid.Columns[colptr].Field;
If ThisField.DataType in [ftString, ftCurrency....] then
if not ThisField.IsNull then
lText:=lDBGrid.Fields[colptr].asString; <==access violation
end;
It's probably easier to check the valid fieldtypes rather than the invalid ones as there's currently about 51 to choose from, most of which you don't want to know about.
-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On Behalf Of John Bird
Sent: Tuesday, 12 October 2010 10:02 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: [DUG] Rave printing
?I have a generalised routine for printing forms using Rave reports D2007.
I struck an interesting problem printing contents of a DBGrid showing
columns from a MSSQL database - I think its because the fields are null or a
type (eg binary) that ClientDataSets cannot display. Printing that column
gives an access violation. I want to have it print nothing of course for a
column with invalid or null or blank data, haven't yet figured out how to
skip them.
Here is the essential code that prints the columns of the grid, (I have
already set tab positions scaled to widths of the columns).
- I think this particular column (column 4 in this case) has nulls.
[here lcds is a TClientDataSet, lDBGrid is a TDBGrid, ThisField is aTField]
for rowptr := 1 to comprowmax do
begin
lcds.RecNo:=rowptr; //have to move around dataset
for colptr := 0 to compcolmax do
begin
ltext:='';
//column may not have a field associated...
if lDBGrid.Columns[colptr].Fieldname <> '' then
begin
ThisField:=lDBGrid.Columns[colptr].Field;
if not ThisField.IsNull then
lText:=lDBGrid.Fields[colptr].asString; <==access violation
end;
printtab(ltext);
end;
println('');
end;
Any ideas how to bullet proof this?
John
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: unsubscribe
More information about the Delphi
mailing list