1
votes

I have this simple procedure but I found a problem, while debugging I found Delphi execute ForceDirectories successfully but jump directly to the end of the procedure without executing the lines after it, why is that ??

var
export_dir: string;
grd_idx: integer;
begin
  export_dir := 'c:\app1\export\';
  SysUtils.ForceDirectories(export_dir);

  showmessage('this line executed then it jump to the end !!');

  for grd_idx := 0 to pred(pagecontrol1.ActivePage.ComponentCount) do begin

    if (pagecontrol1.ActivePage.components[grd_idx] is Tmycomp) then
  ExportToExcel(export_dir+(pagecontrol1.ActivePage.components[grd_idx] as Tmycomp).Name, (pagecontrol1.ActivePage.components[grd_idx] as Tmycomp),
    true, true, true, 'xlsx');

  end;

end;

I use Delphi XE5, 64bit project

Update: I noticed also placing break points on the line after showmessage has an x icon for invalid break point instead of the little red icon for valid break point so I traced from the beginning of the procedure and I can confirm starting from the line begin with the For loop it does not get executed.

ExportToExcel is a built in procedure for exporting data to Excel.

1
I just tested on XE4 with a 64 bit executable and the code ran as expected. Can you create a full SSCCE console app that duplicates the behavior?Graymatter
What version of Windows, and are you running as an administrator? If the C:\app1 folder does not exist, it must be created first before the export folder can be, and a non-admin user can't create folders off the root of C: under Windows Vista and above with UAC enabled. You're not checking the return value of ForceDirectories (or you could simply build with debug DCUs and step into the call to see why it's failing).Ken White
@KenWhite Win7 64bit as Admin, folders created successfully and I stepped through the code it jump from that line to end;!!!William
I can't replicate it (see my answer). Again, my suggestion is to build with debug DCUs and step into the call to ForceDirectories to see what's happening.Ken White
I'm not checking anything until you make up your mind, and then provide the necessary information to your question. I have no idea what ExportToExcel might do, what you are typecasting to Tmycomp or what a Tmycomp is in the first place, and you've not been clear about where the problem is occurring yet.Ken White

1 Answers

1
votes

It is quite possible that pagecontrol1.ActivePage.ComponentCount=0 and code inside of cycle never executed.

P.S. If debugger even is not trying to go first line of cycle, most probably you have optimizations switched on. Check project properties "compiling/code generation" (and make sure you use build configuration "debug").