Autor Beitrag
rob87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 11:36 
Hallo

ich hab ein Problem beim Speichern der Datei. Er meldet mir immer, dass die Datei schreibgeschützt ist und ich sie nur unter einem anderen Namen speichern kann.

Kann das damit zusammenhängen, dass in meinem Task Manager die EXCEL.EXE vorhanden bleibt, auch wenn ich das Delphi-Programm beendet habe? Ich bekomm nämlich bei jedem neuen Ausführen des Delphi-Programms wieder eine EXCEL.EXE zu meinem Task Manager "dazu".

ausblenden Delphi-Quelltext
1:
2:
3:
4:
//Prozedur um zu Excel zu verbinden
//Schließen der Excel-Sachen:
      Excel.Workbooks.Close;
    Excel.Quit;

Ich denk, dass da in den unteren zwei Zeilen der Wurm drin ist.


Zuletzt bearbeitet von rob87 am Di 29.01.08 12:02, insgesamt 1-mal bearbeitet
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Di 29.01.08 11:53 
wenn du immer ein excel in der Taskleiste 'dazu' bekommst ...
sind die auch nach ende deines Programms noch da ?? (das 'freut' dann den User ...)

is bei dir Excel ein Object, das du irgendwo vorher mit create erzeugt hast ??
dann würde ich sagen, da fehlt nach dem excel.quit ein excel.free ?

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Di 29.01.08 11:54 
Sorry, dass ich mich gestern nicht gemeldet habe.

Die Lösung deines Problems ist, dass du nach dem Quit den OleVariant freigibst.

ausblenden Delphi-Quelltext
1:
2:
Excel.Quit;
Excel := UnAssigned;


Danach sollte die Excel.exe aus dem Taskmanager verschwinden.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 12:00 
user profile iconiKilledKenny hat folgendes geschrieben:
Sorry, dass ich mich gestern nicht gemeldet habe.

Kein Thema. Is ja eigentlich eh ein neues Thema. :wink:

user profile iconiKilledKenny hat folgendes geschrieben:

Die Lösung deines Problems ist, dass du nach dem Quit den OleVariant freigibst.

ausblenden Delphi-Quelltext
1:
2:
Excel.Quit;
Excel := UnAssigned;


Danach sollte die Excel.exe aus dem Taskmanager verschwinden.

Funktioniert leider ned. :roll: :roll:


Zuletzt bearbeitet von rob87 am Di 29.01.08 12:05, insgesamt 1-mal bearbeitet
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 12:04 
user profile iconzuma hat folgendes geschrieben:
wenn du immer ein excel in der Taskleiste 'dazu' bekommst ...
sind die auch nach ende deines Programms noch da ?? (das 'freut' dann den User ...)

Ja, leider. :(

user profile iconzuma hat folgendes geschrieben:

is bei dir Excel ein Object, das du irgendwo vorher mit create erzeugt hast ??
dann würde ich sagen, da fehlt nach dem excel.quit ein excel.free ?

Hier mein Erzeugungs-Quelltext:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
//Prozedur um zu Excel zu verbinden
procedure TfrmVerbrEintr.excel_verbinden();
begin
  Excel := CreateOleObject('Excel.Application');

  try
    Excel.Workbooks.Open [Main.dateiname_verbrauch];
  except
    Messagedlg('Datei '+Main.dateiname_verbrauch+' nicht gefunden',mtConfirmation,[mbOK],0);
  end;

  if Excel.Workbooks[1].Sheets.Count = 0 then
    ShowMessage('Keine Arbeitsblätter');

  Excel.Workbooks[1].Activate;
end;
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Di 29.01.08 12:07 
probier mal da, wo du excel.quit machst, direkt danach ein
excel.free (oder muss das Excel.release oder excel.freeandnil sein .. k.a)

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Di 29.01.08 12:09 
Hab ein kleines Beispiel-Projekt angehängt.
Einloggen, um Attachments anzusehen!
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 12:11 
user profile iconzuma hat folgendes geschrieben:
probier mal da, wo du excel.quit machst, direkt danach ein
excel.free (oder muss das Excel.release oder excel.freeandnil sein .. k.a)


Zitat:
Die Methode Free wird vom Automatisierungsobjekt nicht unterstützt
, sagt mein Delphi
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 12:14 
user profile iconiKilledKenny hat folgendes geschrieben:
Hab ein kleines Beispiel-Projekt angehängt.


Merci. Aber: :roll:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Button2Click(Sender: TObject);
begin
  FExcel.Quit;
  FExcel := Unassigned;   <!-- Undefinierter Bezeichner 'Unassigned
end;
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Di 29.01.08 12:17 
Bei mir (Delphi 5) in der Unit System.pas...
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 12:19 
user profile iconiKilledKenny hat folgendes geschrieben:
Bei mir (Delphi 5) in der Unit System.pas...


Bei mir (Delphi 7 Enterprise) geht des ned :(
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Di 29.01.08 12:20 
hab da was mit word gemacht, denke mir, das müsste mit excel auch so gehen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
// Units, die für Word-Nutzung eingebunden werden müssen:
// Word97, Word2000
function gibWordApp(xVisible : boolean = false) : TWordApplication;
begin
 try
  result := TWordApplication.Create(nil);   // Word im Hintergrund starten/erzeugen
  result.Visible:= xVisible;                // Word (nicht) anzeigen
 except
  result := nil;
 end;
end;


und da gibts dann auch ein
Word.free

versuch also mal,
a) die unit Excel einzubinden (uses) und
b) dann eine excel-instanz nach dem obigen Muster zu erzeugen

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 12:22 
user profile iconzuma hat folgendes geschrieben:
hab da was mit word gemacht, denke mir, das müsste mit excel auch so gehen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
// Units, die für Word-Nutzung eingebunden werden müssen:
// Word97, Word2000
function gibWordApp(xVisible : boolean = false) : TWordApplication;
begin
 try
  result := TWordApplication.Create(nil);   // Word im Hintergrund starten/erzeugen
  result.Visible:= xVisible;                // Word (nicht) anzeigen
 except
  result := nil;
 end;
