AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls Delphi Komponente verursacht Fehler beim Beenden von Delphi/Projekt
Thema durchsuchen
Ansicht
Themen-Optionen

Komponente verursacht Fehler beim Beenden von Delphi/Projekt

Ein Thema von BAMatze · begonnen am 26. Jun 2009 · letzter Beitrag vom 3. Aug 2009
 
BAMatze

Registriert seit: 18. Aug 2008
Ort: Berlin
759 Beiträge
 
Turbo Delphi für Win32
 
#7

Re: Komponente verursacht Fehler beim Beenden von Delphi/Pro

  Alt 3. Aug 2009, 07:49
Hallo und Guten Morgen an alle DP´ler,

Habe alles nochmal ein wenig mit Uwes Hinweisen umgearbeitet und die Routine sieht jetzt wie folgt aus:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExcelXP;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

const Testname = 'Test.xls';

var
  Form1: TForm1;
  FExcelApplication: ExcelApplication;
  FExcelWorkbook: ExcelWorkbook;
  FExcelWorksheet: ExcelWorksheet;
  sparentroot: string;
  iUserLCID: integer;

implementation

{$R *.dfm}

procedure ExcelDatenbank_anlegen;
begin
  FExcelApplication := CoExcelApplication.Create;
  FExcelApplication.Workbooks.Add(emptyparam, iUserLCID);
  FExcelWorkbook := FExcelApplication.ActiveWorkbook;
  FExcelWorkbook.Worksheets.Add(emptyParam, emptyParam, emptyParam, emptyParam, iUserLCID);
  FExcelWorksheet := FExcelWorkbook.ActiveSheet as ExcelWorksheet;
  FExcelWorksheet.Cells.Item[3,1] := 'Hallo';
  FExcelWorksheet.Cells.Item[3,2] := 'dies';
  FExcelWorksheet.Cells.Item[3,3] := 'ist';
  FExcelWorksheet.Cells.Item[3,4] := 'ein';
  FExcelWorksheet.Cells.Item[3,5] := 'Test';
  FExcelApplication.visible[iUserLCID] := true;
end;

procedure ExcelDatenbank_oeffnen;
begin
  FExcelApplication := CoExcelApplication.Create;
  FExcelApplication.Workbooks.Open(ExtractFilePath(ParamStr(0)) + TestName, emptyParam, emptyParam, emptyParam, emptyParam
                          , emptyParam, emptyParam, emptyParam, emptyParam, emptyParam, emptyParam, emptyParam, emptyParam
                          , emptyParam, emptyParam, iUserLCID);
  FExcelApplication.visible[iUserLCID] := true;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  // Speichern und Schließen von Excel
  FExcelApplication.ActiveWorkbook.Close(true, sparentroot + Testname, emptyParam, iUserLCID);
end;

procedure TForm1.FormCreate(Sender: TObject);
var DWResult: DWORD;
begin
  sparentroot := ExtractFilePath(ParamStr(0));
  iUserLCID := GetUserDefaultLCID;
  if FindWindow('XLMain','Microsoft Excel - ' + TestName) <> 0 then
      SendMessageTimeout(FindWindow('XLMain','Microsoft Excel - ' + TestName), WM_CLOSE, 0, 0,
      SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult);
  if not FileExists(Testname) then ExcelDatenbank_anlegen
  else ExcelDatenbank_oeffnen;
end;

end.
Es gibt keine Speicherlecks mehr aber eine Frage, wenn ich mit den Interfaces arbeite (was ich ja auch mit create mache, also sie erstellen) brauche ich dann wirklich kein Free mehr?

Vielen Dank
BAMatze
2. Account Sero
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:15 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