zoukankan      html  css  js  c++  java
  • Delphi中回调函数的简单例子

    ----------开发环境: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结束--------

  • 相关阅读:
    微信小程序实战,与后台交互
    微信小程序开发笔记
    微信小程序 之页面跳转
    小程序(四):模板
    (1)Appium基础操作API
    ADB命令
    移动端测试知识概览
    计算机网络常见面试题
    pip命令
    随笔-记录一些简单内容
  • 原文地址:https://www.cnblogs.com/dmqhjp/p/14772029.html
Copyright © 2011-2022 走看看