end;


und da gibts dann auch ein
Word.free

versuch also mal,
a) die unit Excel einzubinden (uses) und
b) dann eine excel-instanz nach dem obigen Muster zu erzeugen


Unit 'Excel' kennt er bei mir ned.
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Di 29.01.08 12:25 
Google brachte für Delphi 7 die Unit Variants.pas zum Vorschein... Evtl. mal ein Unassigned in den Quelltext und dann ein F1, in der Delphi 5 Hilfe wird die Unit angezeigt, in der Solche Dinge deklariert sind.

@zuma:
rob87 versucht die Nutzung von Excel mit einem OleObject, nicht mit den VCL-Komponenten.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 12:30 
user profile iconiKilledKenny hat folgendes geschrieben:
Google brachte für Delphi 7 die Unit Variants.pas zum Vorschein... Evtl. mal ein Unassigned in den Quelltext und dann ein F1, in der Delphi 5 Hilfe wird die Unit angezeigt, in der Solche Dinge deklariert sind.


Dankeschön. Hab die function Unassigned in der Unit Variants (über die Hilfe) gefunden und eingebunden. Nun funktionierts mit deinem Projekt. Schau gleich mal vom Quelltext, was sich da zu meinem unterscheidet.

@zuma: Und ja, ich mach des via OLE ;)
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Di 29.01.08 12:34 
Nichts, ausser dass ich nach dem Excel.Quit noch ein Excel := Unassigned; mache... :D
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 12:36 
user profile iconiKilledKenny hat folgendes geschrieben:
Nichts, ausser dass ich nach dem Excel.Quit noch ein Excel := Unassigned; mache... :D


Ja, eben. Und das hab ich ja nun auch gemacht. Hab nun sogar noch das Excel.Workbooks.Close; weggetan (fraglich ob des so klug war) :roll:

Aber des haut bei mir immer noch nicht hin.
Agawain
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 460

win xp
D5, MySQL, devxpress
BeitragVerfasst: Di 29.01.08 13:41 
hi

Das workbooks.close muß drin bleiben.
Starte mal den Rechner neu, kann sein, daß Windows die Dateien noch nicht freigegeben hat, selbst wenn Du alle Excel-Tasks beendet hast. Zumindest unser Samba-Server macht sowas :wink:.

_________________
Gruß Aga
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 14:15 
user profile iconAgawain hat folgendes geschrieben:
hi

Starte mal den Rechner neu, kann sein, daß Windows die Dateien noch nicht freigegeben hat, selbst wenn Du alle Excel-Tasks beendet hast. Zumindest unser Samba-Server macht sowas :wink:.

Hat nichts gebracht :roll: :?: :?:
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Di 29.01.08 14:22 
Hab nun den Haken gefunden. Ich hab zwei Excel-Objekte erzeugt und nur eines beendet. D.h. bei jedem Programmaufruf hat er am Ende eins hinterlassen.