(应用程序调用一个已为另一线程整理的接口)错误怎么解决

qlonsh 2010-04-06 04:05:42
作用主要用于将数据写入到EXCEL文档中
ExcelApp: Variant; //EXCEL文档为全局变量

在一开始时,我在主窗体中打开EXCLE文档,具体代码如下():
var
FilePath,PageHeader,PageFooter,ExcelFile:string;
begin
//程序在每次测试前生成测试文件
FilePath:=ExtractFilePath(paramstr(0));
ExcelFile:=FilePath+'测试文档\'+FormatdateTime('yy''年''m''月''d''日''dddd',Now);
if not DirectoryExists(ExcelFile) then
begin
if not CreateDir(ExcelFile) then showmessage('创建测试文档文件夹不成功');
end;

ExcelApp.Visible:=false;

ExcelFile:=ExcelFile+'\'+FormatdateTime('yy''年''m''月''d''日''ssss',Now)+'.xls';
if FileExists(ExcelFile) then
begin
//已经存在当天的报警记录则调入
ExcelApp.WorkBooks.Open(ExcelFile);
end
else
begin
//没有当天的报警文件则先产生一个空的Excel文件
ExcelApp.Workbooks.Add(xlWBatWorkSheet);
try
ExcelApp.WorkSheets[1].Rows[1].Font.Color:=clBlue;
ExcelApp.WorkSheets[1].Rows[1].Font.Bold:=true;
ExcelApp.WorkSheets[1].Cells[1,1].Value:='1主相电阻';
ExcelApp.WorkSheets[1].Cells[1,2].Value:='1副相电阻';
ExcelApp.WorkSheets[1].Cells[1,3].Value:='2耐压电否合格';
~~~
~~~~~~略
ExcelApp.Workbooks[1].SaveAs(ExcelFile);
except
exit;
end;
end;

写具体数据过程(主要用在线程中调用),在线程中调用时就会出现上面的错误(应用程序调用一个已为另一线程整理的接口)
procedure WriteExcel(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15:string);
begin
frmmain.Caption:='fdsf';
ExcelApp.WorkSheets[1].Rows[2].Insert; //不同报警时段空行
ExcelApp.WorkSheets[1].Rows[1].Font.Color:=clBlack;
ExcelApp.WorkSheets[1].Cells[2,1].Value:=X1;
ExcelApp.WorkSheets[1].Cells[2,2].Value:=X2;
ExcelApp.WorkSheets[1].Cells[2,3].Value:=X3;
ExcelApp.WorkSheets[1].Cells[2,4].Value:=X4;
ExcelApp.WorkSheets[1].Cells[2,5].Value:=X5;
ExcelApp.WorkSheets[1].Cells[2,6].Value:=X6;
ExcelApp.WorkSheets[1].Cells[2,7].Value:=X7;
ExcelApp.WorkSheets[1].Cells[2,8].Value:=X8;
ExcelApp.WorkSheets[1].Cells[2,9].Value:=X9;
ExcelApp.WorkSheets[1].Cells[2,10].Value:=X10;
ExcelApp.WorkSheets[1].Cells[2,11].Value:=X11;
ExcelApp.WorkSheets[1].Cells[2,12].Value:=X12;
ExcelApp.WorkSheets[1].Cells[2,13].Value:=X13;
ExcelApp.WorkSheets[1].Cells[2,14].Value:=X14;
ExcelApp.WorkSheets[1].Cells[2,15].Value:=X15;
ExcelApp.Workbooks[1].Save;
end;


请问如何解决???
...全文
760 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