bcoder

9月 112012
 

Delphi code to get program version

 

 

 

9月 112012
 

JavaScript
getTime(new Date.getTime 方法)
返回指定的 Date 对象自 1970 年 1 月 1 日午夜(通用时间)以来的毫秒数。当比较两个或更多个 Date 对象时,使用此方法表示某一特定时刻。
返回值类型:Number — 一个整数。
Delphi
MilliSecondsBetween(StrToDateTime(‘1970-01-01 08:00:00’), Now);
注意是8点,北京时间

9月 112012
 

如果你装的是否64位系统,在控制面板->管理工具中打开的ODBC管理器也是否64位的管理器。
如果你装的ODBC驱动是32位的,则在控制面板->管理工具中打开的ODBC管理器中是看不到你安装的驱动的。

32位ODBC管理器在系统中的位置:

WIN7: C:WindowsSysWOW64odbcad32.exe

 

8月 232012
 

8月 232012
 

下面是Socket Error的错误码和描述:

Socket error 0 – Directly send error

Socket error 10004 – Interrupted function call

Socket error 10013 – Permission denied

Socket error 10014 – Bad address

Socket error 10022 – Invalid argument

Socket error 10024 – Too many open files

Socket error 10035 – Resource temporarily unavailable

Socket error 10036 – Operation now in progress

Socket error 10037 – Operation already in progress

Socket error 10038 – Socket operation on non-socket

Socket error 10039 – Destination address required

Socket error 10040 – Message too long

Socket error 10041 – Protocol wrong type for socket

Socket error 10042 – Bad protocol option

Socket error 10043 – Protocol not supported

Socket error 10044 – Socket type not supported

Socket error 10045 – Operation not supported

Socket error 10046 – Protocol family not supported

Socket error 10047 – Address family not supported by protocol family

Socket error 10048 – Address already in use

Socket error 10049 – Cannot assign requested address

Socket error 10050 – Network is down

Socket error 10051 – Network is unreachable

Socket error 10052 – Network dropped connection on reset

Socket error 10053 – Software caused connection abort

Socket error 10054 – Connection reset by peer

Socket error 10055 – No buffer space available

Socket error 10056 – Socket is already connected

Socket error 10057 – Socket is not connected

Socket error 10058 – Cannot send after socket shutdown

Socket error 10060 – Connection timed out

Socket error 10061 – Connection refused

Socket error 10064 – Host is down

Socket error 10065 – No route to host

Socket error 10067 – Too many processes

Socket error 10091 – Network subsystem is unavailable

Socket error 10092 – WINSOCK.DLL version out of range

Socket error 10093 – Successful WSAStartup not yet performed

Socket error 10094 – Graceful shutdown in progress

Socket error 11001 – Host not found

Socket error 11002 – Non-authoritative host not found

Socket error 11003 – This is a non-recoverable error

Socket error 11004 – Valid name, no data record of requested type

 

WSAEADDRINUSE (10048) Address already in use

WSAECONNABORTED (10053) Software caused connection abort

WSAECONNREFUSED (10061) Connection refused

WSAECONNRESET (10054) Connection reset by peer

WSAEDESTADDRREQ (10039) Destination address required

WSAEHOSTUNREACH (10065) No route to host

WSAEMFILE (10024) Too many open files

WSAENETDOWN (10050) Network is down

WSAENETRESET (10052) Network dropped connection

WSAENOBUFS (10055) No buffer space available

WSAENETUNREACH (10051) Network is unreachable

WSAETIMEDOUT (10060) Connection timed out

WSAHOST_NOT_FOUND (11001) Host not found

WSASYSNOTREADY (10091) Network sub-system is unavailable

WSANOTINITIALISED (10093) WSAStartup() not performed

WSANO_DATA (11004) Valid name, no data of that type

WSANO_RECOVERY (11003) Non-recoverable query error

WSATRY_AGAIN (11002) Non-authoritative host found

WSAVERNOTSUPPORTED (10092) Wrong WinSock DLL version

==================================================================

10035
1、对已使用非阻塞的套接字,又进行阻塞方式的接收式出现此错误

10038
1、对无效的套接(invalid_socket)字进行读取出报此错误

10048
1、端口、IP地址已被占用时报此错误

10014
1、Server端TCP,使用WSAAsyncSelect来接收FD_ACCEPT等消息,当窗口为最小化或者不是活动窗口里,处理FD_ACCEPT消息时,使用如下代码:accept(FSrvSock, @cAddrIn, @addrLen); addrLen未初始化,导致返回该错误代码,添加 addrLen := SizeOf(cAddrIn);初始化后问题解决。

10040
1、接收时接收的buffer为integer,发送端发送的为两个Integer,所以接收时出现此错误。

8月 202012
 

* 本例使用ListView和自定义的行部局实现了一个最基本的表格部局
* 和一个可变长度的表格部局
* 并实现的简单的行组件的单击事件

XML文件1 activity_list_view_table.xml

XML文件2 listview_row_basic.xml

XML文件3 listview_row.xml

JAVA代码文件 ListViewTableActivity.java

———————————

点击此下下载源代码

———————————

8月 132012
 

在Android中连接无线网络,输入密码后,“连接”按钮为灰色,不能使用。

