我有这个简单的程序,但我发现了一个问题,在调试时我发现Delphi成功执行ForceDirectories
但直接跳到程序的末尾而不执行后面的行,为什么会这样?
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;
我使用Delphi XE5,64bit项目
更新: 我注意到在showmessage有一个无效断点的x图标而不是有效断点的小红色图标之后也在线上放置了断点,所以我从程序的开头跟踪,我可以确认从行开始{ {1}}循环它不会被执行。
ExportToExcel是将数据导出到Excel的内置过程。
答案 0 :(得分:1)
很可能pagecontrol1.ActivePage.ComponentCount=0
和循环内的代码从未执行过。
P.S。如果调试器甚至没有尝试进入第一行周期,那么很可能你已经开启了优化。检查项目属性“编译/代码生成”(并确保使用构建配置“debug”)。