Delphi编写变长参数的cdecl函数
文章来自:http://hi.baidu.com/523399/blog/item/f36e2e9b25041fbdc9eaf4c6.html
学过C语言的人都知道,printf的参数是不固定的,这种参数形式叫做变长参数。带有变长参数的函数必须是cdecl调用约定,由函数的调用者来清除栈,参数入栈的顺序是从右到左。printf是根据格式化串中的占位标记来猜测栈中的参数的。以下就用Delphi模拟一个简单的类似printf的函数sprintf。
type
VA_FN = function(const par1, par2{, ...}: Pointer): Integer; cdecl varargs;
procedure CvtInt;
{ IN:
EAX: The integer value to be converted to text
ESI: Ptr to the right-hand side of the output buffer: LEA ESI, StrBuf[16]
ECX: Base for conversion: 0 for signed decimal, 10 or 16 for unsigned
EDX: Precision: zero padded minimum field width
OUT:
ESI: Ptr to start of converted text (not start of buffer)
ECX: Length of converted text
}
asm
OR CL,CL
JNZ @CvtLoop
@C1: OR EAX,EAX
JNS @C2
NEG EAX
CALL @C2
MOV AL,'-'
INC ECX
DEC ESI
MOV [ESI],AL
RET
@
相关文档:
作为delphi的铁杆,在正式Delphi2010推出后,我当然也要尝尝新鲜,用电驴下来以后安装。呵呵二十多分钟就搞定了,启动也特快,简单使用一下,棒棒!!看来Delphi(太阳神)又回来了,如是我决定抛弃delphi2007,用这个新家伙。我所用的第三方组件主要是RemObjects和reportbuilder,reportbuilder还没有找到安装forD2009 Ful ......
在DELPHI为编程者提供了一个灵活的绘图场所,即本文所述的
CANVAS类,在DELPHI中的很多控件都具有此属性,使编程者可以
在这些的控件的表面随心所欲的绘图,这对完善用户界面或者制
作一些屏幕特技都有着非凡的作用,下面举例说明几种特殊屏幕
......
procedure TForm1.Button1Click(Sender: TObject);
Var
Num: Integer;
Begin
Try
Num:=StrToInt(Edit1.Text);
Edit2.Text:=IntToStr(Num*Num);
Except
On EConvertError Do ShowMessage(Edit1.Text+'无法转成整数!');
......