pascal

delphi指针

人走茶凉 提交于 2019-12-23 10:42:35
浅谈Object Pascal的指针 大家都认为,C语言之所以强大,以及其自由性,很大部分体现在其灵活的指针运用上。因此,说指针是C语言的灵魂,一点都不为过。同时,这种说法也让很多人 产生误解,似乎只有C语言的指针才能算指针。Basic不支持指针,在此不论。其实,Pascal语言本身也是支持指针的。从最初的Pascal发展至今 的Object Pascal,可以说在指针运用上,丝毫不会逊色于C语言的指针。 以下内容分为八个部分,分别是 一、类型指针的定义 二、无类型指针的定义 三、指针的解除引用 四、取地址(指针赋值) 五、指针运算 六、动态内存分配 七、字符数组的运算 八、函数指针 一、类型指针的定义。对于指向特定类型的指针,在C中是这样定义的: int *ptr; char *ptr; 与之等价的Object Pascal是如何定义的呢? var ptr : ^Integer; ptr : ^char; 其实也就是符号的差别而已。 二、无类型指针的定义。C中有void *类型,也就是可以指向任何类型数据的指针。Object Pascal为其定义了一个专门的类型:Pointer。于是, ptr : Pointer; 就与C中的 void *ptr; 等价了。 三、指针的解除引用。要解除指针引用(即取出指针所指区域的值),C 的语法是 (*ptr),Object Pascal则是

Delphi: How to find and fix an EOutOfMemory Error?

穿精又带淫゛_ 提交于 2019-12-23 09:26:56
问题 I'm building a delphi application which does scientific simulation. It's growing in complexity & now consists of many units and forms. I'm starting to get EOutOFMemory Errors each time I run. It seems to happen during or just after I use an Array of variant temporarily within a functions. At risk of asking a really dumb question, is "array of variant" asking for trouble? ( I could convert everything to string, but array of variant in principle saves a lot of fudging things). the offending

SetLength on multidimensional array

隐身守侯 提交于 2019-12-23 07:36:52
问题 I'd like to know how to set the length of multidimensional arrays/create dynamic multidimensional arrays in Pascal. Like SetLength(arr,len) does for one dimensional arrays. I cannot find the answer. 回答1: var arr: array of array of real; ... SetLength(arr, 10, 20); // creates a 10 by 20 matrix A bad, but equivalent, way of doing this is to do SetLength(arr, 10); for i := low(arr) to high(arr) do SetLength(arr[i], 20); The latter approach allows "non-rectangular" arrays, however. 来源: https:/

Pascal - String to LongWord

为君一笑 提交于 2019-12-23 05:22:54
问题 I have number as String. How to convert that string to LongWord? I know how to convert it to integer. But integer is to small for me. 回答1: Actually you can use StrToInt. The resulting value will overflow (i.e. become negative for values above $7fffffff, you might want to disable overflow checking), but when it is casted to longword, you will get the correct value. Although the low level Val might be safer: var x: longword; e: word; begin Val('$9fffffff', x, e); writeln(x); end. 来源: https:/

Windows Socket 网络编程(二) —— 套接字编程原理[转自VC知识库]

只愿长相守 提交于 2019-12-23 02:16:19
一、客户机/服务器模式 在TCP/IP网络中两个进程间的相互作用的主机模式是客户机/服务器模式(Client/Server model)。该模式的建立基于以下两点:1、非对等作用;2、通信完全是异步的。客户机/服务器模式在操作过程中采取的是主动请示方式: 首先服务器方要先启动,并根据请示提供相应服务:(过程如下) 1、打开一通信通道并告知本地主机,它愿意在某一个公认地址上接收客户请求。 2、等待客户请求到达该端口。 3、接收到重复服务请求,处理该请求并发送应答信号。 4、返回第二步,等待另一客户请求 5、关闭服务器。 客户方: 1、打开一通信通道,并连接到服务器所在主机的特定端口。 2、向服务器发送服务请求报文,等待并接收应答;继续提出请求…… 3、请求结束后关闭通信通道并终止。 二、基本套接字 为了更好说明套接字编程原理,给出几个基本的套接字,在以后的篇幅中会给出更详细的使用说明。 1、创建套接字——socket() 功能:使用前创建一个新的套接字 格式:SOCKET PASCAL FAR socket(int af,int type,int procotol); 参数:af: 通信发生的区域 type: 要建立的套接字类型 procotol: 使用的特定协议 2、指定本地地址——bind() 功能:将套接字地址与所创建的套接字号联系起来。 格式:int PASCAL FAR

Inno Setup FileCopy failing

徘徊边缘 提交于 2019-12-23 00:49:10
问题 I'm working on an installer that needs to create a backup of a directory prior to installing. The method I implement is purely to copy all files from the current directory to a new directory and then I am free to overwrite files (my installer) in the old directory. However, I receive a prompt indicating file copy failed , but I just cannot understand why it doesn't work. My error message prints the correct directory\filename and I can verify that they exist and aren't open in any external

Inno Setup FileCopy failing

可紊 提交于 2019-12-23 00:49:00
问题 I'm working on an installer that needs to create a backup of a directory prior to installing. The method I implement is purely to copy all files from the current directory to a new directory and then I am free to overwrite files (my installer) in the old directory. However, I receive a prompt indicating file copy failed , but I just cannot understand why it doesn't work. My error message prints the correct directory\filename and I can verify that they exist and aren't open in any external

Creating a Binary Tree for a Knockout Tournament

*爱你&永不变心* 提交于 2019-12-22 20:54:04
问题 I am trying to create a binary tree for use in a knockout tournament. The tree consists of TNodes with Left and Right pointers. This is the code that I have come up with (below); however, it runs into difficulties with the pointers in the CreateTree section. Once this creates an empty tree of large enough size, I need to add the names on the Memo1.List to the bottoms of the tree so I can pair them up for matches. How would I do this? Type TNodePtr = ^TNode; TNode = Record Data:String; Left

Creating a Binary Tree for a Knockout Tournament

霸气de小男生 提交于 2019-12-22 20:53:53
问题 I am trying to create a binary tree for use in a knockout tournament. The tree consists of TNodes with Left and Right pointers. This is the code that I have come up with (below); however, it runs into difficulties with the pointers in the CreateTree section. Once this creates an empty tree of large enough size, I need to add the names on the Memo1.List to the bottoms of the tree so I can pair them up for matches. How would I do this? Type TNodePtr = ^TNode; TNode = Record Data:String; Left

Pascal Object: how to do a typed forward declaration?

半城伤御伤魂 提交于 2019-12-22 18:27:55
问题 I'm translating the great fmod C header to Pascal, and I'm stuck because of a forward declaration. If I declare the function before the type, the error is "FMOD_CODEC_STATE: unknown", and if I declare the FMOD_CODEC_STATE before the function, the error is "FMOD_CODEC_METADATACALLBACK: unknown" Any idea how I could solve this problem? Thank you very much ! type FMOD_CODEC_STATE = Record numsubsounds: Integer; waveformat: array[0..0] of FMOD_CODEC_WAVEFORMAT; plugindata: Pointer; filehandle: