⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 9918.txt

📁 关于编程技术技巧的文章
💻 TXT
📖 第 1 页 / 共 4 页
字号:
   PageControl1: TPageControl;
   TabSheet1: TTabSheet;
   StatusBar1: TStatusBar;
   StringGrid1: TStringGrid;
   Button1: TButton;
   Button2: TButton;
   Button3: TButton;
   NMSMTP1: TNMSMTP;
   procedure FormCreate(Sender: TObject);
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
   procedure Button3Click(Sender: TObject);
   procedure NMSMTP1Failure(Sender: TObject);
   procedure NMSMTP1SendStart(Sender: TObject);
   procedure NMSMTP1Success(Sender: TObject);
   private
   { Private declarations }
   public
   { Public declarations }
   end;
  var
   Form1: TForm1;
  implementation
  uses Unit2;
  {$R *.DFM}
  procedure TForm1.FormCreate(Sender: TObject);
  begin
   PageControl1.Pages[0].Caption:=‘Send Mail’;
   self.Caption:=‘My Mailer’;
   self.BorderIcons:=[biSystemMenu,biMinimize];
   self.BorderStyle:=bsSingle;
   Application.Icon:=self.Icon; 
   Application.Title:=self.Caption; 
   with StringGrid1 do
   begin
   Cells[0,0]:=‘Host’;
   Cells[1,0]:=‘To Address’;
   Cells[2,0]:=‘From Address’;
   Cells[3,0]:=‘Your Name’;
   Cells[4,0]:=‘Subject’;
   Cells[5,0]:=‘File’;
   end;
   Button2.Enabled:=False;
   Button3.Enabled:=False;
  end;
  procedure TForm1.Button1Click(Sender: TObject);
  begin
   Form2.Show;
  end;
  procedure TForm1.Button2Click(Sender: TObject);
  var
  i:Integer;
  begin
   for i:=1 to StringGrid1.RowCount-2 do
   with Nmsmtp1 do
   begin
   Host:=StringGrid1.Cells[0,i];
  PostMessage.ToAddress.Add(StringGrid1.Cells[1,i]);
  PostMessage.FromAddress:=StringGrid1.Cells[2,i];
  PostMessage.FromName:=StringGrid1.Cells[3,i];
  PostMessage.Subject:=StringGrid1.Cells[4,i];
   PostMessage.Attachments.Add(StringGrid1.Cells[5,i]);
   Connect;
   Sendmail;
   DisConnect;
   end;
   Button2.Enabled:=False;
   Button3.Click;
   end;
  procedure TForm1.Button3Click(Sender: TObject);
  var
  i:Integer;
  begin
   with StringGrid1 do
   begin
   for i:=1 to RowCount-2 do
   begin
   Cells[0,i]:=‘’;
   Cells[1,i]:=‘’;
   Cells[2,i]:=‘’;
   Cells[3,i]:=‘’;
   Cells[4,i]:=‘’;
   Cells[5,i]:=‘’;
   end;
   RowCount:=2;
   end;
   Button2.Enabled:=False;
   Button3.Enabled:=False;
  end;
  procedure TForm1.NMSMTP1Failure(Sender: TObject);
  begin
   StatusBar1.SimpleText:=‘Mail send failure!’;
  end;
  procedure TForm1.NMSMTP1SendStart(Sender: TObject);
  begin
   StatusBar1.SimpleText:=‘Now Sending...’;
  end;
  procedure TForm1.NMSMTP1Success(Sender: TObject);
  begin
   StatusBar1.SimpleText:=‘Send Success!’;
  end;
  end.
  Button1是“New Mail”按钮,Button 2是“Send”按钮,Button3是“Clear” 按钮。
  以下是Unit2代码清单:
  unit Unit2;
  interface
  uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, 
     Dialogs, StdCtrls;
  type
   TForm2 = class(TForm)
   OpenDialog1: TOpenDialog;
   GroupBox1: TGroupBox;
   GroupBox2: TGroupBox;
   Edit1: TEdit;
   Edit2: TEdit;
   Edit3: TEdit;
   Edit4: TEdit;
   Edit5: TEdit;
   Button1: TButton;
   Button2: TButton;
   Button3: TButton;
   Label1: TLabel;
   Label2: TLabel;
   Label3: TLabel;
   Label4: TLabel;
   Label5: TLabel;
   Label6: TLabel;
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
   procedure Button3Click(Sender: TObject);
   procedure FormActivate(Sender: TObject);
   procedure FormCreate(Sender: TObject);
   private
   { Private declarations }
   public
   { Public declarations }
   end;
  var
   Form2: TForm2;
  implementation
  uses Unit1;
  {$R *.DFM}
  procedure TForm2.FormCreate(Sender: TObject);
  begin
   self.Caption:=‘New Mail’; 
   self.BorderStyle:=bsDialog;
  end;
  procedure TForm2.FormActivate(Sender: TObject);
  begin
   Edit1.Text:=‘’;
   Edit2.Text:=‘’;
   Edit3.Text:=‘’;
   Edit4.Text:=‘’;
   Edit5.Text:=‘’;
   Label1.Caption:=‘No File’;
  end;
  procedure TForm2.Button1Click(Sender: TObject);
  begin
   if OpenDialog1.Execute then
   Label1.Caption:=Opendialog1.Filename;
  end;
  procedure TForm2.Button2Click(Sender: TObject);
  var
  i:Integer;
  begin
   if (Edit1.Text<>‘’) and (Edit2.Text<>‘’) and (Edit5.Text<>‘’) 
