![]() |
Zugriff auf dynamisch erstellte Komponente
Hallo,
für ein größeres Project (techn. Aktienanalyse) möchte ich mit Hilfe von Quickreport und einem DBGrid Daten ausgeben und diese in einer Preview darstellen. Bisher habe ich den QReport nur statisch (also NICHT zur Laufzeit erstellt). Dies hat den Nachteil, dass ich für jede neue Tabelle wieder einen neuen Report erstellen muß. Da ich die Daten mit Hilfe von "SQL" filtere, zusammenfasse,auswerte (Joins,Group's etc.) ist eine statische Erstellung sehr un- praktisch. Nun habe ich durch Zufall im Netz eine Procedur gefunden, die genau das macht, was ich möchte. Nämlich mit EINEM leeren QReport Formular (statisch erzeugt) und den dazugehörigen Bänder, TQRLabels, TQRDBText etc. (Erstellung NUR zur Laufzeit) beliebige Felder und Inhalte von verschiedenen Tables in einer Preview auszugeben (und auszudrucken). Autor R.R. Aguilo -> ![]() Nach der Korrektur einiger kleiner Fehler läuft mein Testprogramm sehr zufriedenstellend. Nun möchte ich wegen der besseren Lesbarkeit mit Hilfe von Procedure "BeforePrint" (s.u.) Tabellierpapier simulieren. Beim Entwurf von QReport (zur Designzeit) gibt es keine Probleme. In meinem Testprogramm jedoch gibt es zur Designzeit noch keine Komponente "DetailBandXXX". Ein weiteres Problem ist, dass mit jedem neuen Aufruf von "GridRepPreview(Grid : TDBGrid)" wieder ein neues Detailband erzeugt wird (und später freigegeben) wird. Ich habe es schon mit TComponentList bzw. mit TObjectList probiert. Kein Erfolg. Da ich ein reiner Hobbyprogrammierer bin wäre ich für ein paar Anregungen oder Lösungsansätze sehr dankbar. Wendelin
Delphi-Quellcode:
unit DBQRGridReport; // DELPHI 7E.
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics,Controls, Forms,Dialogs, ExtCtrls, QuickRpt, QRCtrls, DB, DBQRUnit1, DBGrids,DBQRDataModul; type TGridReport = class(TForm) GridRep: TQuickRep; procedure GridRepPreview(Grid : TDBGrid); (* procedure GridRepBeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean); *) private { Private declarations } public end; var GridReport: TGridReport; implementation {$R *.dfm} procedure TGridReport.GridRepPreview(Grid : TDBGrid); var i, CurrentLeft, CurrentTop : integer; begin GridRep.Dataset:=Grid.DataSource.DataSet; if not GridRep.Bands.HasColumnHeader then GridRep.Bands.HasColumnHeader:=true; if not GridRep.Bands.HasDetail then GridRep.Bands.HasDetail:=true; if not GridRep.Bands.HasPageFooter then // NEU GridRep.Bands.HasPageFooter := TRUE; GridRep.Bands.ColumnHeaderBand.Height:= Abs(Grid.TitleFont.Height) + 10; GridRep.Bands.DetailBand.Height := Abs(Grid.Font.Height) + 10; GridRep.Bands.PageFooterBand.Height := Abs(Grid.Font.Height) + 10; CurrentLeft := 12; CurrentTop := 4; // 6 Grid.DataSource.DataSet.DisableControls; // don't flicker !! try for i:=0 to Grid.FieldCount - 1 do begin if (CurrentLeft + Canvas.TextWidth(Grid.Columns[i].Title.Caption)) > (GridRep.Bands.ColumnHeaderBand.Width) then begin CurrentLeft := 12; CurrentTop := CurrentTop + Canvas.TextHeight('A') + 6; GridRep.Bands.ColumnHeaderBand.Height := GridRep.Bands.ColumnHeaderBand.Height + (Canvas.TextHeight('A') + 10); GridRep.Bands.DetailBand.Height := GridRep.Bands.DetailBand.Height + (Canvas.TextHeight('A') + 10); end; {Create Header with QRLabels} with TQRLabel.Create(GridRep.Bands.ColumnHeaderBand) do begin Parent := GridRep.Bands.ColumnHeaderBand; Color := GridRep.Bands.ColumnHeaderBand.Color; Left := CurrentLeft; Top := CurrentTop - 10; // korr. ! Caption := Grid.Columns[i].Title.Caption; Font.Style := [fsBold,fsUnderline]; end; {Create Detail with QRDBText} with TQRDBText.Create(GridRep.Bands.DetailBand) do begin Parent := GridRep.Bands.DetailBand; Color := GridRep.Bands.DetailBand.Color; Transparent := TRUE; // NEU für Farbwechsel Left := CurrentLeft; Top := CurrentTop; Alignment := taLeftJustify; // NEU / Alt -> Grid.Columns[i].Alignment; AutoSize := FALSE; AutoStretch := FALSE; // korr. ! WordWrap := FALSE; // NEU Width := Grid.Columns[i].Width; Dataset := GridRep.Dataset; DataField := Grid.Fields[i].FieldName; CurrentLeft := CurrentLeft + (Grid.Columns[i].Width) + 15; end; end; {Create SysData / Datum-Zeit} with TQRSysData.Create(GridRep.Bands.PageFooterBand) do begin Parent := GridRep.Bands.PageFooterBand; Color := clWhite; Left := 12; Top := CurrentTop; Alignment := taLeftJustify; Data := qrsDateTime; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Name := 'Arial'; Font.Style := [fsBold]; end; {Create Label / TableName} with TQRLabel.Create(GridRep.Bands.PageFooterBand) do begin Parent := GridRep.Bands.PageFooterBand; Color := clWhite; Left := 512; Top := CurrentTop; Alignment := taLeftJustify; Caption := 'TABLE 1'; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Name := 'Arial'; Font.Style := [fsBold,fsUnderline]; end; {Create Label / Seite :} with TQRLabel.Create(GridRep.Bands.PageFooterBand) do begin Parent := GridRep.Bands.PageFooterBand; Color := clWhite; Left := 948; Top := CurrentTop; Alignment := taLeftJustify; Caption := 'SEITE :'; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Name := 'Arial'; Font.Style := [fsBold]; end; {Create SysData / Seitennummer} with TQRSysData.Create(GridRep.Bands.PageFooterBand) do begin Parent := GridRep.Bands.PageFooterBand; Color := clWhite; Left := 1024; Top := CurrentTop; Alignment := taLeftJustify; Data := qrsPageNumber; Font.Charset := DEFAULT_CHARSET; Font.Color := clWindowText; Font.Height := -13; Font.Name := 'Arial'; Font.Style := [fsBold]; end; {After all, call the QuickRep preview method} GridRep.Preview; {or PreviewModal if you prefer} finally // FREE it NEU! GridRep.Bands.ColumnHeaderBand.Free; // wichtig sonst eListError GridRep.Bands.DetailBand.Free; // wichtig sonst eListError GridRep.Bands.PageHeaderBand.Free; // wichtig sonst eListError with Grid.DataSource.DataSet do begin EnableControls; end; end; end; // Für Tabellierpapier (* procedure TGridReport.GridRepBeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean); begin If GridReport.DetailBandXXX.Color = clWhite THEN GridReport.DetailBandXXX.Color := clMoneyGreen ELSE GridReport.DetailBandXXX.Color := clWhite; end; *) end. |
AW: Zugriff auf dynamisch erstellte Komponente
Zitat:
Viel Glück |
AW: Zugriff auf dynamisch erstellte Komponente
Kauf dir die DevExpress-komponenten (Grid und Printing suite). Dann ist Ruhe im Karton.
Quickreport ist doch &%&$%"§$". [Edit]: Beim zweiten Durchlesen das Wort 'Hobbyprogrammierer' gelesen... Deswegen ist dieser Tipp hier unbrauchbar... Sorry [/Edit] |
AW: Zugriff auf dynamisch erstellte Komponente
Bitte Quellcode wegen der Lesbarkeit mit zutreffendem Delphi- oder Code-Tag klammern, dann bleibt die Formatierung im wesentlichen erhalten. Dafür gibts im Bearbeitungsformular auch Schaltflächen.
Den QReport hab ich nicht installiert, aber im Prinzip sollte es doch so funktionieren:
Delphi-Quellcode:
procedure TGridReport.MyDetailBeforePrint({...});
begin {...} end; // Ereignisbehandlung zuweisen GridRep.Bands.DetailBand.BeforePrint := MyDetailBeforePrint; |
AW: Zugriff auf dynamisch erstellte Komponente
Hallo Omata,
ich meine damit: Tabellierpaper bedeutet das die ZEILEN im Report der besseren Lesbarkeit halber alternierend z.B. in weiss - grün - weiss - grün u.s.w. dargestellt werden s.u. Natürlich kann auch eine andere Farbkombination gewählt werden. begin If GridReport.DetailBandXXX.Color = clWhite THEN GridReport.DetailBandXXX.Color := clMoneyGreen ELSE GridReport.DetailBandXXX.Color := clWhite; end; Dennoch vielen Dank für die schnelle Bearbeitung |
AW: Zugriff auf dynamisch erstellte Komponente
Hallo FredlFesl
mag zwar ein guter Tipp sein, ist mir aber deutlich zu teuer! 599 - 1999 $ !! Habe schon mit RaveReport gearbeitet, benötige ich nicht, da zu komplex und für meine Anforderungen überdimensioniert. Dennoch danke für die schnelle Bearbeitung. P.S. Was bedeutet das : &%&$%"§$" ?? |
AW: Zugriff auf dynamisch erstellte Komponente
Hallo Blup,
Vielen Dank für die schnelle Antwort, aber so geht es leider nicht. Vielleicht stelle ich mich aber auch nur doof an. Kannst Du Deinen Vorschlag etwas näher erläutern ? |
AW: Zugriff auf dynamisch erstellte Komponente
Hallo wendelin,
Ich implementiere alternierende Zeilen immer mit
Delphi-Quellcode:
If Odd (MyDataset.Recno) Then
Band.Color := clWhite else Band.Color := clGray; |
AW: Zugriff auf dynamisch erstellte Komponente
Zitat:
Ich versuchs mal etwas konkreter darzustellen:
Delphi-Quellcode:
type
TGridReport = class(TForm) GridRep: TQuickRep; procedure GridRepPreview(Grid : TDBGrid); procedure GridRepBeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean); // <- muss im Objektinspektor dem Ereignis des Reports "BeforePrint" zugewiesen sein procedure MyDetailBeforePrint({...}); // <- wird erst zur Laufzeit zugewiesen {...} end; implementation procedure TGridReport.GridRepBeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean); begin // dem DetailBand Ereignisbehandlung zuweisen GridRep.Bands.DetailBand.BeforePrint := MyDetailBeforePrint; end; procedure TGridReport.MyDetailBeforePrint({...}); begin {...} end; |
AW: Zugriff auf dynamisch erstellte Komponente
Hallo Blup, vielen Dank für Deine Mühe,
aber ich glaube,dass ich mich sehr... anstelle. :? type TGridReport = class(TForm) GridRep: TQuickRep; procedure GridRepPreview(Grid : TDBGrid); procedure GridRepBeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean); procedure MyDetailBeforePrint({...}); // <--- müssen hier Param. rein und wenn ja, welche ? * * procedure TGridReport.GridRepBeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean); begin // dem DetailBand Ereignisbehandlung zuweisen GridRep.Bands.DetailBand.BeforePrint := MyDetailBeforePrint({...}); // <--- müssen hier Param. rein und wenn ja, welche ? // Error Zeile.188 end; procedure TGridReport.MyDetailBeforePrint({...}); // müssen hier Param. rein und wenn ja, welche ? begin If GridReport.DetailBand.Color = clWhite THEN // error Z. 193 GridReport.DetailBand.Color := clMoneyGreen ELSE GridReport.DetailBand.Color := clWhite; end; Ich schick die mal die Fehlerliste des Compilers: [Error] DBQRGridReport.pas(188): Incompatible types: 'TQRBandBeforePrintEvent' and 'procedure, untyped pointer or untyped parameter' [Error] DBQRGridReport.pas(193): Undeclared identifier: 'DetailBand' [Error] DBQRGridReport.pas(193): 'THEN' expected but identifier 'Color' found |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:24 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz