Changeset 315 for trunk/Packages/Common/Common.pas
- Timestamp:
- Jun 19, 2024, 11:15:44 PM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Common.pas
r314 r315 1 unit UCommon; 2 3 {$mode delphi} 1 unit Common; 4 2 5 3 interface … … 8 6 {$IFDEF WINDOWS}Windows,{$ENDIF} 9 7 {$IFDEF UNIX}baseunix,{$ENDIF} 10 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 11 FileUtil ; //, ShFolder, ShellAPI;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: string; List: TList<string>): string; 68 function Implode(Separator: string; List: TStringList; Around: string = ''): string; 64 69 function LastPos(const SubStr: String; const S: String): Integer; 65 70 function LoadFileToStr(const FileName: TFileName): AnsiString; 66 71 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 67 function MergeArray(A, B: array of string): T ArrayOfString;72 function MergeArray(A, B: array of string): TStringArray; 68 73 function OccurenceOfChar(What: Char; Where: string): Integer; 69 74 procedure OpenWebPage(URL: string); 75 procedure OpenEmail(Email: string); 70 76 procedure OpenFileInShell(FileName: string); 71 77 function PosFromIndex(SubStr: string; Text: string; … … 83 89 function SplitString(var Text: string; Count: Word): string; 84 90 function StripTags(const S: string): string; 85 function TryHexToInt(Data: string; varValue: Integer): Boolean;86 function TryBinToInt(Data: string; varValue: Integer): Boolean;91 function TryHexToInt(Data: string; out Value: Integer): Boolean; 92 function TryBinToInt(Data: string; out Value: Integer): Boolean; 87 93 procedure SortStrings(Strings: TStrings); 88 94 … … 201 207 end;*) 202 208 209 function Implode(Separator: string; List: TStringList; Around: string = ''): string; 210 var 211 I: Integer; 212 begin 213 Result := ''; 214 for I := 0 to List.Count - 1 do begin 215 Result := Result + Around + List[I] + Around; 216 if I < List.Count - 1 then Result := Result + Separator; 217 end; 218 end; 219 203 220 function LastPos(const SubStr: String; const S: String): Integer; 204 221 begin … … 246 263 end; 247 264 248 function TryHexToInt(Data: string; varValue: Integer): Boolean;265 function TryHexToInt(Data: string; out Value: Integer): Boolean; 249 266 var 250 267 I: Integer; … … 262 279 end; 263 280 264 function TryBinToInt(Data: string; varValue: Integer): Boolean;281 function TryBinToInt(Data: string; out Value: Integer): Boolean; 265 282 var 266 283 I: Integer; … … 290 307 end; 291 308 292 function Explode(Separator: char; Data: string): TArrayOfString; 293 begin 294 Result := nil; 295 SetLength(Result, 0); 296 while Pos(Separator, Data) > 0 do begin 309 function Explode(Separator: Char; Data: string): TStringArray; 310 var 311 Index: Integer; 312 begin 313 Result := Default(TStringArray); 314 repeat 315 Index := Pos(Separator, Data); 316 if Index > 0 then begin 317 SetLength(Result, Length(Result) + 1); 318 Result[High(Result)] := Copy(Data, 1, Index - 1); 319 Delete(Data, 1, Index); 320 end else Break; 321 until False; 322 if Data <> '' then begin 297 323 SetLength(Result, Length(Result) + 1); 298 Result[High(Result)] := Copy(Data, 1, Pos(Separator, Data) - 1); 299 Delete(Data, 1, Pos(Separator, Data)); 300 end; 301 SetLength(Result, Length(Result) + 1); 302 Result[High(Result)] := Data; 303 end; 304 305 {$IFDEF Windows} 324 Result[High(Result)] := Data; 325 end; 326 end; 327 328 function Implode(Separator: string; List: TList<string>): string; 329 var 330 I: Integer; 331 begin 332 Result := ''; 333 for I := 0 to List.Count - 1 do begin 334 Result := Result + List[I]; 335 if I < List.Count - 1 then Result := Result + Separator; 336 end; 337 end; 338 339 {$IFDEF WINDOWS} 306 340 function GetUserName: string; 307 341 const … … 311 345 begin 312 346 L := MAX_USERNAME_LENGTH + 2; 347 Result := Default(string); 313 348 SetLength(Result, L); 314 349 if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin … … 324 359 end; 325 360 end; 326 {$ endif}361 {$ENDIF} 327 362 328 363 function ComputerName: string; 329 {$ ifdef mswindows}364 {$IFDEF WINDOWS} 330 365 const 331 366 INFO_BUFFER_SIZE = 32767; … … 342 377 end; 343 378 end; 344 {$ endif}345 {$ ifdef unix}379 {$ENDIF} 380 {$IFDEF UNIX} 346 381 var 347 382 Name: UtsName; … … 351 386 Result := Name.Nodename; 352 387 end; 353 {$ endif}354 355 {$ ifdef windows}388 {$ENDIF} 389 390 {$IFDEF WINDOWS} 356 391 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 357 392 const … … 431 466 procedure LoadLibraries; 432 467 begin 433 {$IFDEF W indows}468 {$IFDEF WINDOWS} 434 469 DLLHandle1 := LoadLibrary('secur32.dll'); 435 470 if DLLHandle1 <> 0 then … … 442 477 procedure FreeLibraries; 443 478 begin 444 {$IFDEF W indows}479 {$IFDEF WINDOWS} 445 480 if DLLHandle1 <> 0 then FreeLibrary(DLLHandle1); 446 481 {$ENDIF} … … 475 510 end; 476 511 512 procedure OpenEmail(Email: string); 513 begin 514 OpenURL('mailto:' + Email); 515 end; 516 477 517 procedure OpenFileInShell(FileName: string); 478 518 begin … … 503 543 end; 504 544 505 function MergeArray(A, B: array of string): T ArrayOfString;506 var 507 I: Integer; 508 begin 509 Result := Default(T ArrayOfString);545 function MergeArray(A, B: array of string): TStringArray; 546 var 547 I: Integer; 548 begin 549 Result := Default(TStringArray); 510 550 SetLength(Result, Length(A) + Length(B)); 511 551 for I := 0 to Length(A) - 1 do
Note:
See TracChangeset
for help on using the changeset viewer.