原因:

1、你使用的无线路由器的密码小于8位,android系统中当无线密码不足8位时候,连接按钮不能使用,解决办法:更改路由器的密码为大于等于8位的。

8月 092012
 

本例主要是使用了Intent对象的隐式调用方式,设置intent的Action, Data和Extra来传递的相关的信息

activity布局代码如下:

类代码如下:

本代码调试环境:

* Eclipse: Indigo Service Release 2
* Android SDK: 4.0(API LEVEL 14)

点击这里下载CallMailApp

注意:

1. 如果你还没有在你的手机或者AVD上创建相关的email帐户,运行此程序时会提示Unsupported action(不支持的Action)!

8月 082012
 

1、为什么要使用service?

在我们开发的应用中,有的时候需要做一些长期运行的任务,比如下载文件、音乐播放器、闹钟或者邮件程序等。由于Android系统会根据系统资源使用情况自动清理闲置的后台程序,所以普通的Activity程序在运行一段时间后就有可能被系统清理掉,不能达到长期运行的效果。而包含service的进程属于优先权比较高的(关于进程的生命周期相关知识请点击这里查看)不容易被系统清理掉,所以对那些应用来说,选择service是必要的。

2、创建一个Service

在工程节点或者包节点上右键,选择”New->Class”,输入包名,类名称,SuperClass输入或者选择android.app.Service,点击ok,创建一个服务类成功,创建完成后初始化代码如下:

创建完成后还无法使用此服务,需要在AndroidManifestXml中声明该服务类,示例如下:

3、服务类的一些重要方法

getApplication()

Return the application that owns this service.
onBind(Intent intent)

Return the communication channel to the service.
onConfigurationChanged(Configuration newConfig)

Called by the system when the device configuration changes while your component is running.
onCreate()

Called by the system when the service is first created.
onDestroy()

Called by the system to notify a Service that it is no longer used and is being removed.
onLowMemory()

This is called when the overall system is running low on memory, and actively running processes should trim their memory usage.
onRebind(Intent intent)

Called when new clients have connected to the service, after it had previously been notified that all had disconnected in itsonUnbind(Intent).
onStart(Intent intent, int startId)

This method was deprecated in API level 5. Implement onStartCommand(Intent, int, int) instead.
onStartCommand(Intent intent, int flags, int startId)

Called by the system every time a client explicitly starts the service by calling startService(Intent), providing the arguments it supplied and a unique integer token representing the start request.
onTaskRemoved(Intent rootIntent)

This is called if the service is currently running and the user has removed a task that comes from the service’s application.
onTrimMemory(int level)

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.
onUnbind(Intent intent)

Called when all clients have disconnected from a particular interface published by the service.
startForeground(int id, Notification notification)

Make this service run in the foreground, supplying the ongoing notification to be shown to the user while in this state.
stopForeground(boolean removeNotification)

Remove this service from foreground state, allowing it to be killed if more memory is needed.
stopSelf()

Stop the service, if it was previously started.
stopSelf(int startId)

Old version of stopSelfResult(int) that doesn’t return a result.
stopSelfResult(int startId)

Stop the service if the most recent time it was started was startId.

4、Service的调用方法

Service可能通过两种方法启动,一种是通过startService另外一种是通过bindService

1) startServie的声明如下:public abstract ComponentName startService (Intent service)

参数说明:service是你要启动的服务对象,通过Intent构造,你可以在Intent对象中加入其他需要的参数,以在服务中使用。执行此函数后,如果服务未启动则系统会创建此服务并执行,如果执行此函数时服务已经在运行,则服务会继续执行。

每次调用startService时都会触发服务内的android.app.Service.onStartCommand方法,此机制提供一个方便的方法通过Intent参数传入一些需要的参数,以避免必须再使用BindService才能实现的功能。

终止由startService启动的服务方法:一种是可以在服务内部调用stopSelf()来停止服务,另一种是在调用startService的context中通过调用stopService来终止

2) bindService声明如下:public abstract boolean bindService (Intent service, ServiceConnection conn, int flags)

参数说明:
service: 是要绑定的服务的实例标识,
conn: 用于接收成功绑定或者结束绑定时的通知,在连接时可以接收service返回的对象,
flags: 为绑定选项,可能为0, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_NOT_FOREGROUND, BIND_ABOVE_CLIENT, BIND_ALLOW_OOM_MANAGEMENT, BIND_WAIVE_PRIORITY.

对于由startService启动的服务,也可以使用此函数进行绑定。如果服务没有启动,可以设置flags为BIND_AUTO_CREATE,这样执行此函数时服务会被自动创建。

只有当调用该服务存在的时候系统才认为该服务有必须继续执行代码,比如当调用该服务的Activity停止或者销毁后它绑定的服务也会停止工作。所以在执行长期操作的时候不要在bindService中执行,即不要在Service的onbind函数中启动相应的定时器,否则当activity结束后,该定时器也会不再执行工作,而应该先用startService启动服务,并在服务的onStartCommand中执行定时器操作。

 

注意:

1、在使用一个service前必须在AndroidManifest.xml中定义该服务类名称,如:<service android:name=”Em8CheckerService”></service>

8月 022012
 

Use windows api to download file in delphi

above is the code