zac
zac

Reputation: 4918

After ForceDirectories statement, Delphi exits the procedure

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.

Upvotes: 1

Views: 218

Answers (1)

Andrei Galatyn
Andrei Galatyn

Reputation: 3432

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").

Upvotes: 1

Related Questions