Jump to content

GringoStarr

Members
  • Content Count

    8
  • Joined

  • Last visited

Posts posted by GringoStarr


  1. I don't know if you missed the last 3 posts I sent. The memory leakage is detected when

    I close the application after running the for-loop. When you shut down the application a

    window pops up with a long list of leaked memory blocks. Anyway, the problem is solved.

    The leakage disappeared when I changed Value.GetText to Value.Text in the statement

     

    TFile.WriteAllText(CSVFile, Value.GetText, Encoding);

    inside the for-loop. Apparently, the expression Value.GetText is what caused the memory leaks.

    Sorry for my sloppy posts.


  2. I've written a procedure that opens .csv files and saves them
    in an excel workbook. It works fine, however, I noticed that
    memory is not being released. After some checking I found that
    it is the ExcelApp.Workbooks.Open() function that's not releasing
    memory. Here's the code:

    for var CSVItem in CSVDataDict do with CSVItem do begin
      const LineCount = Value.Count - 2;
      const CSVFile = Path + Key + '.csv';
      var ColumnWidths : IntegerArray;
    
      TFile.WriteAllText(CSVFile, Value.GetText, Encoding);
      SrcWorkBook := ExcelApp.Workbooks.Open(CSVFile, EmptyParam, EmptyParam, 
                     EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
                     EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 
             EmptyParam, EmptyParam, LCID);
      ExcelWorkSheet := SrcWorkBook.Worksheets[1] as _Worksheet;
      CalculateColumnWidths(Key, ColumnWidths, Value);
      SetWorkSheetAttributes(Key, ExcelWorkSheet, ColumnWidths, LineCount);
      Count := ExcelWorkBook.Worksheets.Count;
      ExcelWorkSheet.Copy(EmptyParam, ExcelWorkBook.Worksheets[Count], LCID);
    end;

    I'm using Excel2010 in my application. I'm kind of new to Delphi Pascal
    and it's hard to find good examples on how to use Excel Automation. Maybe
    I'm not doing it right or is there a problem with memory leaks in the 
    Workbooks.Open() function?

×