Page 1 of 1

Printing form DBGrid in delphi 7

Posted: 01 Jan 2014, 19:18
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.

Re: Printing form DBGrid in delphi 7

Posted: 03 Jan 2014, 09:07
by rustypup
what have you tried?

not big on delphi, but i do know it's printing API is quite capable...

Re: Printing form DBGrid in delphi 7

Posted: 07 Jan 2014, 20:52
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.