这个函数用于获取计算机上首个未使用的 TCP 端口以便程序使用。有时候我们并不需要一个固定的端口来提供服务,通过这个函数,我们就可以找到一个可用的端口了。这个函数如果返回 0 ,则没有任何可用的端口(几率几乎为 0 吧?),同样的方法也可以用于获取可用的 UDP 端口,换个函数而已。 [crayon-62c6c8eac
月度归档: 2015年6月
QPlugins – 基本的原型演示程序已经出来了,欢迎大家测试并提供建议
昨天到今天,我根据自己的想法,将 QPlugins 插件引擎的框架给搭了下。欢迎有兴趣的朋友加入讨论和参考。 首先,QPlugins 插件框架是一个可替换的框架,所有的一切都可以被替换(All can replace),包括插件管理器自身。当然了,替换插件管理器这个有几个方法,直接实现一个新的 IQPluginsMan
QWorker 更新 – TQPlanMask 新增 OnAcceptTime 事件以支持用户自定义的计划任务等更新
【更新说明】 TQPlanMask新增了三个成员: OnAcceptTime:用于让用户自行确定某个时间点是否应该执行计划任务作业; StartTime:用于确定计划任务作业的起始生效时间 StopTime:用于确定计划任务作业的结束时间 注意,如果设置了StartTime 和 StopTime,则必需保证 Start
[QDB] FireDAC -> QDB 的流转换器正在开发中,目前已经能读取数据
虽然不完善,但是一个好的开始。这个是直接从 FireDAC 的二进制格式解析生成的数据,不需要 FireDAC 相关的单元,通过 TQFDConverter 直接解析文件数据来完成。这样大家在设计手机端程序时,就可以直接用 QDataSet 代替 FireDAC 的相关组件。 要将 FireDAC 的数据
一个 HTTP URL 解析和编码的辅助实现
首先,一个 HTTP 的 URL 有下面几个部分组成: 协议类型。是 HTTP 还是 HTTPS 协议,分别对应于 http:// 和 https://; 用户名和密码。这个位于协议类型的后面,用户名和密码之间采用 “:” 进行分隔,跟主机的域名或IP部分用 ‘@’ 符号进行分隔; 域名或IP地
【Delphi】玩转浮点数转整数
Delphi中提供了三个函数: Trunc: 将浮点数的整数部分返回。 Round: 将浮点数四舍五入后返回整数部分。 Int: 将浮点数的小数部分去掉,返回只保留了整数部分的Extended型。 在D2007 + Win7 + Intel平台下测试, 由于Int返回的并非整型,我们把它排除掉。测试结果是 Round
[VCL]控件对齐方式增强函数
VCL 的 TAlign 的功能比较弱,有时候,无法满足我们对齐的需要,所以这里提供了一个额外的 CustomAlign 函数来实现更多的对齐方式。当然,如果你是用 FMX 的话,这些对齐方式已经有了,你可以忽略这篇文章。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
type TCustomAlign = (caNone, caTop, caLeft, caRight, caBottom, caClient, caCenter, caVertCenter, caHorzCenter, caHorizontal, caVertical); procedure CustomAlign(ACtrl: TControl; ALayout: TCustomAlign); implementation procedure CustomAlign(ACtrl: TControl; ALayout: TCustomAlign); var R: TRect; begin if ALayout <> caNone then begin if ACtrl is TCustomForm then R := (ACtrl as TCustomForm).Monitor.BoundsRect else R := ACtrl.Parent.ClientRect; ACtrl.Align:=alNone; case ALayout of caTop: ACtrl.SetBounds(R.Left, R.Top, R.Width, ACtrl.Height); caLeft: ACtrl.SetBounds(R.Left, R.Top, ACtrl.Width, R.Height); caRight: ACtrl.SetBounds(R.Right - ACtrl.Width, R.Top, ACtrl.Width, R.Height); caBottom: ACtrl.SetBounds(R.Left, R.Bottom - ACtrl.Height, R.Width, ACtrl.Height); caClient: ACtrl.SetBounds(R.Left, R.Top, R.Width, R.Height); caCenter: ACtrl.SetBounds(R.Left + (R.Width - ACtrl.Width) div 2, R.Top + (R.Height - ACtrl.Height) div 2, ACtrl.Width, ACtrl.Height); caVertCenter: ACtrl.SetBounds(ACtrl.Left, R.Top + (R.Height - ACtrl.Height) div 2, ACtrl.Width, ACtrl.Height); caHorzCenter: ACtrl.SetBounds(ACtrl.Left + (R.Width - ACtrl.Width) div 2, ACtrl.Top, ACtrl.Width, ACtrl.Height); caHorizontal: ACtrl.SetBounds(R.Left, ACtrl.Top, R.Width, ACtrl.Height); caVertical: ACtrl.SetBounds(ACtrl.Left, R.Top, ACtrl.Width, R.Height); end; end; end; |
当然,如果想要达到FMX的对齐
QWorker 更新 – 修正了 TQJobGroup.Cancel 的一处Bug
【错误描述】 TQJobGroup.Cancel 调用了 TQSimpleJobs.Clear 来清除与自身相关的所有作业,而 TQSimpleJobs.Clear 时,只检查了作业的关联作业函数所隶属的对象,没有检查对应的分组,从而引发此问题。 【更新描述】 1、修正了前述错误; 2、修改了 TQJobGroup.C
[XE8 Bug]-粘贴带有||内容的数据时IDE死掉
创建一个新的 Delphi 工具,然后粘贴类似下面包含 || 的文字: abc||def 结果IDE就会死掉,问题出在新增的Castalia,将注册表: HKEY_CURRENT_USER\Software\Embarcadero\BDS\16.0\Known IDE Packages\Delphi 下对应的项目删除就
【Delphi】GMT时间与TDateTime转换
说到GMT时间,人们天天都在用,但一般人不会被注意到。 在Http的世界里面,GMT无处不在,不信你抓包看看各种Header里面。 GMT是世界时间,在处理的时候需要处理当前的时区。 算了,我懒得多说,直接贴代码吧。吹吹牛,我这个可以高性能的哦~~~~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
const Convert: array[0..255] of Integer = ( -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 ); function PCharToIntDef(const S: PAnsichar; Len: Integer; def: Integer = 0): Integer; var I: Integer; v: Integer; begin Result := 0; for I := 0 to len-1 do begin V := Convert[ord(s[i])]; if V<0 then begin Result := def; Exit; end; result := (result * 10) + V; end; end; function LocalTimeZoneBias: Integer; {$IFDEF LINUX} var TV: TTimeval; TZ: TTimezone; begin gettimeofday(TV, TZ); Result := TZ.tz_minuteswest; end; {$ELSE} var TimeZoneInformation: TTimeZoneInformation; Bias: Longint; begin case GetTimeZoneInformation(TimeZoneInformation) of TIME_ZONE_ID_STANDARD: Bias := TimeZoneInformation.Bias + TimeZoneInformation.StandardBias; TIME_ZONE_ID_DAYLIGHT: Bias := TimeZoneInformation.Bias + ((TimeZoneInformation.DaylightBias div 60) * -100); else Bias := TimeZoneInformation.Bias; end; Result := Bias; end; {$ENDIF} var DLocalTimeZoneBias: Double = 0; function DateTimeToGMT(const DT: TDateTime): TDateTime; inline; begin Result := DT + DLocalTimeZoneBias; end; function GMTToDateTime(const DT: TDateTime): TDateTime; inline; begin Result := DT - DLocalTimeZoneBias; end; function DateTimeToGMTRFC822(const DateTime: TDateTime): string; const WEEK: array[1..7] of string = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); STR_ENGLISH_M: array[1..12] of string = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); var wWeek, wYear, wMonth, wDay, wHour, wMin, wSec, wMilliSec: Word; begin DecodeDateTime(DateTimeToGMT(DateTime), wYear, wMonth, wDay, wHour, wMin, wSec, wMilliSec); wWeek := DayOfWeek(DateTimeToGMT(DateTime)); Result := Format('%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT', [WEEK[wWeek], wDay, STR_ENGLISH_M[wMonth], wYear, wHour, wMin, wSec]); end; function GMTRFC822ToDateTime(const pSour: AnsiString): TDateTime; function GetMonthDig(const Value: PAnsiChar): Integer; const STR_ENGLISH_M: array[1..12] of PAnsiChar = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); begin for Result := Low(STR_ENGLISH_M) to High(STR_ENGLISH_M) do begin if StrLIComp(Value, STR_ENGLISH_M[Result], 3) = 0 then Exit; end; Result := 0; end; var P1, P2, PMax: PAnsiChar; wDay, wMonth, wYear, wHour, wMinute, wSec: SmallInt; begin Result := 0; if Length(pSour) < 25 then Exit; P1 := Pointer(pSour); P2 := P1; PMax := P1 + Length(pSour); while (P1 < PMax) and (P1^ <> ',') do Inc(P1); Inc(P1); if (P1^ <> #32) and (P1 - P2 < 4) then Exit; Inc(P1); P2 := P1; while (P1 < PMax) and (P1^ <> #32) do Inc(P1); if (P1^ <> #32) then Exit; wDay := PCharToIntDef(P2, P1 - P2); if wDay = 0 then Exit; Inc(P1); P2 := P1; while (P1 < PMax) and (P1^ <> #32) do Inc(P1); if (P1^ <> #32) and (P1 - P2 < 3) then Exit; wMonth := GetMonthDig(P2); Inc(P1); P2 := P1; while (P1 < PMax) and (P1^ <> #32) do Inc(P1); if (P1^ <> #32) then Exit; wYear := PCharToIntDef(P2, P1 - P2); if wYear = 0 then Exit; Inc(P1); P2 := P1; while (P1 < PMax) and (P1^ <> ':') do Inc(P1); if (P1^ <> ':') then Exit; wHour := PCharToIntDef(P2, P1 - P2); if wHour = 0 then Exit; Inc(P1); P2 := P1; while (P1 < PMax) and (P1^ <> ':') do Inc(P1); if (P1^ <> ':') then Exit; wMinute := PCharToIntDef(P2, P1 - P2); if wMinute = 0 then Exit; Inc(P1); P2 := P1; while (P1 < PMax) and (P1^ <> #32) do Inc(P1); if (P1^ <> #32) then Exit; wSec := PCharToIntDef(P2, P1 - P2); if wSec = 0 then Exit; Result := GMTToDateTime(EnCodeDateTime(wYear, wMonth, wDay, wHour, wMinute, wSec, 0)); end; initialization DLocalTimeZoneBias := LocalTimeZoneBias / 1440; |
将一个浮点数转换为不小于或不大于该值的最小或最大整数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
function RoundX(v: Double): Double; var APower: Integer; ANeg: Boolean; begin if IsZero(v) then Result := 0 else begin APower := 0; ANeg := v < 0; if ANeg then v := -v; while v < 1 do begin v := v * 10; Dec(APower); end; while v > 10 do begin v := v / 10; Inc(APower); end; if not IsZero(v - Trunc(v)) then Result := (Trunc(v) + 1) * power(10, APower) else Result := Trunc(v) * power(10, APower); if ANeg then Result := -Result; end; end; |
RoundX(1.5) = 2 RoundX(123) = 200 RoundX(-1.5) = -2 RoundX(-123)=-200
[GLScene] – 将屏幕坐标转换为三维世界坐标
GLScene通过TGLSceneViewer.Buffer 提供了几个函数: ScreenToWorld 将屏幕坐标转换为三维世界绝对坐标 PixelRayToWorld 将屏幕坐标转换为当前像素对应点对象所处的三维世界绝对坐标 好了,没什么废话。
[MyBean-插件]MyBean通用报表免费无限制版本发布
【优点】 1.开发时无需安装报表组件(可以直接用编译好的文件,注意版权说明,请自行编译一次相应的报表插件文件)。 2.无带包烦恼所有版本Delphi都可以使用,不拖累Delphi版本的升级。 3.可以实现单据的多种样式设计, 报
【原创分享】LookImage 图像查看器
从很早以前开始,我就用自己编写的图像查看器浏览图片了。至于为什么要这样,可能当初是为了煅炼技术,也可能是作为程序员的一点点自娱自乐的习惯,还有可能就是感觉用自己的亲手开发的工具有成就感。LookImage很多年前就存在了,从最开始的VB版本,到至今的Delphi重新编码版,从最开始的仅仅能查看bmp、jpg,到现在能支
不完美-FMX 程序中避免输入焦点被虚拟键盘遮挡
【更新】 2017.3.27 增加对 10.2 版的兼容,请 SVN 直接检出或单独下载 2016.8.24 修正了 ScrollBox 滚动过程中调整位置造成错位的问题 2016.7.29 修正了当设置了最后一个焦点控件的ReturnType 为 Next 时,回车会出现 Access Volation 的问题 修正