要调用OnWorkEnd事件,如何写? (50分)

  • 主题发起人 主题发起人 myjane
  • 开始时间 开始时间
M

myjane

Unregistered / Unconfirmed
GUEST, unregistred user!
edit1:= Tedit.Create(nil); 要调用onChange中的事件如何写?
是写在一个函数中的。

可能是我写的不清楚。
常规下:双击onchange就可以加入要处理的代码。如下:
procedure TForm1.Edit1Change(Sender: TObject);
begin
.
showmessage('执行Change中的代码');
.
.
end;
但是,动态定义的edit1,如何加入事件代码呢?


----------------------------------------------------------------
这是一个公用函数,把代码贴在这:
----------------------------------------------------------------
unit publicfun;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs, StdCtrls,IdSMTP,IdMessage;

//发SMTP邮件
function SmtpSendMail(FromAddress,FromName, ToAddress, ASubject, MsgBody, fujian: string): Boolean;


implementation


function SmtpSendMail(FromAddress, FromName, ToAddress, ASubject, MsgBody,fujian: string):Boolean;
var
IdSMTP: TIdSMTP;
IdSendMsg: TIdMessage;
var_sHost,var_sUser,var_sPass:string;
begin
var_sHost:='smtp.263.net"
var_suser:='abcd';
var_spass:='abcd';
IdSMTP := TIdSMTP.Create(nil);
IdSendMsg := TIdMessage.Create(IdSMTP);
try
Result := False;

with IdSendMsg do
begin
From.Address:=FromAddress;//发件人地址
From.Name:=FromName;//发件人姓名
Recipients.EMailAddresses:=ToAddress; //收件人地址
Subject:= ASubject;//主题
Body.Add(MsgBody);//正文
if trim(fujian)='' then//是否有附件
else
Tidattachment.Create(IdSendMsg.MessageParts,fujian);//附件
end;

with idsmtp do
begin
Host:=var_sHost;
Username:=var_suser;
Password:=var_spass;
AuthenticationType:=atlogin;
Connect;
Send(IdSendMsg);
end;

{***************************************************************}
{* 我是想在这里加入OnWorkEnd事件,如何写吗? *}
{* 事件中的代码又写在哪里呢? *}
{* idsmtp.Disconnect; *}
{***************************************************************}

finally
IdSendMsg.Free;
IdSMTP.Free;
end;
end;
end.[/red][/b]
 
发消息啊
 
Edit1Change(sender);
你是这个意思吗?不能这么用吗?
 
Edit1.OnChange = Form1.OnClick;
 
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1Change(Sender: TObject);
begin
//
end;

procedure TForm1.Button1Click(Sender: TObject);
var
edt1:TEdit;
begin
edt1:=TEdit.Create(self);
edt1.Parent:=Form1;
edt1.Top:=10;
edt1.Left:=10;
edt1.OnChange:=Edit1Change;
end;
 
procedure myclick;
Edit1.OnChange = myClick;
 
这都不会
 
procedure myclick(sender: tobject);

(sender as tEdit).OnChange = myClick;
 
function fname(.....):boolean;
begin
...
TForm1.Edit1Change
...
end;
 
以上的我都试过了:通不过编译!
 
kaida的应该没问题呀!
 
kaida 的肯定没问题
 
kaida的思路是对的呀 ,你再查查你的程序.
 
这样改:
unit publicfun;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs, StdCtrls,IdSMTP,IdMessage;

//发SMTP邮件
function SmtpSendMail(FromAddress,FromName, ToAddress, ASubject, MsgBody, fujian: string): Boolean;
procedure myWorkEnd;


implementation

procedure myWorkEnd;
begin
......
end;

function SmtpSendMail(FromAddress, FromName, ToAddress, ASubject, MsgBody,fujian: string):Boolean;
var
IdSMTP: TIdSMTP;
IdSendMsg: TIdMessage;
var_sHost,var_sUser,var_sPass:string;
begin
var_sHost:='smtp.263.net"
var_suser:='abcd';
var_spass:='abcd';
IdSMTP := TIdSMTP.Create(nil);
IdSMTP.onworkend := myworkend;
IdSendMsg := TIdMessage.Create(IdSMTP);
try
Result := False;

with IdSendMsg do
begin
From.Address:=FromAddress;//发件人地址
From.Name:=FromName;//发件人姓名
Recipients.EMailAddresses:=ToAddress; //收件人地址
Subject:= ASubject;//主题
Body.Add(MsgBody);//正文
if trim(fujian)='' then//是否有附件
else
Tidattachment.Create(IdSendMsg.MessageParts,fujian);//附件
end;

with idsmtp do
begin
Host:=var_sHost;
Username:=var_suser;
Password:=var_spass;
AuthenticationType:=atlogin;
Connect;
Send(IdSendMsg);
end;

{***************************************************************}
{* 我是想在这里加入OnWorkEnd事件,如何写吗? *}
{* 事件中的代码又写在哪里呢? *}
{* idsmtp.Disconnect; *}
{***************************************************************}

finally
IdSendMsg.Free;
IdSMTP.Free;
end;
end;
end.[/red][/b]
 
后退
顶部