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
@
相关文档:
函数一:
view plaincopy to clipboardprint?
uses
Windows,
SysUtils,
Classes,
ShellAPI;
function RunAndWait(FileName: string; Visibility: Integer): THandle;&nbs ......
内容简介
dbExpress是Borland公司下一代数据访问技术。本书不仅详细介绍了dbExpress的基本功能、使用技巧以及Delphi/Kylix的DataSnap技术,还详细讨论了dbExpress的实现原理以及dbExpress的未来发展趋势。本书结构清晰,讲解透彻,实例丰富。作者李维是Borland公司著名技术专家,曾著有多部Delphi名 ......
服务端:添加ADOConnection,ADOQuery1,ADOQuery2。设置ADOQuery1为主表,ADOQuery2为从表。(通过 ADOQuery2.SQL.Text:= 'select * from 从表 where FKID=:主表PKID'设置)。添加DataSetProvider1和DataSetProvider2分别连接到ADOQuery1和ADOQuery2。
客户端:添加ClientDataSet1,ClientDataSet2。ClientDataS ......
常用控件命名前缀
控件类名
前缀
TForm等窗体类
frm
TButton, TSpeedButton等所有的按钮类
btn
TCheckBox等所有的检查框
chk
TRadioButton单选按钮类
rdo
TListBox等所有的列表框类
lst
TPanel等所有的面板类
pnl
TLabel, TStaticText等所有用来显示的标签类
lbl
TE ......
Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......