Printing form DBGrid in delphi 7

All topics about coding, designing, etc. goes in here.
Post Reply
Cyberduke
Registered User
Posts: 83
Joined: 08 May 2011, 10:46

Printing form DBGrid in delphi 7

Post by Cyberduke »

Hello, I am currently as an project for school writing a program in delphi 7 that uses an database that I created in acces. The problem is that I have to be able to print the output after filtering data on the dbGrid. Now the newer versions of delphi I believe is easier to do that with. But I am stuck with 7. One option is to loop all data into an textfile or rich edit but why do so much trouble if there is an easier way? any help would be appreciated please.
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: Printing form DBGrid in delphi 7

Post by rustypup »

what have you tried?

not big on delphi, but i do know it's printing API is quite capable...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Cyberduke
Registered User
Posts: 83
Joined: 08 May 2011, 10:46

Re: Printing form DBGrid in delphi 7

Post by Cyberduke »

I have since sorted the problem after trying endless possibilities this code works
Here is the entire procedure for the printing.

procedure TForm1.btnPrintAkedemieClick(Sender: TObject);
var
printDialog : TPrintDialog;
k : Integer;
sSpacer : string;
tPrintAnder : TextFile;
begin
for k := 1 to 25 do
sSpacer := sSpacer + '*';

printDialog := TPrintDialog.Create(Form1);

if printDialog.Execute then
begin
AssignPrn(tPrintAnder);
ReWrite(tPrintAnder);

Writeln(tPrintAnder,sFilter);
Writeln(tPrintAnder,'No', ' ' : 2, 'Naam', ' ' : 16 , 'Van');
Writeln(tPrintAnder,sSpacer);
k := 1;
with DataModule1 do
begin
tblPHS_Ander.Open;
tblPHS_Ander.First;
while not tblPHS_Ander.Eof do
begin
Writeln(tPrintAnder,IntToStr(k), '.' ,' ' : 3 -length(IntToStr(k)),tblPHS_Ander ['Naam'], ' ' : 20 - Length(tblPHS_Ander ['Naam']), tblPHS_Ander ['Van']);
tblPHS_Ander.Next;
Inc(k);
end;
end;
closefile(tPrintAnder);
end;
end;

I just have since developed 2 more questions.
1. How to I change the font to print in? Certain fonts don't format right thanks to the fact that every letter uses a different amount of space. As you probably know.
2. I want to put this piece of code into an custom procedure because I have to print with the exact same code but from 4 different Tables. Now the part where I am stuck is what type of variable the name of the table should be? I have tried string but as i thought that didn't worked.
Post Reply