Autor Beitrag
elduchte
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: Fr 20.06.03 14:32 
Hallo,
ich habe es endlich geschafft, eine bestehende Datenbank (unter ACCESS) in mein Delphi-Programm einzubinden. Ist ja auch ganz einfach, wenn ich mal drüber nachdenke....

Allerdings habe ich jetzt noch einen Wunsch: Ich möchte den Inhalt, der in DBGrid dargestellt wird auch ausdrucken können und zwar mit dem Gitternetz. Habe schon einige Versuche hinter mir, bekomme aber immer nur ein leeres Blatt...... Gibt es auch die Möglichkeit, eine Druckansicht zu erstellen?

Gibt es für mein Problem irgendwo ein Tutorial ?

Vielen Dank für Eure Hilfe
Andreas
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Fr 20.06.03 14:48 
hallo andi!

ein stringgrid kannst --> so ausdrucken. du brauchst das programm nur etwas zu adaptieren...
wäre ein report nicht ohnehin praktischer?

mfg, stefan
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: Fr 20.06.03 15:48 
Ein Report???

Kenne ich gar nicht, bin aber auch neu was Delphi-Proggen angeht ... Gibt es den auch unter D5?

Gibt es dort ein gutes Tutorial für? Was ist das genau?

Mein Druckvorhaben ist nämlich ein etwas größeres Problem, zieht sich über mehrere Seiten (viele Spalten)

Über eine Hilfe würde ich mich sehr freuen....

Danke
Andreas
kiwicht
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1021

Win 7, MacOS
Delphi x, VBA, PHP, ...
BeitragVerfasst: Fr 20.06.03 16:03 
bin mir nicht sicher ob´s unter D5 den QReport schon gibt, wenn dem aber so ist, schau mal hier:

www.delphi-forum.de/viewtopic.php?t=12856
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Fr 20.06.03 16:09 
hallo andi!

für den anfang würd ich dir dieses tutorial empfehlen.

falls du die QuickReport-Komponenten nicht dabei hast, gibts auch noch andere. meld dich halt nochmals

mfg, stefan
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: Fr 20.06.03 16:27 
hallo stefan,
vielen dank für deine hilfe.

habe die komponenten gefunden. allerdings weiß ich nicht, ob das alles so richtig ist.

habe ja bereits ein formular, auf dem ich ddas dbgrid plaziert und mit daten über ado, query und datasource gefüllt habe.

wo soll ich denn jetzt den report plazieren? auf ein neues formular? wie verknüpfe ich denn den report mit meiner datenbank? und was ist mit meinen nach bestimmten kriterien sortierten daten? oder fällt das grid dann weg? fragen über fragen......

danke
andreas
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Fr 20.06.03 17:33 
hallo andi

so erstellst du ein neues form, welches du zu deiner unses-klausel dazuschreibst.
in dem tutorial findest auch beschrieben, welche bands du verwenden kannst und wie du die felder auf dem report plazierst
auch hier im forum gibt es schon einige beiträge über QuickReport. benutz einfach die suchfunktion ;)

mfg, stefan
Böser Borstel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154



BeitragVerfasst: Di 31.08.04 10:50 
ausblenden volle Höhe Delphi-Quelltext
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:
procedure PrintGrid(sGrid: TDBGrid; sTitle: WideString);
var
  X,
  Y,
  i,
  F: Integer;
  Text: WideString;
begin
  Printer.Title := sTitle;
  Printer.BeginDoc;
  Printer.Canvas.Pen.Color  := 0;
  Printer.Canvas.Font.Name  := sGrid.Font.Name;
  Printer.Canvas.Font.Size  := sGrid.Font.Size;
  Printer.Canvas.Font.Style := [fsBold, fsUnderline];
  Printer.Canvas.TextOut(0100, Printer.Title);
  for F := 0 to sGrid.Columns.Count - 1 do
  begin
    X := 0;
    for i := 0 to (F - 1do
      X := X + 5 * (sGrid.Columns.Items[i].Width);
    Y := 300;
    Printer.Canvas.Font.Style := [fsBold];
    Printer.Canvas.Font.Size := sGrid.Font.Size;
    TextOutW(Printer.Canvas.Handle, x + 50, y, PWideChar(sGrid.Columns.Items[F].Title.Caption), Length(sGrid.Columns.Items[F].Title.Caption));
    Printer.Canvas.Font.Style := [];
    sGrid.DataSource.DataSet.First;
    for i := 1 to sGrid.DataSource.DataSet.RecordCount do
    begin
      y := 150 * i + 300;
      Text := sGrid.DataSource.DataSet.FieldByName(sGrid.Columns.Items[F].FieldName).Value;
      TextOutW(Printer.Canvas.Handle, x + 50, y + 50, PWideChar(Text), Length(Text));
      sGrid.DataSource.DataSet.Next;
    end;
  end;
  Printer.EndDoc;
end;


Moderiert von user profile iconUGrohne: Code- durch Delphi-Tags ersetzt.
Böser Borstel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154



BeitragVerfasst: Di 31.08.04 14:18 
habe code verbessert, abgeleitetes objekt von tdbgrid hat die methode print
ausblenden volle Höhe Delphi-Quelltext
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:
procedure TTboTntDBGrid.Print(const ATitle: WideString);
var
  Height: Integer;

  function Head: Integer;
  var
    i,
    Col,
    X,
    Y: Integer;
  begin
    Y := 100;
    for Col := 0 to Columns.Count - 1 do
    begin
      X := 0;
      for i := 0 to (Col - 1do
        X := X + 5 * (Columns.Items[i].Width);
      with Printer.Canvas do
      begin
        Font.Style := [fsBold];
        TextOutW(Handle, x + 50, y, PWideChar(Columns.Items[Col].Title.Caption), Length(Columns.Items[Col].Title.Caption));
        Font.Style := [];
      end;
    end;
    Result := Y + Height;
  end//Head

var
  i,
  j,
  k,
  X,
  Y,
  Start,
  Col: Integer;
  Text: WideString;
begin
  if (DataSource <> niland
    (DataSource.DataSet <> nilthen
  begin
    with Printer do
    begin
      Title := ATitle;
      BeginDoc;
      Canvas.Pen.Color  := 0;
      Canvas.Font.Name  := Font.Name;
      Canvas.Font.Size := Font.Size;
      Height := Canvas.TextHeight('MqISenbÖ53rBorST3LBoeHNigen');
    end;
    Start := Head;
    k := 0;
    DataSource.DataSet.First;
    for i := 0 to DataSource.DataSet.RecordCount do
    begin
      y := Height * k + Start;
      if Printer.PageHeight < Y + Height then
      begin
        k := 0;
        y := Height * k + Start;
        Printer.NewPage;
        Head;
      end;
      inc(k);
      for Col := 0 to Columns.Count - 1 do
      begin
        X := 0;
        for j := 0 to (Col - 1do
          X := X + 5 * (Columns.Items[j].Width);
        Text := DataSource.DataSet.FieldByName(Columns.Items[Col].FieldName).Value;
        TextOutW(Printer.Canvas.Handle, x + 50, y, PWideChar(Text), Length(Text));
      end;
      Printer.Canvas.Rectangle(0, Y, Printer.PageWidth, Y + 1);
      DataSource.DataSet.Next;
    end;
    Printer.EndDoc;
  end;
end//TTboTntDBGrid.Print


Moderiert von user profile iconUGrohne: Code- durch Delphi-Tags ersetzt.