怎样强行退出子程序?(100分)

  • 主题发起人 主题发起人 GodWave
  • 开始时间 开始时间
G

GodWave

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TfrmChild.tbCreaLBLClick(Sender: TObject);
var
LBLFile:TextFile;
SLine:String;
j:integer;
begin
if NewFileFlag then
begin
Case MessageDlg('You must Save this File first!',mtConfirmation, [mbYes, mbNo], 0) of
mrYes:SaveAs1Click(Sender);
mrNo:想在此退出子程序,应该怎么办呢?
end;
end;

AssignFile(LBLFile,Table1.DatabaseName+'/'+Table1.TableName+'.lbl');
ReWrite(LBLFile);
try
for j:=1 to 5do
begin
SLine:='1,"12345-001","SAMP",1.00,1.00,100,100';
Writeln(LBLFile,SLine,j);
end;
finally
CloseFile(LBLFile);
end;
end;
 
你说的子程序是?
如果是说这个procedure,可以用Exit;
如果是说的Application,可以用Terminate或Halt;
 
或用
转移语句+exit
来结束!
 
还有:abort;
 
楼上说的对很对,补充一点:
就你这个过程而言,有必要用退出吗?用if不就行了,只有两种情况没必要用Case语句。
...
begin
if NewFileFlag then
if MessageDlg('You must Save this File first!',mtConfirmation, [mbYes, mbNo], 0)= mbYes then
begin
SaveAs1Click(Sender);
AssignFile(LBLFile,Table1.DatabaseName+'/'+Table1.TableName+'.lbl');
ReWrite(LBLFile);
try
for j:=1 to 5do
begin
SLine:='1,"12345-001","SAMP",1.00,1.00,100,100';
Writeln(LBLFile,SLine,j);
end;
finally
CloseFile(LBLFile);
end;
end;
end;
 
To杜宝,
我要的是无论是NewFileFlag为True或为False都执行文件存盘,只有MessageDlg选中No时才不用存盘.
 
请再讨论一下有没有更好的结构,完成上面的功能!
 
呵呵,反过来不就行了?
...
begin
//选了mbNo直接退出,当然就不存盘了!
if MessageDlg('You must Save this File first!',mtConfirmation, [mbYes, mbNo], 0)= mbYes then
begin
if NewFileFlag then

begin
SaveAs1Click(Sender);
end;
AssignFile(LBLFile,Table1.DatabaseName+'/'+Table1.TableName+'.lbl');
ReWrite(LBLFile);
try
for j:=1 to 5do
begin
SLine:='1,"12345-001","SAMP",1.00,1.00,100,100';
Writeln(LBLFile,SLine,j);
end;
finally
CloseFile(LBLFile);
end;
end;
end;
end;
 
多人接受答案了。
 
后退
顶部