Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 07.04.09 10:50 
Hi, Delpher,

ich habe folgende sehr ähnliche Prozeduren, die von Popup's auf verschiedenen DBGrids aufgerufen werden.

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:
procedure TForm1.Excel2Click(Sender: TObject);                          //popup6
begin
  fname := concat(label30.caption, 'OUTXLS\Liste der Lehrkräfte.xls');
  if Excel_vorhanden then
  begin
    if fileexists(fname) then  excelstart(self);    //löschen/überschreiben?
    if not fileexists(fname) or exneu then
    begin
      Excel_Layout1(self);
      Qx2Excel(QLk);                 //Excel(0/0) = [1,0]; Zeile/Spalte!
      excel.activeworkbook.saveas(fname);
      Excel_Layout2(self);
    end;
    excel.visible := true;
  end;
end;

procedure TForm1.Excel4Click(Sender: TObject);                          //popup5
begin
  fname := concat(label30.caption, 'OUTXLS\Schülerliste.xls');
  if Excel_vorhanden then
  begin
    if fileexists(fname) then  excelstart(self);
    if not fileexists(fname) or exneu then
    begin
      Excel_Layout1(self);
      Qx2Excel(QSchueler);
      excel.activeworkbook.saveas(fname);
      Excel_Layout2(self);
    end;
    excel.visible := true;
  end;
end;


Es müsste doch möglich sein, daraus e i n e Proc zu machen, aber mit welchen Übergabeparametern? Wahrscheinlich reicht der Name des DBGrids, denn darunter liegt die Datasource und den Dateinamen kann ich mir dann auch basteln.
Da muss ich wohl basteln mit extractfilename und extractfileextension und Anhängen der Endung '.xls'.

Danke für Hilfe,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 07.04.09 11:14 
By the way,

wie bekomme ich denn zu dem aufgerufenen Popupmenu die Komponente raus, mit der es verbunden ist? popupmenu6.Owner.Name liefert leider nur Form1, ich möchte aber z.B. DBGrid4 haben.

Ich glaube, dann käme ich weiter.

Detlef

_________________
ut vires desint, tamen est laudanda voluntas
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 07.04.09 12:07 
Über den Sender bekommst Du den geklickten Item. Über diesen sollte sich auch das zugehörige Popup finden lassen, wenn Du die Items nicht zwischen den Menüs sharest ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Nico72
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Win XP, Vista
Delphi 7, Delphi 2006
BeitragVerfasst: Di 07.04.09 12:21 
Hallo,

schau dir mal die TPopupMenu.PopupComponent Eigenschaft an.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 07.04.09 19:09 
Hallo, ihr zwei,

leider ging bei mir in der Straße seit ca. 11.15 das Internet/Telefon nicht wegen Wartungsarbeiten, deshalb meine verspätete Antwort.

Nun, leider komme ich mit euren Tipps nicht weiter. Ich habe z.B. DBGrid3 mit Popup4 und DBGrid6 mit Popup8 verbunden. Wie kriege ich also allgemein raus, welches DBGrid (welche Komponente) sich hinter welchem Popupmenu "versteckt"?

Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 07.04.09 19:15 
Scusi, also z.B. mit popupmenu6.popupcomponent.NAME.

Danke, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 07.04.09 19:21 
Autsch, leider zu früh gefreut, folgendes geht nicht:

popupmenu6.popupComponent.Name.Datasource.Dataset

hier hatte ich erwartet, dass ich auf die verschiedenen Datasets zugreifen könnte.

Wie geht das denn?
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 07.04.09 19:47 
user profile iconD. Annies hat folgendes geschrieben Zum zitierten Posting springen:
Autsch, leider zu früh gefreut, folgendes geht nicht:

ausblenden Delphi-Quelltext
1:
              popupmenu6.popupComponent.Name.Datasource.Dataset					


hier hatte ich erwartet, dass ich auf die verschiedenen Datasets zugreifen könnte.

Wie geht das denn?
Detlef


Dann versuch doch mal:
ausblenden Delphi-Quelltext
1:
              TDBGrid(popupmenu6.popupComponent).Datasource.Dataset					


bzw. eigentlich ja:

ausblenden Delphi-Quelltext
1:
              TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset					


;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 07.04.09 21:08 
Hi Benny, das ist klasse! - aber, das folgende funzt nicht:

Qx2Excel(TDBGrid(popupmenu6.popupComponent).Datasource.Dataset); // = QLk!

Gemeint ist: Eine beliebige Query = Qx to = 2 Excel(die Query, z.B. QLk)
[Ich übergebe also mit Qx2Excel eine beliebige Query an Excel]

So kommt noch die Fehlermeldung: Inkompatible Typen TQuery und TDataset.

Kannst du noch mal helfen?
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 07.04.09 21:24 
Das Dataset-Property liefert dir ein TDataset (wie der Name sagt. Entweder deine Prozedur auf TDataset in den Parametern umschreiben, oder noch diesen zusätzlichen Typecast ergänzen ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 07.04.09 21:32 
Hi Benny,

meine Proc wollte ich nicht umschreiben: z.B. Qx2Excel(QLk); ist doch schön
aber wie muss ich denn das andere von dir gemeinte umsetzen?

Detlef

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Mi 08.04.09 07:47 
Hi, ich habe jetzt mal die Proc auf TDataset umgeschrieben - aber gleiches Bild, gleicher Ton. Im Übrigen dachte ich, dass eine Query auch ein Dataset ist, aber das scheint falsch zu sein.

Wie muss ich Benny's Idee umsetzen? Das Internet hat mir keinen Aufschluss gegeben.
Gruß, Detlef

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Hi, Benny,

wäre schön, wenn du jetzt Licht in's Dunkel bringen könntest - du scheinst ja hier voll das Expertenwissen zu haben ich hingegen zur Zeit: :nixweiss:

Bis benny äh, denne

Detlef

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 09.04.09 09:02 
Hat denn keiner eine Lösung / Antwort - auch wenn sie lauten würde: es geht nicht mit D6!

So stochere ich im Nebel (auch bei Seiten aus China, die ich schon gelesen habe)

Gruß, Detlef

P.S. autsch, habe eben erst die PN gelesen, meine Aktivität ist so aber nicht gemeint.

_________________
ut vires desint, tamen est laudanda voluntas
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 09.04.09 10:46 
Poste mal bitte deinen aktuellen Stand (aufgerufene Funktion + aufrufende Prozedur (jeweils relevante Teile). Hab derzeit Delphi nicht bei der Hand, müsste da erst was nachgucken...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 09.04.09 11:21 
Hi, Benny:

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:
procedure TForm1.Excel2Click(Sender: TObject);                          //popup6
//var qxyz : TQuery;
begin                                              // TbLk.tablename
  fname := concat(label30.caption, 'OUTXLS\' + extractfilename(changefileext(TbLk.TableName, '.xls')));
  //showmessage(TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset.Name);

  if Excel_vorhanden then
  begin
    if fileexists(fname) then  excelstart(self);    //löschen/überschreiben?
    if not fileexists(fname) or exneu then
    begin                            //Excel(0/0) = Delphi[1,0]; Zeile/Spalte auch vertauscht!
      Excel_Layout1(self);
      //qxyz := TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset;

      Qx2Excel(QLk);             // GetParentMenu <--- GetParentComponent = Sender ?

      //Qx2Excel(TDBGrid(PopupMenu6.popupComponent).Datasource.DataSet);
  //  Qx2Excel(TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset);
      //Qx2Excel((((sender as TMenuItem).GetParentComponent) as TPopupMenu).PopupComponent) as TDBGrid.Datasource.Dataset);
      //Dx2Excel(TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset);
      excel.activeworkbook.saveas(fname);
      Excel_Layout2(self);
    end;
    excel.visible := true;
  end;
end;

procedure TForm1.Excel4Click(Sender: TObject);                          //popup5
begin
  fname := concat(label30.caption, 'OUTXLS\Schülerliste.xls');
  if Excel_vorhanden then
  begin
    if fileexists(fname) then  excelstart(self);
    if not fileexists(fname) or exneu then
    begin
      Excel_Layout1(self);
      Qx2Excel(QSchueler);
      excel.activeworkbook.saveas(fname);
      Excel_Layout2(self);
    end;
    excel.visible := true;
  end;
end;

procedure TForm1.Qx2Excel(Qx:TQuery);
var i, j : integer;                     // z.B. 3 -> C  (65=48+17)
begin
  rce := Qx.RecordCount; rre := Qx.FieldCount;
  for j := 0 to Qx.FieldCount-1 do
    excel.cells[1,j+1] := Qx.fields[j].fieldname;
  Qx.First; i := 2;
  qx.DisableControls; screen.Cursor := crhourglass;
  while not Qx.Eof do
  begin
    for j := 0 to Qx.fieldcount-1 do
    begin
      if pos('preis', lowercase(Qx.Fields[j].FieldName)) > 0 then
           excel.cells[i,j+1] := Qx.Fields[j].ascurrency
      else
      if pos('isbn', lowercase(Qx.Fields[j].FieldName)) > 0 then
           excel.cells[i,j+1] := '''' + Qx.Fields[j].asstring
      else excel.cells[i,j+1] := Qx.Fields[j].asstring
    end;
    inc(i); Qx.Next;
  end;
  excel.Columns.AutoFit;
  qx.EnableControls; screen.Cursor := crDefault;
end;


Denk dir bitte bei Excel2click() alle wegkommentierten Zeilen weg, das waren nur Versuche von mir.

Detlef

_________________
ut vires desint, tamen est laudanda voluntas
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 09.04.09 11:31 
ausblenden 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:
procedure TForm1.Excel2Click(Sender: TObject);                          //popup6
var 
  qxyz : TQuery;

begin                                              // TbLk.tablename
  fname := concat(label30.caption, 'OUTXLS\' + extractfilename(changefileext(TbLk.TableName, '.xls')));
  //showmessage(TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset.Name);

  if Excel_vorhanden then
  begin
    if fileexists(fname) then  excelstart(self);    //löschen/überschreiben?
    if not fileexists(fname) or exneu then
    begin                            //Excel(0/0) = Delphi[1,0]; Zeile/Spalte auch vertauscht!
      Excel_Layout1(self);
      qxyz := TQuery(TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset);

      Qx2Excel(QLk);             // GetParentMenu <--- GetParentComponent = Sender ?

      excel.activeworkbook.saveas(fname);
      Excel_Layout2(self);
    end;
    excel.visible := true;
  end;
end;

Zitat:
Denk dir bitte bei Excel2click() alle wegkommentierten Zeilen weg, das waren nur Versuche von mir.

Warum löschst Du sie dann nicht einfach ;-)

Änderungen markiert. HTH ;-)

Moderiert von user profile iconNarses: Zitat repariert

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 09.04.09 12:33 
Hi, Benny,

leider funktioniert es nicht - zur Laufzeit gibt es einen EAccessViolation Error 004D5B20 an Adresse 000002BC.

Detlef :cry: (im Gegensatz zu deinem Smiley)

_________________
ut vires desint, tamen est laudanda voluntas
Nico72
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Win XP, Vista
Delphi 7, Delphi 2006
BeitragVerfasst: Do 09.04.09 12:44 
ausblenden 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:
procedure TForm1.Excel2Click(Sender: TObject);                          //popup6
var 
  qxyz : TQuery;
begin                                              // TbLk.tablename
  fname := concat(label30.caption, 'OUTXLS\' + extractfilename(changefileext(TbLk.TableName, '.xls')));
  //showmessage(TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset.Name);

  if Excel_vorhanden then
  begin
    if fileexists(fname) then  excelstart(self);    //löschen/überschreiben?
    if not fileexists(fname) or exneu then
    begin                            //Excel(0/0) = Delphi[1,0]; Zeile/Spalte auch vertauscht!
      Excel_Layout1(self);
      qxyz :=TQuery(TDBGrid(TPopupMenu(TMenuItem(Sender).Owner).popupComponent).Datasource.Dataset);

      //Qx2Excel(QLk);             // GetParentMenu <--- GetParentComponent = Sender ?
      Qx2Excel(qxyz);

      excel.activeworkbook.saveas(fname);
      Excel_Layout2(self);
    end;
    excel.visible := true;
  end;
end;
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 09.04.09 13:09 
Danke, Nico,

das hatte ich gesehen, aber siehe oben.
Was nun?

_________________
ut vires desint, tamen est laudanda voluntas
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 09.04.09 13:37 
Oops, übersehen. TQuery ist bereits die Datasource, nicht erst das DataSet ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.