Changeset 54 for trunk/Packages/Common/UCommon.pas
- Timestamp:
- Dec 24, 2022, 7:17:24 PM (23 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 6 6 Tunneler.dbg 7 7 tunneler.lps 8 *.res 8 9 heaptrclog.trc 9 10 Components/Common/Languages/*.mo 10 Components/CoolTranslator/Demo/lib 11
-
- Property svn:ignore
-
trunk/Packages/Common/UCommon.pas
r51 r54 1 1 unit UCommon; 2 2 3 {$mode delphi}4 5 3 interface 6 4 7 5 uses 8 {$ ifdef Windows}Windows,{$endif}9 {$ ifdef Linux}baseunix,{$endif}10 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 11 FileUtil ; //, ShFolder, ShellAPI;6 {$IFDEF WINDOWS}Windows,{$ENDIF} 7 {$IFDEF UNIX}baseunix,{$ENDIF} 8 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, Graphics, 9 FileUtil, Generics.Collections; //, ShFolder, ShellAPI; 12 10 13 11 type 14 12 TArrayOfByte = array of Byte; 15 TArrayOfString = array of string;16 13 TExceptionEvent = procedure(Sender: TObject; E: Exception) of object; 17 14 … … 35 32 DLLHandle1: HModule; 36 33 37 {$IFDEF Windows} 38 GetUserNameEx: procedure (NameFormat: DWORD; 39 lpNameBuffer: LPSTR; nSize: PULONG); stdcall; 40 {$ENDIF} 34 {$IFDEF WINDOWS} 35 GetUserNameEx: procedure (NameFormat: DWORD; 36 lpNameBuffer: LPSTR; nSize: PULONG); stdcall; 37 {$ENDIF} 38 39 const 40 clLightBlue = TColor($FF8080); 41 clLightGreen = TColor($80FF80); 42 clLightRed = TColor($8080FF); 41 43 42 44 function AddLeadingZeroes(const aNumber, Length : integer) : string; … … 51 53 function ComputerName: string; 52 54 procedure DeleteFiles(APath, AFileSpec: string); 55 function Explode(Separator: Char; Data: string): TStringArray; 53 56 procedure ExecuteProgram(Executable: string; Parameters: array of string); 54 57 procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog); … … 62 65 function GetFileFilterItemExt(Filter: string; Index: Integer): string; 63 66 function IntToBin(Data: Int64; Count: Byte): string; 67 function Implode(Separator: Char; List: TList<string>): string; 64 68 function LastPos(const SubStr: String; const S: String): Integer; 65 69 function LoadFileToStr(const FileName: TFileName): AnsiString; 66 70 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 67 function MergeArray(A, B: array of string): T ArrayOfString;71 function MergeArray(A, B: array of string): TStringArray; 68 72 function OccurenceOfChar(What: Char; Where: string): Integer; 69 73 procedure OpenWebPage(URL: string); 74 procedure OpenEmail(Email: string); 70 75 procedure OpenFileInShell(FileName: string); 71 76 function PosFromIndex(SubStr: string; Text: string; … … 83 88 function SplitString(var Text: string; Count: Word): string; 84 89 function StripTags(const S: string): string; 85 function TryHexToInt(Data: string; varValue: Integer): Boolean;86 function TryBinToInt(Data: string; varValue: Integer): Boolean;90 function TryHexToInt(Data: string; out Value: Integer): Boolean; 91 function TryBinToInt(Data: string; out Value: Integer): Boolean; 87 92 procedure SortStrings(Strings: TStrings); 88 93 … … 246 251 end; 247 252 248 function TryHexToInt(Data: string; varValue: Integer): Boolean;253 function TryHexToInt(Data: string; out Value: Integer): Boolean; 249 254 var 250 255 I: Integer; … … 262 267 end; 263 268 264 function TryBinToInt(Data: string; varValue: Integer): Boolean;269 function TryBinToInt(Data: string; out Value: Integer): Boolean; 265 270 var 266 271 I: Integer; … … 290 295 end; 291 296 292 function Explode(Separator: char; Data: string): TArrayOfString; 293 begin 294 SetLength(Result, 0); 295 while Pos(Separator, Data) > 0 do begin 297 function Explode(Separator: Char; Data: string): TStringArray; 298 var 299 Index: Integer; 300 begin 301 Result := Default(TStringArray); 302 repeat 303 Index := Pos(Separator, Data); 304 if Index > 0 then begin 305 SetLength(Result, Length(Result) + 1); 306 Result[High(Result)] := Copy(Data, 1, Index - 1); 307 Delete(Data, 1, Index); 308 end else Break; 309 until False; 310 if Data <> '' then begin 296 311 SetLength(Result, Length(Result) + 1); 297 Result[High(Result)] := Copy(Data, 1, Pos(Separator, Data) - 1); 298 Delete(Data, 1, Pos(Separator, Data)); 299 end; 300 SetLength(Result, Length(Result) + 1); 301 Result[High(Result)] := Data; 302 end; 303 304 {$IFDEF Windows} 312 Result[High(Result)] := Data; 313 end; 314 end; 315 316 function Implode(Separator: Char; List: TList<string>): string; 317 var 318 I: Integer; 319 begin 320 Result := ''; 321 for I := 0 to List.Count - 1 do begin 322 Result := Result + List[I]; 323 if I < List.Count - 1 then Result := Result + Separator; 324 end; 325 end; 326 327 {$IFDEF WINDOWS} 305 328 function GetUserName: string; 306 329 const … … 310 333 begin 311 334 L := MAX_USERNAME_LENGTH + 2; 335 Result := Default(string); 312 336 SetLength(Result, L); 313 337 if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin … … 323 347 end; 324 348 end; 325 {$ endif}349 {$ENDIF} 326 350 327 351 function ComputerName: string; 328 {$ ifdef mswindows}352 {$IFDEF WINDOWS} 329 353 const 330 354 INFO_BUFFER_SIZE = 32767; … … 341 365 end; 342 366 end; 343 {$ endif}344 {$ ifdef unix}367 {$ENDIF} 368 {$IFDEF UNIX} 345 369 var 346 370 Name: UtsName; 347 371 begin 372 Name := Default(UtsName); 348 373 fpuname(Name); 349 374 Result := Name.Nodename; 350 375 end; 351 {$ endif}352 353 {$ ifdef windows}376 {$ENDIF} 377 378 {$IFDEF WINDOWS} 354 379 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 355 380 const … … 429 454 procedure LoadLibraries; 430 455 begin 431 {$IFDEF W indows}456 {$IFDEF WINDOWS} 432 457 DLLHandle1 := LoadLibrary('secur32.dll'); 433 458 if DLLHandle1 <> 0 then … … 440 465 procedure FreeLibraries; 441 466 begin 442 {$IFDEF W indows}467 {$IFDEF WINDOWS} 443 468 if DLLHandle1 <> 0 then FreeLibrary(DLLHandle1); 444 469 {$ENDIF} … … 473 498 end; 474 499 500 procedure OpenEmail(Email: string); 501 begin 502 OpenURL('mailto:' + Email); 503 end; 504 475 505 procedure OpenFileInShell(FileName: string); 476 506 begin … … 501 531 end; 502 532 503 function MergeArray(A, B: array of string): TArrayOfString; 504 var 505 I: Integer; 506 begin 533 function MergeArray(A, B: array of string): TStringArray; 534 var 535 I: Integer; 536 begin 537 Result := Default(TStringArray); 507 538 SetLength(Result, Length(A) + Length(B)); 508 539 for I := 0 to Length(A) - 1 do
Note:
See TracChangeset
for help on using the changeset viewer.