Problems with Flexcel

Hello,


I open a xlsx-File as "my own template" with flexcel actual version, see listing 1 below.
Then I create an Excel-File using this template, see listing 2-

In the last line I obtain an "access violation". How ist should be correctly?

Sincerely Peter
 

listing 1
()
function TCoordinatesXLSForm.ReadTemplate: boolean;
()
var
  templateFileName : string;
  fname : string;
begin
  templateFileName := 'NNextNeighbors.Template.xlsx';
  RedFIO.GetFirstPathFromRedirectionFile(path, templateFileName);
  ok := RedFIO.UseFirstDirectoryFromPath(path, templateFileName, fname);

  if(XLSNeighbors=Nil) then
  begin
    XLSNeighbors := TXlsFile.Create(true);
  end;
  XLSNeighbors.Open(fName);
  XLSNeighbors.ActiveSheet := 1;
  ReadTemplate := True;
  EXIT;
end;

listing 2:
()
function TCoordinatesXLSForm.WriteNeighborsExcel(fileName : string): boolean;
()
var
  i  :  Cardinal;
  j  :  Cardinal;
  completeFilePath : string;
begin
  if(XLSNeighbors=Nil) then
  begin
    XLSNeighbors := TXlsFile.Create(true);
  end;
  GetPathFromRedirectionFile(completeFilePath, fileName);
  completeFilePath := completeFilePath + ''+fileName;
  XLSNeighbors.Save(completeFilePath);
  

Hi,

At first sight, I don't see anything wrong with the code posted, but the problem is probably somewhere else and showing here. Maybe when you destroy the  XLSNeighbors variable, you don't set it to nil?

It is hard to diagnose with just this information, but can you try running it with FastMM in full debug mode?

If you are already familiar with full debug mode, just turn it on. If you aren't, the methods are different in FastMM4 and FastMM5, but here are the steps for FastMM5:

1. Get FastMM5 from https://github.com/pleriche/FastMM5
2. In your project, right click in your project and select "View Source"  (or press ctrl-v in the project explorer)
3. In the firs line of your uses, add FastMM5, like:



program VCLTest;


uses
  FastMM5,
  Forms,
  SysUtils,
  FVCLTest in 'FVCLTest.pas' {VCLTestForm},




Then, somewhere in your code after initialization, call:


uses FastMM5...
....
if not FastMM_EnterDebugMode then raise Exception.Create('Can''t enter full debug mode');


You will have to copy a dll to the folder where your exe is too.
Once you do all that, you should get a much better message and location of where the access violation really is.