and (Label1.Caption<>‘No File’) then
   begin
   with Form1.StringGrid1 do
   begin
   RowCount:=RowCount+1;
   i:=RowCount-2;
   Cells[0,i]:=Edit1.Text;
   Cells[1,i]:=Edit2.Text;
   Cells[2,i]:=Edit5.Text;
   Cells[3,i]:=Edit3.Text;
   Cells[4,i]:=Edit4.Text;
   Cells[5,i]:=Label1.Caption;
   end;
   Form1.Button2.Enabled:=True;
   Form1.Button3.Enabled:=True;
   end;
   self.Hide;
  end;
  procedure TForm2.Button3Click(Sender: TObject);
  begin
   self.Hide; 
  end;
  end.
  Edit1、Edit2、Edit3、Edit4、Edit5编辑框分别用于填写服务器名称、收件
人地址、发件人名称、邮件主题和发件人地址。
  现在一个E-mail发送程序就完成了。你可以试一试,自已给自已发几封邮件,
用FoxMail之类的软件是否能收到信。顺便说一句,本文就是用这个自编程序发到
编辑部的。

***********************************************************

                       FoxPro中的陷阱技术及应用

                     甘肃省自考办(730030)马尚玮 
                    甘肃社会主义学院(730046)杨凤 

陷阱技术是系统开发中为加强系统的安全性、可靠性,提高系统的容错能力
而发展起来 的,它是一项集技术性、技巧性为一体的工作。在编制软件时,
合理、恰当地使用陷阱技术 ,能使编制的软件性能可靠,操作方便、灵活。
作为面向过程的关系型数据库语言,FoxPro是 目前较为广泛流行的数据库语
言,和一般Xbase关系型数据库语言一样。FoxPro下应用系统 程序的设计仍
采用程序顺序调用的"串行"方式,程序在实际运行的过程中经常会出现错误
或中途中断,对诸如此类的突发事件,如果能合理设置陷阱进行处理,就可防
止系统运行瘫痪, 这样设计的程序就具备了对突发事件进行"并行"处理的能
力。 

FoxPro 2.5允许用户设置各类陷阱,以捕获可能发生的某些随机事件。它提
供了4类命 令,可以为错误处理,响应按键,打印处理、非正常退出等提供陷
阱(中断)服务。在程序设计 中,使用该技术的方法是,首先编好可能发生的
随机事件的服务子程序,然后在主程序的开头 加上一条陷阱设置语句,指出
陷阱服务程序的入口。程序运行过程中,每执行完一条语句,系 统就自动检
查一下所期待的中断事件是否发生,如已发生则控制转向该事件的服务程序,
服 务程序执行完毕后,返回被中断的程序继续执行。 

一、出错陷阱的设置 

这类陷阱包括程序运行出错陷阱和输入陷阱,有两条命令ON ERROR和
ON READERROR用于 设置这类陷阱。 

1.ON ERROR[] 


该命令的功能是自动捕获命令或程序执行过程中的各类错误,然后执行<命
令>。<命令 >可以是一条命令,也可以是一段程序。通常是执行一个带有
关错误参数的陷阱处理服务子 程序。错误的参数可通过以下函数获得: 

SYS(16,1)当前出错主程序名 

PROGRAM()当前出错程序名 

LINENO()当前出错程序行号 

MESSAGE(1)出错程序源代码 

ERROR()错误代码 

MESSAGE()错误信息 

注意:以上函数使用时只能以参数的形式传递给出错陷阱处理服务子程序,不
能在程序 中直接调用,以免得到错误信息。 

下列程序ERROR1.PRG是一个出错陷阱处理程序,其使用方法是在主程序的开
始执行一条 命令: 

ON ERROR DO ERROR1 WITH SYS(16,1),PROGRAM(),LINENO(),MESSAGE(1),ERROR(),ME SSAGE() 

这样在整个程序执行过程中,只要出现错误,系统就自动执行ERROR1.PRG程序。 

SET TALK OFF 

ON ERROR DO ERROR1 WITH SYS(16,1),PROGRAM(),LINENO(),MESSAGE(1),ERROR(),M ESSAGE() 

…… 

PROCEDURE ERROR1 

PARAMETERS MPROG,PROG,LIEN,SCODE,ERR,ERRMESS 

DEFINE WINDOW WIN1 FROM 5,10 TO 14,70 

ACTIVATE WINDOW WIN1 

ON ERROR *\关闭出错陷阱 

@0,5 SAY ‘当前出错主程序名:'+MPROG 

@1,5 SAY ‘当前出错程序名:'+PROG 

@2,5 SAY ‘当前出错行号:'+LINE 

@3,5 SAY ‘出错程序源代码:'+SCODE 

@4,5 SAY ‘错误代码:'+ERR 

@5,5 SAY ‘错误信息:'+ERRMESS 

WAIT `请修改程序,然后再运行,按任意键退出' 

DEACTIVATE WINDOW WIN1 

RETURN 

在一个程序中可以有多个ON ERROR命令,但任一时刻,只有最后一次执行的
ON ERROR命 令有效。执行不带参数的ON ERROR命令可关闭出错陷阱。 

2.ON READERROR[] 

该命令为数据输入错误设置陷阱。这里数据输入错误是指在@…SAY/GET语句
中输入超 出RANGE的范围或不满足VALID的条件或其它非法数据。使用该陷阱
设置的主要目的是尽量 在数据输入时进行正确性校验,提示出错内容,保证数
据输入的正确。在READ命令执行期间 ,当出现输入错误时,陷阱被触发,控制
转移并执行<命令>(或语句)。请看下面的程序示例, 其中子程序ERROR2用
于输入出错处理。 

(1)STORE ‘ 'TO YEAR,MONTH,JOB 

(2)@10,30 SAY ‘请输入考生出生年/月和职业代码' 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -