procedure TForm1.BitBtn1Click(Sender: TObject);
var
변수 선언
begin
초기값 설정
With SQL do
Begin
//전체합 구하기
while not Qr_Item.Eof do---------------------------- ①
begin
P_Data_Total :=P_Data_Total + strtointdef(Qr_Item.FieldByName('sa_taxg').AsString,0);
Qr_Item.Next;
end;
while not eof do----------------------------------------- ②
begin
if
페이지 결정
end
if
5칸 마다 공백 2칸과 합 구하기
end
end
if
5칸 이하의 공백과 합 구하기
end
end
총합구하기
end
이런식으로 구성이 되어 있습니다.
그런데 위의 ② while문만 가지고 하면 잘 프린트가 되는데
①while를 추가해서 실행하면 에러가 발생합니다. 왜 에러가 나줄 이유를 모르겠습니다. 선배님들 도와 주세요...
전체 소스는 몇에 공개 하겠습니다. 많은 충고 부탁합니다.
---- 소스
unit oneproject;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, DB, DBTables, Grids, DBGrids, StdCtrls,Buttons,
printers;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Qr_Item: TQuery;
DBNavigator1: TDBNavigator;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
i,j :Integer;
P_Head : String;//타이틀 헤드
P_Titl : String;//목록제목
P_Data: String; //DB에서 불러온값.
//
P_Sum : String;//합계
P_ASum: String;//총합계
sa_taxg,sa_taxg2:Integer;//5개마다 합계
bi_sa:Real;
iTotal: integer;//전체합
P_Data_Total: integer;
begin
//초기설정값...
iTotal := 0;
sa_taxg :=0;
bi_sa:=0;
sa_taxg2 :=0;
P_Data_Total:=0;
P_Head :='거 래 처 리 스 트';
//자리 지정 %-12s는 간격 , code,1,12 글자의 공간
P_Titl := Format('%-12s' , [copy('Code',1, 12)])+' '+
Format('%-13s', [copy('상호명',1, 13)])+' '+
Format('%-20s', [copy('사업자번호',1,20)])+' '+
Format('%-12s', [copy('대표자',1,12)])+' '+
Format('%-20s', [copy('종목',1,20)])+' '+
Format('%-5s', [copy('Taxg',1,5)]);
Printer.BeginDoc;//Start
//제목
printer.Canvas.Font.Size := 14;//폰트
Printer.Canvas.Font.Name := '굴림체';//글자체
Printer.Canvas.TextOut(1200,70,P_Head);//그림판위에 테스트 행태로 값을
Printer.Canvas.Pen.Width :=5;
Printer.Canvas.pen.Color := clBlack;
Printer.Canvas.pen.Style := psSolid;
Printer.Canvas.MoveTo(1200,190);
Printer.Canvas.LineTo(2200,190);
//목록
printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Name := '굴림체';
Printer.Canvas.Pen.Width :=5;
Printer.Canvas.pen.Color := clBlack;
Printer.Canvas.pen.Style := psSolid;
Printer.Canvas.MoveTo(20,320);
Printer.Canvas.LineTo(3650,320);
Printer.Canvas.TextOut(20,350,P_Titl);
Printer.Canvas.Pen.Width :=5;
Printer.Canvas.pen.Color := clBlack;
Printer.Canvas.pen.Style := psSolid;
Printer.Canvas.MoveTo(20,450);
Printer.Canvas.LineTo(3650,450);
Close;
With Qr_Item do
Begin
Close;
Qr_Item.SQL.Clear;
Qr_Item.SQL.Add('select sa_code,sa_sona, sa_saup, sa_king,sa_jong, ');
Qr_Item.SQL.Add('sa_taxg from Safl');
Qr_Item.Open;
Qr_item.First;
i:=0;
j:=0;
//전체합 구하기
while not Qr_Item.Eof do
begin
P_Data_Total :=P_Data_Total + strtointdef(Qr_Item.FieldByName('sa_taxg').AsString,0);
Qr_Item.Next;
end;
while not Eof do
Begin
i:=i+1;
j:=j+1;
P_Data := Format('%-12s',[Copy(Qr_Item.FieldByName('sa_code').AsString,1,12)])+' '+
Format('%-13s',[Copy(Qr_Item.FieldByName('sa_sona').AsString,1,13)])+' '+
Format('%-20s',[Copy(Qr_Item.FieldByName('sa_saup').AsString,1,20)])+' '+
Format('%-12s',[Copy(Qr_Item.FieldByName('sa_king').AsString,1,12)])+' '+
Format('%-22s',[Copy(Qr_Item.FieldByName('sa_jong').AsString,1,20)])+' '+
Format('%-5s',[Copy(Qr_Item.FieldByName('sa_taxg').AsString,1,5)]);
//합계 구하기(총 합계와 5개마다 합계)...
//5개 합계
sa_taxg :=sa_taxg + strtointdef(Qr_Item.FieldByName('sa_taxg').AsString,0);
//총 합계
iTotal := iTotal + strtointdef(Qr_Item.FieldByName('sa_taxg').AsString,0);
//데이터값
Printer.Canvas.Font.size := 10;
Printer.Canvas.Font.Name := '돋움체';
Printer.Canvas.TextOut(20,400+(i*80),P_Data);
//70칸 마다 다음 페이지로
if i > 70 then
Begin
//l := l+1;
printer.Canvas.TextOut(20,90,'');
Printer.NewPage;
//제목
printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Name := '굴림체';
Printer.Canvas.Pen.Width :=5;
Printer.Canvas.pen.Color := clBlack;
Printer.Canvas.pen.Style := psSolid;
Printer.Canvas.MoveTo(20,320);
Printer.Canvas.LineTo(3650,320);
Printer.Canvas.TextOut(20,350,P_Titl);
Printer.Canvas.Pen.Width :=5;
Printer.Canvas.pen.Color := clBlack;
Printer.Canvas.pen.Style := psSolid;
Printer.Canvas.MoveTo(20,450);
Printer.Canvas.LineTo(3650,450);
i :=1;
j:=0;
end;
//5칸 마다 줄 삽입
if j > 4 then
Begin
Printer.Canvas.Pen.Width :=5;
Printer.Canvas.pen.Color := clBlack;
Printer.Canvas.pen.Style := psDot;
Printer.Canvas.MoveTo(20,490+(i*80));
Printer.Canvas.LineTo(3650,490+(i*80));
//bi_sa:= sa_taxg/P_Data_Total;
P_sum :=Format('%-25s',[Copy('',1,25)])+' '+
Format('%-54s',[Copy('합계',1,54)])+' '+
Format('%-10s',[Copy(inttostr(sa_taxg),1,5)])+' '+
Format('%-10s',[Copy(floattostr(bi_sa),1,5)]);
Printer.Canvas.TextOut(20,500+(i*80),P_sum); //합계
bi_sa:=0;
sa_taxg :=0; //초기화
j :=0;
i :=i+2; //여백주기
end;
Qr_Item.Next;
end;
if j <= 4 then
Begin
bi_sa:= sa_taxg/iTotal;
P_sum :=Format('%-25s',[Copy('',1,25)])+' '+
Format('%-54s',[Copy('합계',1,54)])+' '+
Format('%-10s',[Copy(inttostr(sa_taxg),1,5)])+' '+
Format('%-10s',[Copy(floattostr(bi_sa),1,5)]);
Printer.Canvas.TextOut(20,500+(i*80),P_sum); //합계
bi_sa:=0;
sa_taxg := 0;
j :=0;
i := i+2;
end;
Close;
end;
//총 합계...
P_Asum :=Format('%-25s',[Copy('',1,25)])+' '+
Format('%-54s',[Copy('총합계',1,54)])+' '+
Format('%-10s',[Copy(inttostr(iTotal),1,5)]);
Printer.Canvas.Pen.Width :=5;
Printer.Canvas.pen.Color := clBlack;
Printer.Canvas.pen.Style := psSolid;
Printer.Canvas.MoveTo(20,510+(i*80));
Printer.Canvas.LineTo(3650,510+(i*80));
Printer.Canvas.TextOut(20,530+(i*80),P_Asum);
printer.EndDoc; //End
end;
end.
Error가 나는 것이 아니라 출력이 안되는게 아닌지...
//전체합 구하기
while not Qr_Item.Eof do
begin
P_Data_Total :=P_Data_Total + strtointdef(Qr_Item.FieldByName('sa_taxg').AsString,0);
Qr_Item.Next;
end;
Qr_Item.First; <======== Eof에 와있을테니까 ....