扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:陈家朋 来源:yesky 2007年10月28日
关键字: Linux
void qsort(void *base, size_t nelem, size_t width, int (_USERENTRY *fcmp)(const void *, const void *)); |
void *bsearch(const void *key, const void *base, size_t nelem, size_t width, int (_USERENTRY *fcmp)(const void *, const void *)); |
#include <stdio.h> #include <stdlib.h> int sort_function( const void *a, const void *b); int list[5] = { 54, 21, 11, 67, 22 }; int main(void) { int x; qsort((void *)list, 5, sizeof(list[0]), sort_function); for (x = 0; x < 5; x++) printf("%i\n", list[x]); return 0; } int sort_function( const void *a, const void *b) { return *(int*)a-*(int*)b; } |
type TCalcFunc=function (a:integer;b:integer):integer; |
function Add(a:integer;b:integer):integer begin result:=a+b; end; function Sub(a:integer;b:integer):integer begin result:=a-b; end; |
function Calc(calc:TcalcFunc;a:integer;b:integer):integer |
c:=calc(add,a,b);//c=a+b c:=calc(sub,a,b);//c=a-b |
type IShape=interface(IInterface) procedure Draw; end |
type TRect=class(TObject,IShape) protected function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall; function _AddRef: Integer; stdcall; function _Release: Integer; stdcall; public procedure Draw; end; type TRound=class(TObject,IShape) protected function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall; function _AddRef: Integer; stdcall; function _Release: Integer; stdcall; public procedure Draw; end; |
procedure MyDraw(shape:IShape); var shape:IShape; begin shape.Draw; end; |
MyDraw(Trect.Create); MyDraw(Tround.Create); |
TNotifyEvent = procedure(Sender: TObject) of object; TMyEvent=procedure(Sender:Tobject;EventId:Integer) of object; |
property OnCreate: TNotifyEvent read FOnCreate write FOnCreate stored IsForm; |
type TCallback=Class procedure ClickFunc(sender:TObject); end; procedure Tcallback.ClickFunc(sender:TObject); begin showmessage('the caller is clicked!'); end; |
type TCustomFrm=class(TForm) public procedure RegisterClickFunc(cb:procedure(sender:Tobject) of object); end; procedure TcustomFrm..RegisterClickFunc(cb:TNotifyEvent); begin self.OnClick=cb; end; |
var frm:TcustomFrm; begin frm:=TcustomFrm.Create(Application); frm.RegisterClickFunc(Tcallback.Create().ClickFunc); end; |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者