首页 > Windows开发 > 详细

Delphi中回调函数的简单例子

时间:2021-05-15 20:16:02      阅读:49      评论:0      收藏:0      [点我收藏+]

----------开发环境:D7

这是一个简单的回调函数,再结合回调函数的相关资料(资料没有提供),能快速的掌握回调函数;

回调函数定义在Unit2中

 

技术分享图片

 

 

--------------------

 

---------Unit1开始

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure mytest(str:string);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses Unit2;
{$R *.dfm}

procedure TForm1.mytest(str: string);
begin
Edit2.Text :=str;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
getss(mytest,StrToFloatDef(Edit1.Text,1));
end;

end.

 

----------Unit1结束

----------------Form1开始

object Form1: TForm1
Left = 786
Top = 461
Width = 273
Height = 283
Caption = ‘Form1‘
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = ‘MS Sans Serif‘
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 104
Top = 136
Width = 75
Height = 25
Caption = ‘Button1‘
TabOrder = 0
OnClick = Button1Click
end
object Edit1: TEdit
Left = 64
Top = 64
Width = 121
Height = 21
ImeName = ‘中文(简体) - 搜狗拼音输入法‘
TabOrder = 1
Text = ‘Edit1‘
end
object Edit2: TEdit
Left = 64
Top = 104
Width = 121
Height = 21
ImeName = ‘中文(简体) - 搜狗拼音输入法‘
TabOrder = 2
Text = ‘Edit2‘
end
end

-----------------Form1结束

 

------------Unit2开始------

unit Unit2;

interface
uses Windows,Classes;
type
Tmyfun=procedure(str:string) of object ;
function getss(MyFun:Tmyfun;mydouble:double=0 ):integer ;


implementation


function getss(MyFun:Tmyfun;mydouble:double=0 ):integer ;
begin
Result:=0;
if mydouble>0 then
begin
MyFun(‘正数‘);
end
else
if mydouble=0 then
begin
MyFun(‘零‘);
end
else
begin
MyFun(‘负数‘);
end;

end;
end.

 

------------Unit2结束--------

Delphi中回调函数的简单例子

原文:https://www.cnblogs.com/dmqhjp/p/14772029.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!