3 |
interface |
interface |
4 |
uses |
uses |
5 |
Controls, |
Controls, |
6 |
Graphics //TColor |
Graphics, //TColor |
7 |
|
IniFiles, |
8 |
|
Windows //TFileTime |
9 |
; |
; |
10 |
|
|
11 |
type |
type |
22 |
class function TColorToHex(Color : TColor) : string; |
class function TColorToHex(Color : TColor) : string; |
23 |
class function HexToTColor(sColor : string) : TColor; |
class function HexToTColor(sColor : string) : TColor; |
24 |
|
|
25 |
|
class function AdobeReaderExists(): Boolean; |
26 |
|
|
27 |
|
class function Sto_GetFmtFileVersion(const FileName: String = ''): String; |
28 |
|
|
29 |
|
class function CheckUrl(url:string): boolean; |
30 |
|
|
31 |
|
class function FileTime2DateTime(FileTime: TFileTime): TDateTime; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
39 |
|
|
40 |
uses StrUtils, |
uses StrUtils, |
41 |
Types, //TRect , |
Types, //TRect , |
|
Windows, |
|
42 |
Messages, |
Messages, |
43 |
SysUtils //IntToStr etc |
SysUtils, //IntToStr etc |
44 |
|
Registry, |
45 |
|
wininet //CheckUrl |
46 |
|
|
47 |
; |
; |
48 |
|
|
49 |
{ |
{ |
173 |
end; |
end; |
174 |
|
|
175 |
|
|
176 |
|
class function TUtils.AdobeReaderExists(): Boolean; |
177 |
|
var |
178 |
|
AReg: TRegistry; |
179 |
|
begin |
180 |
|
result:= false; |
181 |
|
AReg := TRegistry.Create; |
182 |
|
AReg.RootKey := HKEY_LOCAL_MACHINE; |
183 |
|
if AReg.KeyExists('\SOFTWARE\Adobe\Acrobat Reader') then |
184 |
|
result:= True; |
185 |
|
AReg.Free; |
186 |
|
end; |
187 |
|
|
188 |
|
|
189 |
|
/// <summary> |
190 |
|
/// This function reads the file resource of "FileName" and returns |
191 |
|
/// the version number as formatted text.</summary> |
192 |
|
/// <example> |
193 |
|
/// Sto_GetFmtFileVersion() = '4.13.128.0' |
194 |
|
/// Sto_GetFmtFileVersion('', '%.2d-%.2d-%.2d') = '04-13-128' |
195 |
|
/// </example> |
196 |
|
/// <remarks>If "Fmt" is invalid, the function may raise an |
197 |
|
/// EConvertError exception.</remarks> |
198 |
|
/// <param name="FileName">Full path to exe or dll. If an empty |
199 |
|
/// string is passed, the function uses the filename of the |
200 |
|
/// running exe or dll.</param> |
201 |
|
/// <param name="Fmt">Format string, you can use at most four integer |
202 |
|
/// values.</param> |
203 |
|
/// <returns>Formatted version number of file, '' if no version |
204 |
|
/// resource found.</returns> |
205 |
|
class function TUtils.Sto_GetFmtFileVersion(const FileName: String = ''): String; |
206 |
|
var |
207 |
|
sFileName: String; |
208 |
|
iBufferSize: DWORD; |
209 |
|
iDummy: DWORD; |
210 |
|
pBuffer: Pointer; |
211 |
|
pFileInfo: Pointer; |
212 |
|
iVer: array[1..4] of Integer; |
213 |
|
begin |
214 |
|
// set default value |
215 |
|
Result := ''; |
216 |
|
// get filename of exe/dll if no filename is specified |
217 |
|
sFileName := Trim(FileName); |
218 |
|
if (sFileName = '') then |
219 |
|
sFileName := GetModuleName(HInstance); |
220 |
|
// get size of version info (0 if no version info exists) |
221 |
|
iBufferSize := GetFileVersionInfoSize(PChar(sFileName), iDummy); |
222 |
|
if (iBufferSize > 0) then |
223 |
|
begin |
224 |
|
GetMem(pBuffer, iBufferSize); |
225 |
|
try |
226 |
|
// get fixed file info (language independent) |
227 |
|
GetFileVersionInfo(PChar(sFileName), 0, iBufferSize, pBuffer); |
228 |
|
VerQueryValue(pBuffer, '\', pFileInfo, iDummy); |
229 |
|
// read version blocks |
230 |
|
iVer[1] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS); |
231 |
|
iVer[2] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS); |
232 |
|
iVer[3] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS); |
233 |
|
iVer[4] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS); |
234 |
|
finally |
235 |
|
FreeMem(pBuffer); |
236 |
|
end; |
237 |
|
|
238 |
|
// format result string |
239 |
|
Result := Format('%d.%d.%d.%d', [iVer[1], iVer[2], iVer[3], iVer[4]]); |
240 |
|
|
241 |
|
end; |
242 |
|
end; |
243 |
|
|
244 |
|
|
245 |
|
class function TUtils.CheckUrl(url:string):boolean; |
246 |
|
var |
247 |
|
hSession, hfile: hInternet; |
248 |
|
dwindex,dwcodelen :dword; |
249 |
|
dwcode:array[1..20] of char; |
250 |
|
res : pchar; |
251 |
|
begin |
252 |
|
if pos('http://',lowercase(url))=0 then |
253 |
|
url := 'http://'+url; |
254 |
|
Result := false; |
255 |
|
hSession := InternetOpen('InetURL:/1.0', |
256 |
|
INTERNET_OPEN_TYPE_PRECONFIG, |
257 |
|
nil, |
258 |
|
nil, |
259 |
|
0); |
260 |
|
if assigned(hsession) then |
261 |
|
begin |
262 |
|
hfile := InternetOpenUrl(hsession, |
263 |
|
pchar(url), |
264 |
|
nil, |
265 |
|
0, |
266 |
|
INTERNET_FLAG_RELOAD, |
267 |
|
0); |
268 |
|
dwIndex := 0; |
269 |
|
dwCodeLen := 10; |
270 |
|
HttpQueryInfo(hfile, |
271 |
|
HTTP_QUERY_STATUS_CODE, |
272 |
|
@dwcode, |
273 |
|
dwcodeLen, |
274 |
|
dwIndex); |
275 |
|
res := pchar(@dwcode); |
276 |
|
result:= (res ='200') or (res ='302'); |
277 |
|
if assigned(hfile) then |
278 |
|
InternetCloseHandle(hfile); |
279 |
|
InternetCloseHandle(hsession); |
280 |
|
end; |
281 |
|
|
282 |
|
end; |
283 |
|
|
284 |
|
|
285 |
|
class function TUtils.FileTime2DateTime(FileTime: TFileTime): TDateTime; |
286 |
|
var |
287 |
|
LocalFileTime: TFileTime; |
288 |
|
SystemTime: TSystemTime; |
289 |
|
begin |
290 |
|
FileTimeToLocalFileTime(FileTime, LocalFileTime) ; |
291 |
|
FileTimeToSystemTime(LocalFileTime, SystemTime) ; |
292 |
|
Result := SystemTimeToDateTime(SystemTime) ; |
293 |
|
end; |
294 |
|
|
295 |
|
|
296 |
end. |
end. |