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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811
|
{
/***************************************************************************
lclproc.pas
-----------
Component Library Code
***************************************************************************/
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Useful lower level helper functions and classes.
}
unit LCLProc;
{$MODE ObjFPC}{$H+}
{$I lcl_defines.inc}
{$inline on}
interface
uses
{$IFDEF Darwin}MacOSAll, {$ENDIF}
Classes, SysUtils, Math, TypInfo, Types, Laz_AVL_Tree,
// LazUtils
FPCAdds, LazFileUtils, LazUtilities, LazMethodList, LazUTF8, LazUTF8Classes,
LazLoggerBase, LazTracer,
// LCL
LCLStrConsts, LCLType;
type
TMethodList = LazMethodList.TMethodList;
{ TDebugLCLItemInfo }
TDebugLCLItemInfo = class
public
Item: Pointer;
IsDestroyed: boolean;
Info: string;
CreationStack: TStackTracePointers; // stack trace at creationg
DestructionStack: TStackTracePointers;// stack trace at destruction
function AsString(WithStackTraces: boolean): string;
destructor Destroy; override;
end;
{ TDebugLCLItems }
TDebugLCLItems = class
private
FItems: TAvlTree;// tree of TDebugLCLItemInfo
FName: string;
public
constructor Create(const TheName: string);
destructor Destroy; override;
function FindInfo(p: Pointer; CreateIfNotExists: boolean = false
): TDebugLCLItemInfo;
function IsDestroyed(p: Pointer): boolean;
function IsCreated(p: Pointer): boolean;
function MarkCreated(p: Pointer; const InfoText: string): TDebugLCLItemInfo;
procedure MarkDestroyed(p: Pointer);
function GetInfo(p: Pointer; WithStackTraces: boolean): string;
property Name: string read FName;
end;
{$IFDEF DebugLCLComponents}
var
DebugLCLComponents: TDebugLCLItems = nil;
{$ENDIF}
function CompareDebugLCLItemInfos(Data1, Data2: Pointer): integer;
function CompareItemWithDebugLCLItemInfo(Item, DebugItemInfo: Pointer): integer;
type
TStringsSortCompare = function(const Item1, Item2: string): Integer;
procedure MergeSort(List: TFPList; const OnCompare: TListSortCompare); overload;// sort so that for each i is OnCompare(List[i],List[i+1])<=0
procedure MergeSort(List: TFPList; StartIndex, EndIndex: integer; const OnCompare: TListSortCompare); overload;// sort so that for each i is OnCompare(List[i],List[i+1])<=0
procedure MergeSort(List: TStrings; const OnCompare: TStringsSortCompare); overload;// sort so that for each i is OnCompare(List[i],List[i+1])<=0
function GetEnumValueDef(TypeInfo: PTypeInfo; const Name: string;
const DefaultValue: Integer): Integer;
function KeyAndShiftStateToKeyString(Key: word; ShiftState: TShiftState): String;
function KeyStringIsIrregular(const s: string): boolean;
function ShortCutToText(ShortCut: TShortCut): string;// localized output
function ShortCutToTextRaw(ShortCut: TShortCut): string;// NOT localized output
function TextToShortCut(const ShortCutText: string): TShortCut;// localized input
function TextToShortCutRaw(const ShortCutText: string): TShortCut;// NOT localized input
function GetCompleteText(const sText: string; iSelStart: Integer;
bCaseSensitive, bSearchAscending: Boolean; slTextList: TStrings): string;
function IsEditableTextKey(Key: Word): Boolean;
// Hooks used to prevent unit circles
type
TSendApplicationMessageFunction =
function(Msg: Cardinal; WParam: WParam; LParam: LParam):Longint;
TOwnerFormDesignerModifiedProc =
procedure(AComponent: TComponent);
var
SendApplicationMessageFunction: TSendApplicationMessageFunction=nil;
OwnerFormDesignerModifiedProc: TOwnerFormDesignerModifiedProc=nil;
function SendApplicationMessage(Msg: Cardinal; WParam: WParam; LParam: LParam):Longint;
procedure OwnerFormDesignerModified(AComponent: TComponent);
procedure FreeThenNil(var obj);
{ the LCL interfaces finalization sections are called before the finalization
sections of the LCL. Those parts, that should be finalized after the LCL, can
be registered here. }
procedure RegisterInterfaceInitializationHandler(p: TProcedure);
procedure CallInterfaceInitializationHandlers;
procedure RegisterInterfaceFinalizationHandler(p: TProcedure);
procedure CallInterfaceFinalizationHandlers;
function OffsetRect(var ARect: TRect; dx, dy: Integer): Boolean;
procedure MoveRect(var ARect: TRect; x, y: Integer);
procedure MoveRectToFit(var ARect: TRect; const MaxRect: TRect);
procedure MakeMinMax(var i1, i2: integer);
procedure CalculateLeftTopWidthHeight(X1,Y1,X2,Y2: integer;
out Left,Top,Width,Height: integer);
function DeleteAmpersands(var Str : String) : Longint;
function ComparePointers(p1, p2: Pointer): integer; inline;
function CompareHandles(h1, h2: THandle): integer;
function CompareRect(R1, R2: PRect): Boolean;
function ComparePoints(const p1, p2: TPoint): integer;
function CompareCaret(const FirstCaret, SecondCaret: TPoint): integer;
function CompareMethods(const m1, m2: TMethod): boolean; inline;
function RoundToInt(const e: Extended): integer;
function RoundToCardinal(const e: Extended): cardinal;
function TruncToInt(const e: Extended): integer;
function TruncToCardinal(const e: Extended): cardinal;
function StrToDouble(const s: string): double;
// Call debugging procedure in LazLoggerBase.
procedure RaiseGDBException(const Msg: string); inline;
{$IFnDEF WithOldDebugln}
procedure DbgOut(const s: string = ''); inline; overload;
procedure DbgOut(Args: array of const); {inline;} overload;
procedure DbgOut(const S: String; Args: array of const); {inline;} overload;// similar to Format(s,Args)
procedure DbgOut(const s1, s2: string; const s3: string = '';
const s4: string = ''; const s5: string = ''; const s6: string = '';
const s7: string = ''; const s8: string = ''; const s9: string = '';
const s10: string = ''; const s11: string = ''; const s12: string = '';
const s13: string = ''; const s14: string = ''; const s15: string = '';
const s16: string = ''; const s17: string = ''; const s18: string = ''); inline; overload;
procedure DebugLn(const s: string = ''); inline; overload;
procedure DebugLn(Args: array of const); {inline;} overload;
procedure DebugLn(const S: String; Args: array of const); {inline;} overload;// similar to Format(s,Args)
procedure DebugLn(const s1, s2: string; const s3: string = '';
const s4: string = ''; const s5: string = ''; const s6: string = '';
const s7: string = ''; const s8: string = ''; const s9: string = '';
const s10: string = ''; const s11: string = ''; const s12: string = '';
const s13: string = ''; const s14: string = ''; const s15: string = '';
const s16: string = ''; const s17: string = ''; const s18: string = ''); inline; overload;
procedure DebugLnEnter(const s: string = ''); inline; overload;
procedure DebugLnEnter(Args: array of const); {inline;} overload;
procedure DebugLnEnter(s: string; Args: array of const); {inline;} overload;
procedure DebugLnEnter(const s1, s2: string; const s3: string = '';
const s4: string = ''; const s5: string = ''; const s6: string = '';
const s7: string = ''; const s8: string = ''; const s9: string = '';
const s10: string = ''; const s11: string = ''; const s12: string = '';
const s13: string = ''; const s14: string = ''; const s15: string = '';
const s16: string = ''; const s17: string = ''; const s18: string = ''); inline; overload;
procedure DebugLnExit(const s: string = ''); inline; overload;
procedure DebugLnExit(Args: array of const); {inline;} overload;
procedure DebugLnExit(s: string; Args: array of const); {inline;} overload;
procedure DebugLnExit (const s1, s2: string; const s3: string = '';
const s4: string = ''; const s5: string = ''; const s6: string = '';
const s7: string = ''; const s8: string = ''; const s9: string = '';
const s10: string = ''; const s11: string = ''; const s12: string = '';
const s13: string = ''; const s14: string = ''; const s15: string = '';
const s16: string = ''; const s17: string = ''; const s18: string = ''); inline; overload;
procedure CloseDebugOutput;
{$ELSE}
procedure DebugLn(Args: array of const); overload;
procedure DebugLn(const S: String; Args: array of const); overload;// similar to Format(s,Args)
procedure DebugLn; overload;
procedure DebugLn(const s: string); overload;
procedure DebugLn(const s1,s2: string); overload;
procedure DebugLn(const s1,s2,s3: string); overload;
procedure DebugLn(const s1,s2,s3,s4: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8,s9: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15: string); overload;
procedure DebugLn(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16: string); overload;
procedure DebugLnEnter(const s: string = ''); overload;
procedure DebugLnEnter(Args: array of const); overload;
procedure DebugLnEnter(s: string; Args: array of const); overload;
procedure DebugLnEnter(const s1, s2: string; const s3: string = '';
const s4: string = ''; const s5: string = ''; const s6: string = '';
const s7: string = ''; const s8: string = ''; const s9: string = '';
const s10: string = ''; const s11: string = ''; const s12: string = '';
const s13: string = ''; const s14: string = ''; const s15: string = '';
const s16: string = ''; const s17: string = ''; const s18: string = ''); overload;
procedure DebugLnExit(const s: string = ''); overload;
procedure DebugLnExit(Args: array of const); overload;
procedure DebugLnExit(s: string; Args: array of const); overload;
procedure DebugLnExit (const s1, s2: string; const s3: string = '';
const s4: string = ''; const s5: string = ''; const s6: string = '';
const s7: string = ''; const s8: string = ''; const s9: string = '';
const s10: string = ''; const s11: string = ''; const s12: string = '';
const s13: string = ''; const s14: string = ''; const s15: string = '';
const s16: string = ''; const s17: string = ''; const s18: string = ''); overload;
procedure DbgOut(const S: String; Args: array of const); overload;
procedure DbgOut(const s: string); overload;
procedure DbgOut(const s1,s2: string); overload;
procedure DbgOut(const s1,s2,s3: string); overload;
procedure DbgOut(const s1,s2,s3,s4: string); overload;
procedure DbgOut(const s1,s2,s3,s4,s5: string); overload;
procedure DbgOut(const s1,s2,s3,s4,s5,s6: string); overload;
procedure DbgOut(const s1,s2,s3,s4,s5,s6,s7: string); overload;
procedure DbgOut(const s1,s2,s3,s4,s5,s6,s7,s8: string); overload;
procedure DbgOut(const s1,s2,s3,s4,s5,s6,s7,s8,s9: string); overload;
procedure DbgOut(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10: string); overload;
procedure DbgOut(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11: string); overload;
procedure DbgOut(const s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12: string); overload;
procedure CloseDebugOutput;
{$ENDIF}
function DbgS(const c: cardinal): string; overload; inline;
function DbgS(const i: longint): string; overload; inline;
function DbgS(const i: int64): string; overload; inline;
function DbgS(const q: qword): string; overload; inline;
function DbgS(const r: TRect): string; overload; inline;
function DbgS(const p: TPoint): string; overload; inline;
function DbgS(const p: pointer): string; overload; inline;
function DbgS(const e: extended; MaxDecimals: integer = 999): string; overload; inline;
function DbgS(const b: boolean): string; overload; inline;
function DbgS(const s: TComponentState): string; overload; inline;
function DbgS(const m: TMethod): string; overload; inline;
function DbgSName(const p: TObject): string; overload; inline;
function DbgSName(const p: TClass): string; overload; inline;
function DbgStr(const StringWithSpecialChars: string): string; overload; inline;
function DbgWideStr(const StringWithSpecialChars: widestring): string; overload; inline;
function dbgMemRange(P: PByte; Count: integer; Width: integer = 0): string; overload; inline;
function dbgMemStream(MemStream: TCustomMemoryStream; Count: integer): string; overload; inline;
function dbgObjMem(AnObject: TObject): string; overload; inline;
function dbgHex(i: Int64): string; overload; inline;
function DbgSWindowPosFlags(Flags: UInt): String;
function DbgS(const i1,i2,i3,i4: integer): string; overload; inline;
function DbgS(const Shift: TShiftState): string; overload; inline;
function DbgsVKCode(c: word): string;
function DbgS(const ASize: TSize): string; overload; inline;
function DbgS(const ATM: TTextMetric): string; overload;
function DbgS(const AScrollInfo: TScrollInfo): string; overload;
function DbgS(const AVariant: Variant): string; overload;
procedure DbgOutThreadLog(const Msg: string); overload;
procedure DebuglnThreadLog(const Msg: string); overload;
procedure DebuglnThreadLog(Args: array of const); overload;
procedure DebuglnThreadLog; overload;
procedure DbgSaveData(FileName: String; AData: PChar; ADataSize: PtrUInt);
procedure DbgAppendToFile(FileName, S: String);
procedure DbgAppendToFileWithoutLn(FileName, S: String);
// some string manipulation functions
function StripLN(const ALine: String): String;
function GetPart(const ASkipTo, AnEnd: String; var ASource: String;
const AnIgnoreCase: Boolean = False; const AnUpdateSource: Boolean = True): String; overload;
function GetPart(const ASkipTo, AnEnd: array of String; var ASource: String;
const AnIgnoreCase: Boolean = False; const AnUpdateSource: Boolean = True): String; overload;
function TextToSingleLine(const AText: string): string;
function SwapCase(Const S: String): String;
// case..of utility functions
function StringCase(const AString: String; const ACase: array of String {; const AIgnoreCase = False, APartial = false: Boolean}): Integer; overload;
function StringCase(const AString: String; const ACase: array of String; const AIgnoreCase, APartial: Boolean): Integer; overload;
function ClassCase(const AClass: TClass; const ACase: array of TClass {; const ADescendant: Boolean = True}): Integer; overload;
function ClassCase(const AClass: TClass; const ACase: array of TClass; const ADecendant: Boolean): Integer; overload;
// MWE: define (missing) UTF16string similar to UTF8
// strictly spoken, a widestring <> utf16string
// todo: use it in existing functions
type
UTF16String = type UnicodeString;
PUTF16String = ^UTF16String;
// Felipe: Don't substitute with calls to lazutf16 because lazutf16 includes
// some initialization code and tables, which are not necessary for the LCL
function UTF16CharacterLength(p: PWideChar): integer;
function UTF16Length(const s: UTF16String): PtrInt;
function UTF16Length(p: PWideChar; WordCount: PtrInt): PtrInt;
function UTF16CharacterToUnicode(p: PWideChar; out CharLen: integer): Cardinal;
function UnicodeToUTF16(u: cardinal): UTF16String;
// identifier
function CreateFirstIdentifier(const Identifier: string): string;
function CreateNextIdentifier(const Identifier: string): string;
// Font
function IsFontNameDefault(const AName: string): boolean; inline;
{$IFDEF WithOldDebugln}
type
TDebugLnProc = procedure (s: string) of object;
var
DebugLnMaxNestPrefixLen: Integer = 15;
DebugLnNestLvlIndent: Integer = 2;
DebugText: ^Text;
DebugLnProc: TDebugLnProc = nil;
DebugOutProc: TDebugLnProc = nil;
{$ENDIF}
implementation
uses gettext;
const
{$IFDEF WithOldDebugln}
Str_LCL_Debug_File = 'lcldebug.log';
{$ENDIF}
UNKNOWN_VK_PREFIX = 'Word(''';
UNKNOWN_VK_POSTFIX = ''')';
var
InterfaceInitializationHandlers: TFPList = nil;
InterfaceFinalizationHandlers: TFPList = nil;
{$IFDEF WithOldDebugln}
DebugTextAllocated: boolean;
DebugNestLvl: Integer = 0;
DebugNestPrefix: PChar = nil;
DebugNestAtBOL: Boolean;
{$ENDIF}
function DeleteAmpersands(var Str : String) : Longint;
// Replace all &x with x
// and return the position of the first ampersand letter in the resulting Str.
// double ampersands && are converted to a single & and are ignored.
var
SrcPos, DestPos, SrcLen: Integer;
begin
Result:=-1;
SrcLen:=length(Str);
SrcPos:=1;
DestPos:=1;
while SrcPos<=SrcLen do begin
if (Str[SrcPos]='&') and (SrcPos<SrcLen) then begin
// & found
inc(SrcPos); // skip &
if (Str[SrcPos]<>'&') and (Result<1) then
Result:=DestPos;
end;
if DestPos<SrcPos then
Str[DestPos]:=Str[SrcPos];
inc(SrcPos);
inc(DestPos);
end;
if DestPos<SrcPos then
SetLength(Str,DestPos-1);
end;
//-----------------------------------------------------------------------------
// Keys and shortcuts
const
// MS documentation:
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
//
// Note: ShortcutToText must ignore single key Ctrl, Alt, Shift, Win,
// so these items have empty str here
//
KeyCodeStrings: array[0..$FF] of string = (
'Unknown',
'Mouse_Left', // 0x1 - VK_LBUTTON
'Mouse_Right', // 0x2 - VK_RBUTTON
'Cancel', // 0x3 - VK_CANCEL - generated by Ctrl+Break
'Mouse_Middle', // 0x4 - VK_MBUTTON
'Mouse_X1', // 0x5 - VK_XBUTTON1
'Mouse_X2', // 0x6 - VK_XBUTTON2
'', // 0x7
'Backspace', // 0x8 - VK_BACK
'Tab', // 0x9 - VK_TAB
'', // 0xa
'', // 0xb
'NumClear', // 0xc - VK_CLEAR - generated by Num5 (NumLock off)
'Enter', // 0xd - VK_RETURN
'', // 0xe
'', // 0xf
'', //'Shift', // 0x10 - VK_SHIFT
'', //'Ctrl', // 0x11 - VK_CONTROL
'', //'Alt', // 0x12 - VK_MENU
'Break', // 0x13 - VK_PAUSE - Pause/Break key
'CapsLock', // 0x14 - VK_CAPITAL
'IME_Kana', // 0x15 - VK_KANA
'', // 0x16
'IME_Junja', // 0x17 - VK_JUNJA
'IME_final', // 0x18 - VK_FINAL
'IME_Hanja', // 0x19 - VK_HANJA
'', // 0x1a
'Esc', // 0x1b - VK_ESCAPE
'IME_convert', // 0x1c - VK_CONVERT
'IME_nonconvert', // 0x1d - VK_NONCONVERT
'IME_accept', // 0x1e - VK_ACCEPT
'IME_mode_change', // 0x1f - VK_MODECHANGE
'Space', // 0x20 - VK_SPACE
'PgUp', // 0x21 - VK_PRIOR
'PgDown', // 0x22 - VK_NEXT
'End', // 0x23 - VK_END
'Home', // 0x24 - VK_HOME
'Left', // 0x25 - VK_LEFT
'Up', // 0x26 - VK_UP
'Right', // 0x27 - VK_RIGHT
'Down', // 0x28 - VK_DOWN
'Select', // 0x29 - VK_SELECT
'Print', // 0x2a - VK_PRINT
'Execute', // 0x2b - VK_EXECUTE
'PrintScreen', // 0x2c - VK_SNAPSHOT
'Ins', // 0x2d - VK_INSERT
'Del', // 0x2e - VK_DELETE
'Help', // 0x2f - VK_HELP
'0', // 0x30
'1', // 0x31
'2', // 0x32
'3', // 0x33
'4', // 0x34
'5', // 0x35
'6', // 0x36
'7', // 0x37
'8', // 0x38
'9', // 0x39
'', // 0x3a
'', // 0x3b
'', // 0x3c
'', // 0x3d
'', // 0x3e
'', // 0x3f
'', // 0x40
'A', // 0x41
'B', // 0x42
'C', // 0x43
'D', // 0x44
'E', // 0x45
'F', // 0x46
'G', // 0x47
'H', // 0x48
'I', // 0x49
'J', // 0x4a
'K', // 0x4b
'L', // 0x4c
'M', // 0x4d
'N', // 0x4e
'O', // 0x4f
'P', // 0x50
'Q', // 0x51
'R', // 0x52
'S', // 0x53
'T', // 0x54
'U', // 0x55
'V', // 0x56
'W', // 0x57
'X', // 0x58
'Y', // 0x59
'Z', // 0x5a
'', //'LWindows', // 0x5b - VK_LWIN
'', //'RWindows', // 0x5c - VK_RWIN
'PopUp', // 0x5d - VK_APPS - PC, key near right Ctrl
'', // 0x5e
'Sleep', // 0x5f - VK_SLEEP
'Num0', // 0x60 - VK_NUMPAD0
'Num1', // 0x61
'Num2', // 0x62
'Num3', // 0x63
'Num4', // 0x64
'Num5', // 0x65
'Num6', // 0x66
'Num7', // 0x67
'Num8', // 0x68
'Num9', // 0x69 - VK_NUMPAD9
'NumMul', // 0x6a - VK_MULTIPLY
'NumPlus', // 0x6b - VK_ADD
'NumSepar', // 0x6c - VK_SEPARATOR
'NumMinus', // 0x6d - VK_SUBTRACT
'NumDot', // 0x6e - VK_DECIMAL
'NumDiv', // 0x6f - VK_DIVIDE
'F1', // 0x70 - VK_F1
'F2', // 0x71
'F3', // 0x72
'F4', // 0x73
'F5', // 0x74
'F6', // 0x75
'F7', // 0x76
'F8', // 0x77
'F9', // 0x78
'F10', // 0x79
'F11', // 0x7a
'F12', // 0x7b
'F13', // 0x7c
'F14', // 0x7d
'F15', // 0x7e
'F16', // 0x7f
'F17', // 0x80
'F18', // 0x81
'F19', // 0x82
'F20', // 0x83
'F21', // 0x84
'F22', // 0x85
'F23', // 0x86
'F24', // 0x87 - VK_F24
'', // 0x88
'', // 0x89
'', // 0x8a
'', // 0x8b
'', // 0x8c
'', // 0x8d
'', // 0x8e
'', // 0x8f
'NumLock', // 0x90 - VK_NUMLOCK
'ScrollLock', // 0x91 - VK_SCROLL
'OEM_0x92', // 0x92
'OEM_0x93', // 0x93
'OEM_0x94', // 0x94
'OEM_0x95', // 0x95
'OEM_0x96', // 0x96
'', // 0x97
'', // 0x98
'', // 0x99
'', // 0x9a
'', // 0x9b
'', // 0x9c
'', // 0x9d
'', // 0x9e
'', // 0x9f
'', //'LShift', // 0xa0 - VK_LSHIFT
'', //'RShift', // 0xa1 - VK_RSHIFT
'', //'LCtrl', // 0xa2 - VK_LCONTROL
'', //'RCtrl', // 0xa3 - VK_RCONTROL
'', //'LAlt', // 0xa4 - VK_LMENU
'', //'RAlt', // 0xa5 - VK_RMENU
'BrowserBack', // 0xa6 - VK_BROWSER_BACK
'BrowserForward', // 0xa7 - VK_BROWSER_FORWARD
'BrowserRefresh', // 0xa8 - VK_BROWSER_REFRESH
'BrowserStop', // 0xa9 - VK_BROWSER_STOP
'BrowserSearch', // 0xaa - VK_BROWSER_SEARCH
'BrowserFav', // 0xab - VK_BROWSER_FAVORITES
'BrowserHome', // 0xac - VK_BROWSER_HOME
'VolumeMute', // 0xad - VK_VOLUME_MUTE
'VolumeDown', // 0xae - VK_VOLUME_DOWN
'VolumeUp', // 0xaf - VK_VOLUME_UP
'MediaNext', // 0xb0 - VK_MEDIA_NEXT_TRACK
'MediaPrev', // 0xb1 - VK_MEDIA_PREV_TRACK
'MediaStop', // 0xb2 - VK_MEDIA_STOP
'MediaPlayPause', // 0xb3 - VK_MEDIA_PLAY_PAUSE
'LaunchMail', // 0xb4 - VK_LAUNCH_MAIL
'LaunchMedia', // 0xb5 - VK_LAUNCH_MEDIA_SELECT
'LaunchApp1', // 0xb6 - VK_LAUNCH_APP1
'LaunchApp2', // 0xb7 - VK_LAUNCH_APP2
'', // 0xb8
'', // 0xb9
';', // 0xba - VK_OEM_1 - Can vary by keyboard, US keyboard, the ';:' key
'+', // 0xbb - VK_OEM_PLUS - For any country/region, the '+' key
',', // 0xbc - VK_OEM_COMMA - For any country/region, the ',' key
'-', // 0xbd - VK_OEM_MINUS - For any country/region, the '-' key
'.', // 0xbe - VK_OEM_PERIOD - For any country/region, the '.' key
'/', // 0xbf - VK_OEM_2 - Can vary by keyboard, US keyboard, the '/?' key
'`', // 0xc0 - VK_OEM_3 - Can vary by keyboard, US keyboard, the '`~' key
'', // 0xc1
'', // 0xc2
'', // 0xc3
'', // 0xc4
'', // 0xc5
'', // 0xc6
'', // 0xc7
'', // 0xc8
'', // 0xc9
'', // 0xca
'', // 0xcb
'', // 0xcc
'', // 0xcd
'', // 0xce
'', // 0xcf
'', // 0xd0
'', // 0xd1
'', // 0xd2
'', // 0xd3
'', // 0xd4
'', // 0xd5
'', // 0xd6
'', // 0xd7
'', // 0xd8
'', // 0xd9
'', // 0xda
'[', // 0xdb - VK_OEM_4 - Can vary by keyboard, US keyboard, the '[{' key
'\', // 0xdc - VK_OEM_5 - Can vary by keyboard, US keyboard, the '\|' key
']', // 0xdd - VK_OEM_6 - Can vary by keyboard, US keyboard, the ']}' key
'''', // 0xde - VK_OEM_7 - Can vary by keyboard, US keyboard, the 'single-quote/double-quote' key
'OEM_8', // 0xdf - VK_OEM_8
'', // 0xe0
'OEM_0xE1', // 0xe1
'\', // 0xe2 - VK_OEM_102 - Either the angle bracket key or the backslash key on the RT 102-key keyboard
'OEM_0xE3', // 0xe3
'OEM_0xE4', // 0xe4
'IME_process', // 0xe5 - VK_PROCESSKEY
'OEM_0xE6', // 0xe6
'UnicodePacket', // 0xe7 - VK_PACKET
'', // 0xe8
'OEM_0xE9', // 0xe9
'OEM_0xEA', // 0xea
'OEM_0xEB', // 0xeb
'OEM_0xEC', // 0xec
'OEM_0xED', // 0xed
'OEM_0xEE', // 0xee
'OEM_0xEF', // 0xef
'OEM_0xF0', // 0xf0
'OEM_0xF1', // 0xf1
'OEM_0xF2', // 0xf2
'OEM_0xF3', // 0xf3
'OEM_0xF4', // 0xf4
'OEM_0xF5', // 0xf5
'Attn', // 0xf6 - VK_ATTN
'CrSel', // 0xf7 - VK_CRSEL
'ExSel', // 0xf8 - VK_EXSEL
'EraseEOF', // 0xf9 - VK_EREOF
'Play', // 0xfa - VK_PLAY
'Zoom', // 0xfb - VK_ZOOM
'', // 0xfc
'PA1', // 0xfd - VK_PA1
'OEM_Clear', // 0xfe - VK_OEM_CLEAR
'' // 0xff
);
function CompareDebugLCLItemInfos(Data1, Data2: Pointer): integer;
begin
Result:=ComparePointers(TDebugLCLItemInfo(Data1).Item,
TDebugLCLItemInfo(Data2).Item);
end;
function CompareItemWithDebugLCLItemInfo(Item, DebugItemInfo: Pointer): integer;
begin
Result:=ComparePointers(Item,TDebugLCLItemInfo(DebugItemInfo).Item);
end;
function GetEnumValueDef(TypeInfo: PTypeInfo; const Name: string;
const DefaultValue: Integer): Integer;
begin
Result:=GetEnumValue(TypeInfo,Name);
if Result<0 then
Result:=DefaultValue;
end;
function KeyCodeToKeyString(Key: TShortCut; Localized: boolean): string;
begin
if Key <= High(KeyCodeStrings) then
begin
if Localized then
case Key of
VK_UNKNOWN: Result:=ifsVK_UNKNOWN;
VK_BACK: Result:=SmkcBkSp;
VK_TAB: Result:=SmkcTab;
VK_ESCAPE: Result:=SmkcEsc;
VK_RETURN: Result:=SmkcEnter;
VK_SPACE: Result:=SmkcSpace;
VK_PRIOR: Result:=SmkcPgUp;
VK_NEXT: Result:=SmkcPgDn;
VK_END: Result:=SmkcEnd;
VK_HOME: Result:=SmkcHome;
VK_LEFT: Result:=SmkcLeft;
VK_UP: Result:=SmkcUp;
VK_RIGHT: Result:=SmkcRight;
VK_DOWN: Result:=SmkcDown;
VK_INSERT: Result:=SmkcIns;
VK_DELETE: Result:=SmkcDel;
VK_HELP: Result:=ifsVK_HELP;
// must ignore single Shift, Alt, Ctrl in KeyCodeStrings
//VK_SHIFT: Result:=SmkcShift;
//VK_CONTROL: Result:=SmkcCtrl;
//VK_MENU: Result:=SmkcAlt;
otherwise
Result := KeyCodeStrings[Key];
end
else
Result := KeyCodeStrings[Key];
end
else
case Key of
scMeta: if Localized then Result:=SmkcMeta else Result:='Meta+';
scShift: if Localized then Result:=SmkcShift else Result:='Shift+';
scCtrl: if Localized then Result:=SmkcCtrl else Result:='Ctrl+';
scAlt: if Localized then Result:=SmkcAlt else Result:='Alt+';
otherwise
Result:='';
end;
end;
// Used also by TWidgetSet.GetAcceleratorString
function KeyAndShiftStateToKeyString(Key: word; ShiftState: TShiftState): String;
procedure AddPart(const APart: string);
begin
if Result <> '' then
Result := Result + '+';
Result := Result + APart;
end;
var
s: string;
begin
Result := '';
if ssCtrl in ShiftState then AddPart(ifsCtrl);
if ssAlt in ShiftState then AddPart(ifsAlt);
if ssShift in ShiftState then AddPart(ifsVK_SHIFT);
if ssMeta in ShiftState then
{$IFDEF LCLcarbon}
AddPart(ifsVK_CMD);
{$ELSE}
AddPart(ifsVK_META);
{$ENDIF}
if ssSuper in ShiftState then AddPart(ifsVK_SUPER);
s := KeyCodeToKeyString(Key, true);
// function returned "Word(nnn)" previously, keep this
if s = '' then
s := UNKNOWN_VK_PREFIX + IntToStr(Key) + UNKNOWN_VK_POSTFIX;
AddPart(s);
end;
function KeyStringIsIrregular(const s: string): boolean;
begin
Result:=(length(UNKNOWN_VK_PREFIX)<length(s)) and
(AnsiStrLComp(PChar(s),PChar(UNKNOWN_VK_PREFIX),length(UNKNOWN_VK_PREFIX))=0);
end;
function ShortCutToTextGeneric(ShortCut: TShortCut; Localized: boolean): string;
var
Name: string;
begin
Result := '';
Name := KeyCodeToKeyString(ShortCut and $FF, Localized);
if Name <> '' then
begin
if ShortCut and scShift <> 0 then Result := Result + KeyCodeToKeyString(scShift, Localized);
if ShortCut and scCtrl <> 0 then Result := Result + KeyCodeToKeyString(scCtrl, Localized);
if ShortCut and scMeta <> 0 then Result := Result + KeyCodeToKeyString(scMeta, Localized);
if ShortCut and scAlt <> 0 then Result := Result + KeyCodeToKeyString(scAlt, Localized);
Result := Result + Name;
end;
end;
function ShortCutToText(ShortCut: TShortCut): string;
begin
Result:=ShortCutToTextGeneric(ShortCut, true);
end;
function ShortCutToTextRaw(ShortCut: TShortCut): string;
begin
Result:=ShortCutToTextGeneric(ShortCut, false);
end;
function TextToShortCutGeneric(const ShortCutText: string; Localized: boolean): TShortCut;
function CompareFront(var StartPos: integer; const Front: string): Boolean;
begin
if (Front<>'') and (StartPos+length(Front)-1<=length(ShortCutText))
and (AnsiStrLIComp(@ShortCutText[StartPos], PChar(Front), Length(Front))= 0)
then begin
Result:=true;
inc(StartPos,length(Front));
end else
Result:=false;
end;
var
Key: TShortCut;
Shift: TShortCut;
StartPos: integer;
Name: string;
begin
Result := 0;
if ShortCutText = '' then Exit;
Shift := 0;
StartPos := 1;
while True do
begin
if CompareFront(StartPos, KeyCodeToKeyString(scShift, Localized)) then
Shift := Shift or scShift
else if CompareFront(StartPos, '^') then
Shift := Shift or scCtrl
else if CompareFront(StartPos, KeyCodeToKeyString(scCtrl, Localized)) then
Shift := Shift or scCtrl
else if CompareFront(StartPos, KeyCodeToKeyString(scAlt, Localized)) then
Shift := Shift or scAlt
else if CompareFront(StartPos, KeyCodeToKeyString(scMeta, Localized)) then
Shift := Shift or scMeta
else
Break;
end;
for Key := Low(KeyCodeStrings) to High(KeyCodeStrings) do
begin
Name := KeyCodeToKeyString(Key, Localized);
if (Name<>'') and (length(Name)=length(ShortCutText)-StartPos+1)
and (AnsiStrLIComp(@ShortCutText[StartPos], PChar(Name), length(Name)) = 0)
then begin
Result := Key or Shift;
Exit;
end;
end;
end;
function TextToShortCut(const ShortCutText: string): TShortCut;
begin
Result:=TextToShortCutGeneric(ShortCutText, true);
end;
function TextToShortCutRaw(const ShortCutText: string): TShortCut;
begin
Result:=TextToShortCutGeneric(ShortCutText, false);
end;
function GetCompleteText(const sText: string; iSelStart: Integer;
bCaseSensitive, bSearchAscending: Boolean; slTextList: TStrings): string;
function IsSamePrefix(const sCompareText, sPrefix: string; iStart: Integer;
var ResultText: string): Boolean;
var
sTempText: string;
begin
Result := False;
sTempText := UTF8Copy(sCompareText, 1, iStart);
if not bCaseSensitive then
sTempText := UTF8UpperCase(sTempText);
if (sTempText = sPrefix) then
begin
ResultText := sCompareText;
Result := True;
end;
end;
var
i: Integer;
sPrefixText: string;
begin
//DebugLn(['GetCompleteText sText=',sText,' iSelStart=',iSelStart,' bCaseSensitive=',bCaseSensitive,' bSearchAscending=',bSearchAscending,' slTextList.Count=',slTextList.Count]);
Result := sText;//Default to return original text if no identical text are found
if (sText = '') then Exit;//Everything is compatible with nothing, Exit.
if (iSelStart = 0) then Exit;//Cursor at beginning
if (slTextList.Count = 0) then Exit;//No text list to search for idtenticals, Exit.
sPrefixText := UTF8Copy(sText, 1, iSelStart);//Get text from beginning to cursor position.
if not bCaseSensitive then
sPrefixText := UTF8UpperCase(sPrefixText);
if bSearchAscending then
begin
for i := 0 to slTextList.Count - 1 do
if IsSamePrefix(slTextList[i], sPrefixText, iSelStart, Result) then
break;
end else
begin
for i := slTextList.Count - 1 downto 0 do
if IsSamePrefix(slTextList[i], sPrefixText, iSelStart, Result) then
break;
end;
end;
function IsEditableTextKey(Key: Word): Boolean;
begin
Result := (((Key >= VK_A) and (Key <= VK_Z)) or
((Key >= VK_NUMPAD0) and (Key <= VK_DIVIDE)) or
((Key >= VK_0) and (Key <= VK_9)) or
((Key >= 186) and (Key <= 188)) or
((Key >= 190) and (Key <= 192)) or
((Key >= 219) and (Key <= 222)));
end;
function SendApplicationMessage(Msg: Cardinal; WParam: WParam; LParam: LParam
): Longint;
begin
if SendApplicationMessageFunction<>nil then
Result:=SendApplicationMessageFunction(Msg, WParam, LParam)
else
Result:=0;
end;
procedure OwnerFormDesignerModified(AComponent: TComponent);
begin
if ([csDesigning,csLoading,csDestroying]*AComponent.ComponentState
=[csDesigning])
then begin
if OwnerFormDesignerModifiedProc<>nil then
OwnerFormDesignerModifiedProc(AComponent);
end;
end;
function OffSetRect(var ARect: TRect; dx,dy: Integer): Boolean;
Begin
with ARect do
begin
Left := Left + dx;
Right := Right + dx;
Top := Top + dy;
Bottom := Bottom + dy;
end;
Result := (ARect.Left >= 0) and (ARect.Top >= 0);
end;
procedure FreeThenNil(var obj);
begin
LazUtilities.FreeThenNil(obj);
end;
procedure RegisterInterfaceInitializationHandler(p: TProcedure);
begin
InterfaceInitializationHandlers.Add(p);
end;
procedure CallInterfaceInitializationHandlers;
var
i: Integer;
begin
for i:=0 to InterfaceInitializationHandlers.Count-1 do
TProcedure(InterfaceInitializationHandlers[i])();
end;
procedure RegisterInterfaceFinalizationHandler(p: TProcedure);
begin
InterfaceFinalizationHandlers.Add(p);
end;
procedure CallInterfaceFinalizationHandlers;
var
i: Integer;
begin
for i:=InterfaceFinalizationHandlers.Count-1 downto 0 do
TProcedure(InterfaceFinalizationHandlers[i])();
end;
procedure MoveRect(var ARect: TRect; x, y: Integer);
begin
inc(ARect.Right,x-ARect.Left);
inc(ARect.Bottom,y-ARect.Top);
ARect.Left:=x;
ARect.Top:=y;
end;
procedure MoveRectToFit(var ARect: TRect; const MaxRect: TRect);
// move ARect, so it fits into MaxRect
// if MaxRect is too small, ARect is resized.
begin
if ARect.Left<MaxRect.Left then begin
// move rectangle right
ARect.Right:=Min(ARect.Right+MaxRect.Left-ARect.Left,MaxRect.Right);
ARect.Left:=MaxRect.Left;
end;
if ARect.Top<MaxRect.Top then begin
// move rectangle down
ARect.Bottom:=Min(ARect.Bottom+MaxRect.Top-ARect.Top,MaxRect.Bottom);
ARect.Top:=MaxRect.Top;
end;
if ARect.Right>MaxRect.Right then begin
// move rectangle left
ARect.Left:=Max(ARect.Left-ARect.Right+MaxRect.Right,MaxRect.Left);
ARect.Right:=MaxRect.Right;
end;
if ARect.Bottom>MaxRect.Bottom then begin
// move rectangle left
ARect.Top:=Max(ARect.Top-ARect.Bottom+MaxRect.Bottom,MaxRect.Top);
ARect.Bottom:=MaxRect.Bottom;
end;
end;
procedure MakeMinMax(var i1, i2: integer);
var
h: Integer;
begin
if i1>i2 then begin
h:=i1;
i1:=i2;
i2:=h;
end;
end;
procedure CalculateLeftTopWidthHeight(X1, Y1, X2, Y2: integer;
out Left, Top, Width, Height: integer);
begin
if X1 <= X2 then
begin
Left := X1;
Width := X2 - X1;
end
else
begin
Left := X2;
Width := X1 - X2;
end;
if Y1 <= Y2 then
begin
Top := Y1;
Height := Y2 - Y1;
end
else
begin
Top := Y2;
Height := Y1 - Y2;
end;
end;
function ComparePointers(p1, p2: Pointer): integer;
begin
Result:=LazUtilities.ComparePointers(p1, p2);
end;
function CompareHandles(h1, h2: THandle): integer;
begin
if h1>h2 then
Result:=1
else if h1<h2 then
Result:=-1
else
Result:=0;
end;
function CompareRect(R1, R2: PRect): Boolean;
begin
Result:=(R1^.Left=R2^.Left) and (R1^.Top=R2^.Top) and
(R1^.Bottom=R2^.Bottom) and (R1^.Right=R2^.Right);
{if not Result then begin
DebugLn(' DIFFER: ',R1^.Left,',',R1^.Top,',',R1^.Right,',',R1^.Bottom
,' <> ',R2^.Left,',',R2^.Top,',',R2^.Right,',',R2^.Bottom);
end;}
end;
function ComparePoints(const p1, p2: TPoint): integer;
begin
if p1.Y>p2.Y then
Result:=1
else if p1.Y<p2.Y then
Result:=-1
else if p1.X>p2.X then
Result:=1
else if p1.X<p2.X then
Result:=-1
else
Result:=0;
end;
function CompareCaret(const FirstCaret, SecondCaret: TPoint): integer;
begin
if (FirstCaret.Y<SecondCaret.Y) then
Result:=1
else if (FirstCaret.Y>SecondCaret.Y) then
Result:=-1
else if (FirstCaret.X<SecondCaret.X) then
Result:=1
else if (FirstCaret.X>SecondCaret.X) then
Result:=-1
else
Result:=0;
end;
function CompareMethods(const m1, m2: TMethod): boolean;
begin
Result:=LazMethodList.CompareMethods(m1, m2);
end;
function RoundToInt(const e: Extended): integer;
begin
Result:=integer(Round(e));
{$IFDEF VerboseRound}
DebugLn('RoundToInt ',e,' ',Result);
{$ENDIF}
end;
function RoundToCardinal(const e: Extended): cardinal;
begin
Result:=cardinal(Round(e));
{$IFDEF VerboseRound}
DebugLn('RoundToCardinal ',e,' ',Result);
{$ENDIF}
end;
function TruncToInt(const e: Extended): integer;
begin
Result:=integer(Trunc(e));
{$IFDEF VerboseRound}
DebugLn('TruncToInt ',e,' ',Result);
{$ENDIF}
end;
function TruncToCardinal(const e: Extended): cardinal;
begin
Result:=cardinal(Trunc(e));
{$IFDEF VerboseRound}
DebugLn('TruncToCardinal ',e,' ',Result);
{$ENDIF}
end;
function StrToDouble(const s: string): double;
begin
{$IFDEF VerboseRound}
DebugLn('StrToDouble "',s,'"');
{$ENDIF}
Result:=Double(StrToFloat(s));
end;
procedure MergeSort(List: TFPList; const OnCompare: TListSortCompare);
begin
if List=nil then exit;
MergeSort(List,0,List.Count-1,OnCompare);
end;
procedure MergeSort(List: TFPList; StartIndex, EndIndex: integer;
const OnCompare: TListSortCompare);
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
var
MergeList: PPointer;
procedure SmallSort(StartPos, EndPos: PtrInt);
// use insertion sort for small lists
var
i: PtrInt;
Best: PtrInt;
j: PtrInt;
Item: Pointer;
begin
for i:=StartPos to EndPos-1 do begin
Best:=i;
for j:=i+1 to EndPos do
if OnCompare(List[Best],List[j])>0 then
Best:=j;
if Best>i then begin
Item:=List[i];
List[i]:=List[Best];
List[Best]:=Item;
end;
end;
end;
procedure Merge(Pos1, Pos2, Pos3: PtrInt);
// merge two sorted arrays
// the first array ranges Pos1..Pos2-1, the second ranges Pos2..Pos3
var Src1Pos,Src2Pos,DestPos,cmp,a:PtrInt;
begin
while (Pos3>=Pos2) and (OnCompare(List[Pos2-1],List[Pos3])<=0) do
dec(Pos3);
if (Pos1>=Pos2) or (Pos2>Pos3) then exit;
Src1Pos:=Pos2-1;
Src2Pos:=Pos3;
DestPos:=Pos3;
while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin
cmp:=OnCompare(List[Src1Pos],List[Src2Pos]);
if cmp>0 then begin
MergeList[DestPos]:=List[Src1Pos];
dec(Src1Pos);
end else begin
MergeList[DestPos]:=List[Src2Pos];
dec(Src2Pos);
end;
dec(DestPos);
end;
while Src2Pos>=Pos2 do begin
MergeList[DestPos]:=List[Src2Pos];
dec(Src2Pos);
dec(DestPos);
end;
for a:=DestPos+1 to Pos3 do
List[a]:=MergeList[a];
end;
procedure Sort(StartPos, EndPos: PtrInt);
// sort an interval in List. Use MergeList as work space.
var
mid: integer;
begin
if EndPos-StartPos<6 then begin
SmallSort(StartPos,EndPos);
end else begin
mid:=(StartPos+EndPos) shr 1;
Sort(StartPos,mid);
Sort(mid+1,EndPos);
Merge(StartPos,mid+1,EndPos);
end;
end;
var
Cnt: Integer;
begin
if (List=nil) then exit;
Cnt:=List.Count;
if StartIndex<0 then StartIndex:=0;
if EndIndex>=Cnt then EndIndex:=Cnt-1;
if StartIndex>=EndIndex then exit;
MergeList:=GetMem(List.Count*SizeOf(Pointer));
Sort(StartIndex,EndIndex);
Freemem(MergeList);
end;
procedure MergeSort(List: TStrings; const OnCompare: TStringsSortCompare);
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
var
MergeList: PAnsiString;
procedure SmallSort(StartPos, EndPos: PtrInt);
// use insertion sort for small lists
var
i: PtrInt;
Best: PtrInt;
j: PtrInt;
Item: string;
begin
for i:=StartPos to EndPos-1 do begin
Best:=i;
for j:=i+1 to EndPos do
if OnCompare(List[Best],List[j])>0 then
Best:=j;
if Best>i then begin
Item:=List[i];
List[i]:=List[Best];
List[Best]:=Item;
end;
end;
end;
procedure Merge(Pos1, Pos2, Pos3: PtrInt);
// merge two sorted arrays
// the first array ranges Pos1..Pos2-1, the second ranges Pos2..Pos3
var Src1Pos,Src2Pos,DestPos,cmp,a:integer;
begin
while (Pos3>=Pos2) and (OnCompare(List[Pos2-1],List[Pos3])<=0) do
dec(Pos3);
if (Pos1>=Pos2) or (Pos2>Pos3) then exit;
Src1Pos:=Pos2-1;
Src2Pos:=Pos3;
DestPos:=Pos3;
while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin
cmp:=OnCompare(List[Src1Pos],List[Src2Pos]);
if cmp>0 then begin
MergeList[DestPos]:=List[Src1Pos];
dec(Src1Pos);
end else begin
MergeList[DestPos]:=List[Src2Pos];
dec(Src2Pos);
end;
dec(DestPos);
end;
while Src2Pos>=Pos2 do begin
MergeList[DestPos]:=List[Src2Pos];
dec(Src2Pos);
dec(DestPos);
end;
for a:=DestPos+1 to Pos3 do
List[a]:=MergeList[a];
end;
procedure Sort(StartPos, EndPos: PtrInt);
// sort an interval in List. Use MergeList as work space.
var
mid: integer;
begin
if EndPos-StartPos<6 then begin
SmallSort(StartPos,EndPos);
end else begin
mid:=(StartPos+EndPos) shr 1;
Sort(StartPos,mid);
Sort(mid+1,EndPos);
Merge(StartPos,mid+1,EndPos);
end;
end;
var
CurSize: PtrInt;
i: PtrInt;
begin
if (List=nil) or (List.Count<=1) then exit;
CurSize:=PtrInt(List.Count)*SizeOf(Pointer);
MergeList:=GetMem(CurSize);
FillChar(MergeList^,CurSize,0);
Sort(0,List.Count-1);
for i:=0 to List.Count-1 do MergeList[i]:='';
Freemem(MergeList);
end;
// Debug funcs :
procedure RaiseGDBException(const Msg: string);
begin
LazTracer.RaiseGDBException(Msg);
end;
{$IFnDEF WithOldDebugln}
procedure CloseDebugOutput;
begin
DebugLogger.Finish;
end;
procedure DbgOut(const s: string);
begin
DebugLogger.DbgOut(s);
end;
procedure DbgOut(Args: array of const);
begin
DebugLogger.DbgOut(Args);
end;
procedure DbgOut(const S: String; Args: array of const);
begin
DebugLogger.DbgOut(S, Args);
end;
procedure DbgOut(const s1, s2: string; const s3: string; const s4: string; const s5: string;
const s6: string; const s7: string; const s8: string; const s9: string; const s10: string;
const s11: string; const s12: string; const s13: string; const s14: string;
const s15: string; const s16: string; const s17: string; const s18: string);
begin
DebugLogger.DbgOut(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18);
end;
procedure DebugLn(const s: string);
begin
DebugLogger.DebugLn(s);
end;
procedure DebugLn(Args: array of const);
begin
DebugLogger.DebugLn(Args);
end;
procedure DebugLn(const S: String; Args: array of const);
begin
DebugLogger.DebugLn(S, Args);
end;
procedure DebugLn(const s1, s2: string; const s3: string; const s4: string; const s5: string;
const s6: string; const s7: string; const s8: string; const s9: string; const s10: string;
const s11: string; const s12: string; const s13: string; const s14: string;
const s15: string; const s16: string; const s17: string; const s18: string);
begin
DebugLogger.DebugLn(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18);
end;
procedure DebugLnEnter(const s: string);
begin
DebugLogger.DebugLnEnter(s);
end;
procedure DebugLnEnter(Args: array of const);
begin
DebugLogger.DebugLnEnter(Args);
end;
procedure DebugLnEnter(s: string; Args: array of const);
begin
DebugLogger.DebugLnEnter(s, Args);
end;
procedure DebugLnEnter(const s1, s2: string; const s3: string; const s4: string;
const s5: string; const s6: string; const s7: string; const s8: string; const s9: string;
const s10: string; const s11: string; const s12: string; const s13: string;
const s14: string; const s15: string; const s16: string; const s17: string;
const s18: string);
begin
DebugLogger.DebugLnEnter(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18);
end;
procedure DebugLnExit(const s: string);
begin
DebugLogger.DebugLnExit(s);
end;
procedure DebugLnExit(Args: array of const);
begin
DebugLogger.DebugLnExit(Args);
end;
procedure DebugLnExit(s: string; Args: array of const);
begin
DebugLogger.DebugLnExit(s, Args);
end;
procedure DebugLnExit(const s1, s2: string; const s3: string; const s4: string;
const s5: string; const s6: string; const s7: string; const s8: string; const s9: string;
const s10: string; const s11: string; const s12: string; const s13: string;
const s14: string; const s15: string; const s16: string; const s17: string;
const s18: string);
begin
DebugLogger.DebugLnExit(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18);
end;
{$ELSE}
procedure InitializeDebugOutput;
var
DebugFileName: string;
function GetDebugFileName: string;
const
DebugLogStart = '--debug-log=';
DebugLogStartLength = length(DebugLogStart);
var
i: integer;
EnvVarName: string;
begin
Result := '';
// first try to find the log file name in the command line parameters
for i:= 1 to Paramcount do begin
if copy(ParamStrUTF8(i),1, DebugLogStartLength)=DebugLogStart then begin
Result := copy(ParamStrUTF8(i), DebugLogStartLength+1,
Length(ParamStrUTF8(i))-DebugLogStartLength);
end;
end;
// if not found yet, then try to find in the environment variables
if (length(result)=0) then begin
EnvVarName:= ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'') + '_debuglog';
Result := GetEnvironmentVariableUTF8(EnvVarName);
end;
if (length(result)>0) then
Result := ExpandFileNameUTF8(Result);
end;
var
fm: Byte;
begin
DebugText := nil;
DebugFileName := GetDebugFileName;
if (length(DebugFileName)>0) and
(DirPathExists(ExtractFileDir(DebugFileName))) then
begin
fm:=Filemode;
new(DebugText);
try
Filemode:=fmShareDenyNone;
Assign(DebugText^, DebugFileName);
if FileExistsUTF8(DebugFileName) then
Append(DebugText^)
else
Rewrite(DebugText^);
except
Freemem(DebugText);
DebugText := nil;
// Add extra line ending: a dialog will be shown in windows gui application
writeln(StdOut, 'Cannot open file: ', DebugFileName+LineEnding);
end;
Filemode:=fm;
end;
if DebugText=nil then
begin
if TextRec(Output).Mode=fmClosed then
DebugText := nil
else
DebugText := @Output;
DebugTextAllocated := false;
end else
DebugTextAllocated := true;
end;
procedure CloseDebugOutput;
begin
if DebugTextAllocated then begin
Close(DebugText^);
Dispose(DebugText);
DebugTextAllocated := false;
end;
DebugText := nil;
end;
procedure FinalizeDebugOutput;
begin
CloseDebugOutput;
end;
procedure DebugLnNestCreatePrefix;
const
CurrentLen: Integer = 0;
var
s: String;
NewLen: Integer;
begin
NewLen := DebugNestLvl * DebugLnNestLvlIndent;
if NewLen < 0 then NewLen := 0;
if (NewLen >= DebugLnMaxNestPrefixLen) then begin
NewLen := DebugLnMaxNestPrefixLen;
s := IntToStr(DebugNestLvl);
if length(s)+1 > NewLen then
NewLen := length(s)+1;
end else
s := '';
if NewLen > CurrentLen then
ReAllocMem(DebugNestPrefix, NewLen+21);
CurrentLen := NewLen+20;
FillChar(DebugNestPrefix^, NewLen, ' ');
if s <> '' then
System.Move(s[1], DebugNestPrefix[0], length(s));
if (NewLen >= DebugLnMaxNestPrefixLen) then
DebugNestPrefix[DebugLnMaxNestPrefixLen] := #0
else
DebugNestPrefix[NewLen] := #0;
end;
procedure DebugLnNestFreePrefix;
begin
if DebugNestPrefix <> nil then
ReAllocMem(DebugNestPrefix, 0);
end;
procedure DumpStack;
begin
if Assigned(DebugText) then
Dump_Stack(DebugText^, get_frame);
end;
procedure DebugLn(Args: array of const);
var
i: Integer;
begin
for i:=Low(Args) to High(Args) do begin
case Args[i].VType of
vtInteger: DbgOut(dbgs(Args[i].vinteger));
vtInt64: DbgOut(dbgs(Args[i].VInt64^));
vtQWord: DbgOut(dbgs(Args[i].VQWord^));
vtBoolean: DbgOut(dbgs(Args[i].vboolean));
vtExtended: DbgOut(dbgs(Args[i].VExtended^));
{$ifdef FPC_CURRENCY_IS_INT64}
// MWE:
// fpc 2.x has troubles in choosing the right dbgs()
// so we convert here
vtCurrency: DbgOut(dbgs(int64(Args[i].vCurrency^)/10000, 4));
{$else}
vtCurrency: DbgOut(dbgs(Args[i].vCurrency^));
{$endif}
vtString: DbgOut(Args[i].VString^);
vtAnsiString: DbgOut(AnsiString(Args[i].VAnsiString));
vtChar: DbgOut(Args[i].VChar);
vtPChar: DbgOut(Args[i].VPChar);
vtPWideChar: DbgOut(Args[i].VPWideChar);
vtWideChar: DbgOut(AnsiString(Args[i].VWideChar));
vtWidestring: DbgOut(AnsiString(WideString(Args[i].VWideString)));
vtUnicodeString: DbgOut(AnsiString(UnicodeString(Args[i].VUnicodeString)));
vtObject: DbgOut(DbgSName(Args[i].VObject));
vtClass: DbgOut(DbgSName(Args[i].VClass));
vtPointer: DbgOut(Dbgs(Args[i].VPointer));
else
DbgOut('?unknown variant?');
end;
end;
DebugLn;
end;
procedure DebugLn(const S: String; Args: array of const);
begin
DebugLn(Format(S, Args));
end;
procedure DebugLn;
begin
DebugLn('');
end;
procedure DebugLn(const s: string);
begin
{$ifdef WinCE}
if DebugNestAtBOL and (s <> '') then
DbgAppendToFile(ExtractFilePath(ParamStr(0)) + Str_LCL_Debug_File, DebugNestPrefix+s)
else
DbgAppendToFile(ExtractFilePath(ParamStr(0)) + Str_LCL_Debug_File, s);
{$else}
// First of all verify if a widgetset has override DebugLn
if DebugLnProc <> nil then
begin
DebugLnProc(s);
Exit;
end;
// Now the default code
if not Assigned(DebugText) then exit;
if DebugNestAtBOL and (s <> '') then
write(DebugText^, DebugNestPrefix);
writeln(DebugText^, ConvertLineEndings(s));
{$endif}
DebugNestAtBOL := True;
end;
procedure DebugLn(const s1, s2: string);
begin
DebugLn(s1+s2);
end;
procedure DebugLn(const s1, s2, s3: string);
begin
DebugLn(s1+s2+s3);
end;
procedure DebugLn(const s1, s2, s3, s4: string);
begin
DebugLn(s1+s2+s3+s4);
end;
procedure DebugLn(const s1, s2, s3, s4, s5: string);
begin
DebugLn(s1+s2+s3+s4+s5);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8, s9: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8+s9);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11,
s12: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12,
s13: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12+s13);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13,
s14: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12+s13+s14);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13,
s14, s15: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12+s13+s14+s15);
end;
procedure DebugLn(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13,
s14, s15, s16: string);
begin
DebugLn(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12+s13+s14+s15+s16);
end;
procedure DebugLnEnter(const s: string);
begin
if not DebugNestAtBOL then
DebugLn;
if s <> '' then
DebugLn(s);
inc(DebugNestLvl);
DebugLnNestCreatePrefix;
end;
procedure DebugLnEnter(Args: array of const);
begin
if not DebugNestAtBOL then
DebugLn;
DebugLn(Args);
inc(DebugNestLvl);
DebugLnNestCreatePrefix;
end;
procedure DebugLnEnter(s: string; Args: array of const);
begin
DebugLnEnter(Format(s, Args));
end;
procedure DebugLnEnter(const s1: string; const s2: string; const s3: string;
const s4: string; const s5: string; const s6: string; const s7: string;
const s8: string; const s9: string; const s10: string; const s11: string;
const s12: string; const s13: string; const s14: string; const s15: string;
const s16: string; const s17: string; const s18: string);
begin
DebugLnEnter(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12+s13+s14+s15+s16+s17+s18);
end;
procedure DebugLnExit(const s: string);
begin
dec(DebugNestLvl);
if DebugNestLvl < 0 then DebugNestLvl := 0;
DebugLnNestCreatePrefix;
if not DebugNestAtBOL then
DebugLn;
if s <> '' then
DebugLn(s);
end;
procedure DebugLnExit(Args: array of const);
begin
dec(DebugNestLvl);
if DebugNestLvl < 0 then DebugNestLvl := 0;
DebugLnNestCreatePrefix;
if not DebugNestAtBOL then
DebugLn;
DebugLn(Args);
end;
procedure DebugLnExit(s: string; Args: array of const);
begin
DebugLnExit(Format(s, Args));
end;
procedure DebugLnExit(const s1: string; const s2: string; const s3: string;
const s4: string; const s5: string; const s6: string; const s7: string;
const s8: string; const s9: string; const s10: string; const s11: string;
const s12: string; const s13: string; const s14: string; const s15: string;
const s16: string; const s17: string; const s18: string);
begin
DebugLnExit(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12+s13+s14+s15+s16+s17+s18);
end;
procedure DbgOut(const S: String; Args: array of const);
begin
DbgOut(Format(S, Args));
end;
procedure DBGOut(const s: string);
begin
{$ifdef WinCE}
if DebugNestAtBOL and (s <> '') then
DbgAppendToFileWithoutLn(ExtractFilePath(ParamStr(0)) + Str_LCL_Debug_File, DebugNestPrefix);
DbgAppendToFileWithoutLn(ExtractFilePath(ParamStr(0)) + Str_LCL_Debug_File, s);
{$else}
if DebugOutProc <> nil then
begin
DebugOutProc(s);
Exit;
end;
if Assigned(DebugText) then begin
if DebugNestAtBOL and (s <> '') then
write(DebugText^, DebugNestPrefix);
write(DebugText^, s);
end;
{$endif}
DebugNestAtBOL := (s = '') or (s[length(s)] in [#10,#13]);
end;
procedure DBGOut(const s1, s2: string);
begin
DbgOut(s1+s2);
end;
procedure DbgOut(const s1, s2, s3: string);
begin
DbgOut(s1+s2+s3);
end;
procedure DbgOut(const s1, s2, s3, s4: string);
begin
DbgOut(s1+s2+s3+s4);
end;
procedure DbgOut(const s1, s2, s3, s4, s5: string);
begin
DbgOut(s1+s2+s3+s4+s5);
end;
procedure DbgOut(const s1, s2, s3, s4, s5, s6: string);
begin
DbgOut(s1+s2+s3+s4+s5+s6);
end;
procedure DbgOut(const s1, s2, s3, s4, s5, s6, s7: string);
begin
DbgOut(s1+s2+s3+s4+s5+s6+s7);
end;
procedure DbgOut(const s1, s2, s3, s4, s5, s6, s7, s8: string);
begin
DbgOut(s1+s2+s3+s4+s5+s6+s7+s8);
end;
procedure DbgOut(const s1, s2, s3, s4, s5, s6, s7, s8, s9: string);
begin
DbgOut(s1+s2+s3+s4+s5+s6+s7+s8+s9);
end;
procedure DbgOut(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10: string);
begin
DbgOut(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10);
end;
procedure DbgOut(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11: string);
begin
DbgOut(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11);
end;
procedure DbgOut(const s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12: string);
begin
DbgOut(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12);
end;
{$ENDIF}
function DbgS(const c: cardinal): string;
begin
Result:=LazLoggerBase.DbgS(c);
end;
function DbgS(const i: longint): string;
begin
Result:=LazLoggerBase.DbgS(i);
end;
function DbgS(const i: int64): string;
begin
Result:=LazLoggerBase.DbgS(i);
end;
function DbgS(const q: qword): string;
begin
Result:=LazLoggerBase.DbgS(q);
end;
function DbgS(const r: TRect): string;
begin
Result:=LazLoggerBase.DbgS(r);
end;
function DbgS(const p: TPoint): string;
begin
Result:=LazLoggerBase.DbgS(p);
end;
function DbgS(const p: pointer): string;
begin
Result:=LazLoggerBase.DbgS(p);
end;
function DbgS(const e: extended; MaxDecimals: integer): string;
begin
Result:=LazLoggerBase.DbgS(e,MaxDecimals);
end;
function DbgS(const b: boolean): string;
begin
Result:=LazLoggerBase.DbgS(b);
end;
function DbgS(const s: TComponentState): string;
begin
Result:=LazLoggerBase.DbgS(s);
end;
function DbgS(const m: TMethod): string;
begin
Result:=LazLoggerBase.DbgS(m);
end;
function DbgSName(const p: TObject): string;
begin
Result:=LazLoggerBase.DbgSName(p);
end;
function DbgSName(const p: TClass): string;
begin
Result:=LazLoggerBase.DbgSName(p);
end;
function DbgStr(const StringWithSpecialChars: string): string;
begin
Result:=LazLoggerBase.DbgStr(StringWithSpecialChars);
end;
function DbgWideStr(const StringWithSpecialChars: widestring): string;
begin
Result:=LazLoggerBase.DbgWideStr(StringWithSpecialChars);
end;
function dbgMemRange(P: PByte; Count: integer; Width: integer): string;
begin
Result:=LazLoggerBase.dbgMemRange(P,Count,Width);
end;
function dbgMemStream(MemStream: TCustomMemoryStream; Count: integer): string;
begin
Result:=LazLoggerBase.dbgMemStream(MemStream,Count);
end;
function dbgObjMem(AnObject: TObject): string;
begin
Result:=LazLoggerBase.dbgObjMem(AnObject);
end;
function dbghex(i: Int64): string;
begin
Result:=LazLoggerBase.dbghex(i);
end;
function DbgSWindowPosFlags(Flags: UInt): String;
begin
Result := '';
if (SWP_NOSIZE and Flags) <> 0 then
Result := Result + 'SWP_NOSIZE, ';
if (SWP_NOMOVE and Flags) <> 0 then
Result := Result + 'SWP_NOMOVE, ';
if (SWP_NOZORDER and Flags) <> 0 then
Result := Result + 'SWP_NOZORDER, ';
if (SWP_NOREDRAW and Flags) <> 0 then
Result := Result + 'SWP_NOREDRAW, ';
if (SWP_NOACTIVATE and Flags) <> 0 then
Result := Result + 'SWP_NOACTIVATE, ';
if (SWP_DRAWFRAME and Flags) <> 0 then
Result := Result + 'SWP_DRAWFRAME, ';
if (SWP_SHOWWINDOW and Flags) <> 0 then
Result := Result + 'SWP_SHOWWINDOW, ';
if (SWP_HIDEWINDOW and Flags) <> 0 then
Result := Result + 'SWP_HIDEWINDOW, ';
if (SWP_NOCOPYBITS and Flags) <> 0 then
Result := Result + 'SWP_NOCOPYBITS, ';
if (SWP_NOOWNERZORDER and Flags) <> 0 then
Result := Result + 'SWP_NOOWNERZORDER, ';
if (SWP_NOSENDCHANGING and Flags) <> 0 then
Result := Result + 'SWP_NOSENDCHANGING, ';
if (SWP_DEFERERASE and Flags) <> 0 then
Result := Result + 'SWP_DEFERERASE, ';
if (SWP_ASYNCWINDOWPOS and Flags) <> 0 then
Result := Result + 'SWP_ASYNCWINDOWPOS, ';
if (SWP_STATECHANGED and Flags) <> 0 then
Result := Result + 'SWP_STATECHANGED, ';
if (SWP_SourceIsInterface and Flags) <> 0 then
Result := Result + 'SWP_SourceIsInterface, ';
if Result <> '' then
Delete(Result, Length(Result) - 1, 2);
end;
function DbgS(const i1, i2, i3, i4: integer): string;
begin
Result:=LazLoggerBase.DbgS(i1,i2,i3,i4);
end;
function DbgS(const Shift: TShiftState): string;
begin
Result:=LazLoggerBase.DbgS(Shift);
end;
function DbgsVKCode(c: word): string;
begin
case c of
VK_UNKNOWN: Result:='VK_UNKNOWN';
VK_LBUTTON: Result:='VK_LBUTTON';
VK_RBUTTON: Result:='VK_RBUTTON';
VK_CANCEL: Result:='VK_CANCEL';
VK_MBUTTON: Result:='VK_MBUTTON';
VK_BACK: Result:='VK_BACK';
VK_TAB: Result:='VK_TAB';
VK_CLEAR: Result:='VK_CLEAR';
VK_RETURN: Result:='VK_RETURN';
VK_SHIFT: Result:='VK_SHIFT';
VK_CONTROL: Result:='VK_CONTROL';
VK_MENU: Result:='VK_MENU';
VK_PAUSE: Result:='VK_PAUSE';
VK_CAPITAL: Result:='VK_CAPITAL';
VK_KANA: Result:='VK_KANA';
VK_JUNJA: Result:='VK_JUNJA';
VK_FINAL: Result:='VK_FINAL';
VK_HANJA: Result:='VK_HANJA';
VK_ESCAPE: Result:='VK_ESCAPE';
VK_CONVERT: Result:='VK_CONVERT';
VK_NONCONVERT: Result:='VK_NONCONVERT';
VK_ACCEPT: Result:='VK_ACCEPT';
VK_MODECHANGE: Result:='VK_MODECHANGE';
VK_SPACE: Result:='VK_SPACE';
VK_PRIOR: Result:='VK_PRIOR';
VK_NEXT: Result:='VK_NEXT';
VK_END: Result:='VK_END';
VK_HOME: Result:='VK_HOME';
VK_LEFT: Result:='VK_LEFT';
VK_UP: Result:='VK_UP';
VK_RIGHT: Result:='VK_RIGHT';
VK_DOWN: Result:='VK_DOWN';
VK_SELECT: Result:='VK_SELECT';
VK_PRINT: Result:='VK_PRINT';
VK_EXECUTE: Result:='VK_EXECUTE';
VK_SNAPSHOT: Result:='VK_SNAPSHOT';
VK_INSERT: Result:='VK_INSERT';
VK_DELETE: Result:='VK_DELETE';
VK_HELP: Result:='VK_HELP';
VK_0: Result:='VK_0';
VK_1: Result:='VK_1';
VK_2: Result:='VK_2';
VK_3: Result:='VK_3';
VK_4: Result:='VK_4';
VK_5: Result:='VK_5';
VK_6: Result:='VK_6';
VK_7: Result:='VK_7';
VK_8: Result:='VK_8';
VK_9: Result:='VK_9';
VK_A: Result:='VK_A';
VK_B: Result:='VK_B';
VK_C: Result:='VK_C';
VK_D: Result:='VK_D';
VK_E: Result:='VK_E';
VK_F: Result:='VK_F';
VK_G: Result:='VK_G';
VK_H: Result:='VK_H';
VK_I: Result:='VK_I';
VK_J: Result:='VK_J';
VK_K: Result:='VK_K';
VK_L: Result:='VK_L';
VK_M: Result:='VK_M';
VK_N: Result:='VK_N';
VK_O: Result:='VK_O';
VK_P: Result:='VK_P';
VK_Q: Result:='VK_Q';
VK_R: Result:='VK_R';
VK_S: Result:='VK_S';
VK_T: Result:='VK_T';
VK_U: Result:='VK_U';
VK_V: Result:='VK_V';
VK_W: Result:='VK_W';
VK_X: Result:='VK_X';
VK_Y: Result:='VK_Y';
VK_Z: Result:='VK_Z';
VK_LWIN: Result:='VK_LWIN';
VK_RWIN: Result:='VK_RWIN';
VK_APPS: Result:='VK_APPS';
VK_SLEEP: Result:='VK_SLEEP';
VK_NUMPAD0: Result:='VK_NUMPAD0';
VK_NUMPAD1: Result:='VK_NUMPAD1';
VK_NUMPAD2: Result:='VK_NUMPAD2';
VK_NUMPAD3: Result:='VK_NUMPAD3';
VK_NUMPAD4: Result:='VK_NUMPAD4';
VK_NUMPAD5: Result:='VK_NUMPAD5';
VK_NUMPAD6: Result:='VK_NUMPAD6';
VK_NUMPAD7: Result:='VK_NUMPAD7';
VK_NUMPAD8: Result:='VK_NUMPAD8';
VK_NUMPAD9: Result:='VK_NUMPAD9';
VK_MULTIPLY: Result:='VK_MULTIPLY';
VK_ADD: Result:='VK_ADD';
VK_SEPARATOR: Result:='VK_SEPARATOR';
VK_SUBTRACT: Result:='VK_SUBTRACT';
VK_DECIMAL: Result:='VK_DECIMAL';
VK_DIVIDE: Result:='VK_DIVIDE';
VK_F1: Result:='VK_F1';
VK_F2: Result:='VK_F2';
VK_F3: Result:='VK_F3';
VK_F4: Result:='VK_F4';
VK_F5: Result:='VK_F5';
VK_F6: Result:='VK_F6';
VK_F7: Result:='VK_F7';
VK_F8: Result:='VK_F8';
VK_F9: Result:='VK_F9';
VK_F10: Result:='VK_F10';
VK_F11: Result:='VK_F11';
VK_F12: Result:='VK_F12';
VK_F13: Result:='VK_F13';
VK_F14: Result:='VK_F14';
VK_F15: Result:='VK_F15';
VK_F16: Result:='VK_F16';
VK_F17: Result:='VK_F17';
VK_F18: Result:='VK_F18';
VK_F19: Result:='VK_F19';
VK_F20: Result:='VK_F20';
VK_F21: Result:='VK_F21';
VK_F22: Result:='VK_F22';
VK_F23: Result:='VK_F23';
VK_F24: Result:='VK_F24';
VK_NUMLOCK: Result:='VK_NUMLOCK';
VK_SCROLL: Result:='VK_SCROLL';
VK_LSHIFT: Result:='VK_LSHIFT';
VK_RSHIFT: Result:='VK_RSHIFT';
VK_LCONTROL: Result:='VK_LCONTROL';
VK_RCONTROL: Result:='VK_RCONTROL';
VK_LMENU: Result:='VK_LMENU';
VK_RMENU: Result:='VK_RMENU';
VK_BROWSER_BACK: Result:='VK_BROWSER_BACK';
VK_BROWSER_FORWARD: Result:='VK_BROWSER_FORWARD';
VK_BROWSER_REFRESH: Result:='VK_BROWSER_REFRESH';
VK_BROWSER_STOP: Result:='VK_BROWSER_STOP';
VK_BROWSER_SEARCH: Result:='VK_BROWSER_SEARCH';
VK_BROWSER_FAVORITES: Result:='VK_BROWSER_FAVORITES';
VK_BROWSER_HOME: Result:='VK_BROWSER_HOME';
VK_VOLUME_MUTE: Result:='VK_VOLUME_MUTE';
VK_VOLUME_DOWN: Result:='VK_VOLUME_DOWN';
VK_VOLUME_UP: Result:='VK_VOLUME_UP';
VK_MEDIA_NEXT_TRACK: Result:='VK_MEDIA_NEXT_TRACK';
VK_MEDIA_PREV_TRACK: Result:='VK_MEDIA_PREV_TRACK';
VK_MEDIA_STOP: Result:='VK_MEDIA_STOP';
VK_MEDIA_PLAY_PAUSE: Result:='VK_MEDIA_PLAY_PAUSE';
VK_LAUNCH_MAIL: Result:='VK_LAUNCH_MAIL';
VK_LAUNCH_MEDIA_SELECT: Result:='VK_LAUNCH_MEDIA_SELECT';
VK_LAUNCH_APP1: Result:='VK_LAUNCH_APP1';
VK_LAUNCH_APP2: Result:='VK_LAUNCH_APP2';
// New keys in 0.9.31+
VK_LCL_EQUAL: Result:='VK_LCL_EQUAL';
VK_LCL_COMMA: Result:='VK_LCL_COMMA';
VK_LCL_POINT: Result:='VK_LCL_POINT';
VK_LCL_SLASH: Result:='VK_LCL_SLASH';
VK_LCL_SEMI_COMMA:Result:='VK_LCL_SEMI_COMMA';
VK_LCL_MINUS :Result:='VK_LCL_MINUS';
VK_LCL_OPEN_BRAKET:Result:='VK_LCL_OPEN_BRAKET';
VK_LCL_CLOSE_BRAKET:Result:='VK_LCL_CLOSE_BRAKET';
VK_LCL_BACKSLASH :Result:='VK_LCL_BACKSLASH';
VK_LCL_TILDE :Result:='VK_LCL_TILDE';
VK_LCL_QUOTE :Result:='VK_LCL_QUOTE';
//
VK_LCL_POWER: Result:='VK_LCL_POWER';
VK_LCL_CALL: Result:='VK_LCL_CALL';
VK_LCL_ENDCALL: Result:='VK_LCL_ENDCALL';
VK_LCL_AT: Result:='VK_LCL_AT';
else
Result:='VK_('+dbgs(c)+')';
end;
end;
function DbgS(const ASize: TSize): string;
begin
Result:=LazLoggerBase.DbgS(ASize);
end;
function DbgS(const ATM: TTextMetric): string;
begin
with ATM do
Result :=
'tmHeight: ' + DbgS(tmHeight) +
' tmAscent: ' + DbgS(tmAscent) +
' tmDescent: ' + DbgS(tmDescent) +
' tmInternalLeading: ' + DbgS(tmInternalLeading) +
' tmExternalLeading: ' + DbgS(tmExternalLeading) +
' tmAveCharWidth: ' + DbgS(tmAveCharWidth) +
' tmMaxCharWidth: ' + DbgS(tmMaxCharWidth) +
' tmWeight: ' + DbgS(tmWeight) +
' tmOverhang: ' + DbgS(tmOverhang) +
' tmDigitizedAspectX: ' + DbgS(tmDigitizedAspectX) +
' tmDigitizedAspectY: ' + DbgS(tmDigitizedAspectY) +
' tmFirstChar: ' + tmFirstChar +
' tmLastChar: ' + tmLastChar +
' tmDefaultChar: ' + tmDefaultChar +
' tmBreakChar: ' + tmBreakChar +
' tmItalic: ' + DbgS(tmItalic) +
' tmUnderlined: ' + DbgS(tmUnderlined) +
' tmStruckOut: ' + DbgS(tmStruckOut) +
' tmPitchAndFamily: ' + DbgS(tmPitchAndFamily) +
' tmCharSet: ' + DbgS(tmCharSet);
end;
function DbgS(const AScrollInfo: TScrollInfo): string;
begin
Result := '';
if (SIF_POS and AScrollInfo.fMask) > 0 then
Result := 'Pos: ' + DbgS(AScrollInfo.nPos);
if (SIF_RANGE and AScrollInfo.fMask) > 0 then
Result := Result + ' Min: ' + DbgS(AScrollInfo.nMin) + ' Max: ' +
DbgS(AScrollInfo.nMax);
if (SIF_PAGE and AScrollInfo.fMask) > 0 then
Result := Result + ' Page: ' + DbgS(AScrollInfo.nPage);
if (SIF_TRACKPOS and AScrollInfo.fMask) > 0 then
Result := Result + ' TrackPos: ' + DbgS(AScrollInfo.nTrackPos);
if Result = '' then Result := '(no scrollinfo)';
end;
function DbgS(const AVariant: Variant): string;
begin
if TVarData(AVariant).VType = varEmpty then
result := '<empty>'
else
if TVarData(AVariant).vtype = varNull then
result := '<null>'
else
result := AVariant;
end;
procedure DbgOutThreadLog(const Msg: string);
var
PID: PtrInt;
fs: TFileStreamUTF8;
Filename: string;
begin
PID:=PtrInt(GetThreadID);
Filename:='Log'+IntToStr(PID);
if FileExistsUTF8(Filename) then
fs:=TFileStreamUTF8.Create(Filename,fmOpenWrite or fmShareDenyNone)
else
fs:=TFileStreamUTF8.Create(Filename,fmCreate);
fs.Position:=fs.Size;
fs.Write(Msg[1], length(Msg));
fs.Free;
end;
procedure DebuglnThreadLog(const Msg: string);
var
PID: PtrInt;
begin
PID:=PtrInt(GetThreadID);
DbgOutThreadLog(IntToStr(PtrInt(PID))+' : '+Msg+LineEnding);
end;
procedure DebuglnThreadLog(Args: array of const);
var
i: Integer;
s: String;
begin
s:='';
for i:=Low(Args) to High(Args) do begin
case Args[i].VType of
vtInteger: s:=s+dbgs(Args[i].vinteger);
vtInt64: s:=s+dbgs(Args[i].VInt64^);
vtQWord: s:=s+dbgs(Args[i].VQWord^);
vtBoolean: s:=s+dbgs(Args[i].vboolean);
vtExtended: s:=s+dbgs(Args[i].VExtended^);
{$ifdef FPC_CURRENCY_IS_INT64}
// MWE:
// ppcppc 2.0.2 has troubles in choosing the right dbgs()
// so we convert here (i don't know about other versions
vtCurrency: s:=s+dbgs(int64(Args[i].vCurrency^)/10000, 4);
{$else}
vtCurrency: s:=s+dbgs(Args[i].vCurrency^);
{$endif}
vtString: s:=s+Args[i].VString^;
vtAnsiString: s:=s+AnsiString(Args[i].VAnsiString);
vtChar: s:=s+Args[i].VChar;
vtPChar: s:=s+Args[i].VPChar;
vtPWideChar: s:=AnsiString(WideString(s)+Args[i].VPWideChar);
vtWideChar: s:=AnsiString(WideString(s)+Args[i].VWideChar);
vtWidestring: s:=AnsiString(WideString(s)+WideString(Args[i].VWideString));
{$IF FPC_FULLVERSION>=20701}
vtUnicodeString: s:=AnsiString(UnicodeString(s)+UnicodeString(Args[i].VUnicodeString));
{$endif}
vtObject: s:=s+DbgSName(Args[i].VObject);
vtClass: s:=s+DbgSName(Args[i].VClass);
vtPointer: s:=s+Dbgs(Args[i].VPointer);
else
DbgOutThreadLog('?unknown variant?');
end;
end;
DebuglnThreadLog(s);
end;
procedure DebuglnThreadLog;
begin
DebuglnThreadLog('');
end;
procedure DbgSaveData(FileName: String; AData: PChar; ADataSize: PtrUInt);
var
S: TStream;
begin
S := TFileStreamUTF8.Create(FileName, fmCreate);
S.Write(AData^, ADataSize);
S.Free;
end;
procedure DbgAppendToFile(FileName, S: String);
var
F: TextFile;
begin
AssignFile(F, FileName);
{$I-}
Append(F);
if IOResult <> 0 then
Rewrite(F);
{$I+}
WriteLn(F, S);
CloseFile(F);
end;
procedure DbgAppendToFileWithoutLn(FileName, S: String);
var
F: TextFile;
begin
AssignFile(F, FileName);
{$I-}
Append(F);
if IOResult <> 0 then
Rewrite(F);
{$I+}
Write(F, S);
CloseFile(F);
end;
function StripLN(const ALine: String): String;
var
idx: Integer;
begin
Result := ALine;
idx := Pos(#10, Result);
if idx = 0
then begin
idx := Pos(#13, Result);
if idx = 0 then Exit;
end
else begin
if (idx > 1)
and (Result[idx - 1] = #13)
then Dec(idx);
end;
SetLength(Result, idx - 1);
end;
function GetPart(const ASkipTo, AnEnd: String; var ASource: String;
const AnIgnoreCase, AnUpdateSource: Boolean): String;
begin
Result := GetPart([ASkipTo], [AnEnd], ASource, AnIgnoreCase, AnUpdateSource);
end;
function GetPart(const ASkipTo, AnEnd: array of String; var ASource: String;
const AnIgnoreCase: Boolean = False; const AnUpdateSource: Boolean = True): String;
var
n, i, idx: Integer;
S, Source, Match: String;
HasEscape: Boolean;
begin
Source := ASource;
if High(ASkipTo) >= 0
then begin
idx := 0;
Match := '';
HasEscape := False;
if AnIgnoreCase
then S := UpperCase(Source)
else S := Source;
for n := Low(ASkipTo) to High(ASkipTo) do
begin
if ASkipTo[n] = ''
then begin
HasEscape := True;
Continue;
end;
if AnIgnoreCase
then i := Pos(UpperCase(ASkipTo[n]), S)
else i := Pos(ASkipTo[n], S);
if i > idx
then begin
idx := i;
Match := ASkipTo[n];
end;
end;
if (idx = 0) and not HasEscape
then begin
Result := '';
Exit;
end;
if idx > 0
then Delete(Source, 1, idx + Length(Match) - 1);
end;
if AnIgnoreCase
then S := UpperCase(Source)
else S := Source;
idx := MaxInt;
for n := Low(AnEnd) to High(AnEnd) do
begin
if AnEnd[n] = '' then Continue;
if AnIgnoreCase
then i := Pos(UpperCase(AnEnd[n]), S)
else i := Pos(AnEnd[n], S);
if (i > 0) and (i < idx) then idx := i;
end;
if idx = MaxInt
then begin
Result := Source;
Source := '';
end
else begin
Result := Copy(Source, 1, idx - 1);
Delete(Source, 1, idx - 1);
end;
if AnUpdateSource
then ASource := Source;
end;
{
Ensures the covenient look of multiline string
when displaying it in the single line
* Replaces CR and LF with spaces
* Removes duplicate spaces
}
function TextToSingleLine(const AText: string): string;
var
str: string;
i, wstart, wlen: Integer;
begin
str := Trim(AText);
wstart := 0;
wlen := 0;
i := 1;
while i < Length(str) - 1 do
begin
if (str[i] in [' ', #13, #10]) then
begin
if (wstart = 0) then
begin
wstart := i;
wlen := 1;
end else
Inc(wlen);
end else
begin
if wstart > 0 then
begin
str[wstart] := ' ';
Delete(str, wstart+1, wlen-1);
Dec(i, wlen-1);
wstart := 0;
end;
end;
Inc(i);
end;
Result := str;
end;
function SwapCase(Const S: String): String;
// Inverts the character case. Like LowerCase and UpperCase combined.
var
i : Integer;
P : PChar;
begin
Result := S;
if not assigned(pointer(result)) then exit;
UniqueString(Result);
P:=Pchar(pointer(Result));
for i := 1 to Length(Result) do begin
if (P^ in ['a'..'z']) then
P^ := char(byte(p^) - 32)
else if (P^ in ['A'..'Z']) then
P^ := char(byte(p^) + 32);
Inc(P);
end;
end;
function StringCase(const AString: String; const ACase: array of String {; const AIgnoreCase = False, APartial = false: Boolean}): Integer;
begin
Result := StringCase(AString, ACase, False, False);
end;
function StringCase(const AString: String; const ACase: array of String; const AIgnoreCase, APartial: Boolean): Integer;
var
Search, S: String;
begin
if High(ACase) = -1
then begin
Result := -1;
Exit;
end;
if AIgnoreCase
then Search := UpperCase(AString)
else Search := AString;
for Result := Low(ACase) to High(ACase) do
begin
if AIgnoreCase
then S := UpperCase(ACase[Result])
else S := ACase[Result];
if Search = S then Exit;
if not APartial then Continue;
if Length(Search) >= Length(S) then Continue;
if StrLComp(PChar(Search), PChar(S), Length(Search)) = 0 then Exit;
end;
Result := -1;
end;
function ClassCase(const AClass: TClass; const ACase: array of TClass {; const ADecendant: Boolean = True}): Integer;
begin
Result := ClassCase(AClass, ACase, True);
end;
function ClassCase(const AClass: TClass; const ACase: array of TClass; const ADecendant: Boolean): Integer;
begin
for Result := Low(ACase) to High(ACase) do
begin
if AClass = ACase[Result] then Exit;
if not ADecendant then Continue;
if AClass.InheritsFrom(ACase[Result]) then Exit;
end;
Result := -1;
end;
function UTF16CharacterLength(p: PWideChar): integer;
// returns length of UTF16 character in number of words
// The endianess of the machine will be taken.
begin
if p<>nil then begin
if (ord(p[0]) < $D800) or (ord(p[0]) > $DFFF) then
Result:=1
else
Result:=2;
end else begin
Result:=0;
end;
end;
function UTF16Length(const s: UTF16String): PtrInt;
begin
Result:=UTF16Length(PWideChar(s),length(s));
end;
function UTF16Length(p: PWideChar; WordCount: PtrInt): PtrInt;
var
CharLen: LongInt;
begin
Result:=0;
while (WordCount>0) do begin
inc(Result);
CharLen:=UTF16CharacterLength(p);
inc(p,CharLen);
dec(WordCount,CharLen);
end;
end;
function UTF16CharacterToUnicode(p: PWideChar; out CharLen: integer): Cardinal;
var
w1: cardinal;
w2: Cardinal;
begin
if p<>nil then begin
w1:=ord(p[0]);
if (w1 < $D800) or (w1 > $DFFF) then begin
// is 1 word character
Result:=w1;
CharLen:=1;
end else begin
// could be 2 word character
w2:=ord(p[1]);
if (w2>=$DC00) then begin
// is 2 word character
Result:=(w1-$D800) shl 10 + (w2-$DC00) + $10000;
CharLen:=2;
end else begin
// invalid character
Result:=w1;
CharLen:=1;
end;
end;
end else begin
Result:=0;
CharLen:=0;
end;
end;
function UnicodeToUTF16(u: cardinal): UTF16String;
begin
// u should be <= $10FFFF to fit into UTF-16
if u < $10000 then
// Note: codepoints $D800 - $DFFF are reserved
Result:=system.widechar(u)
else
Result:=system.widechar($D800+((u - $10000) shr 10))+system.widechar($DC00+((u - $10000) and $3ff));
end;
function CreateFirstIdentifier(const Identifier: string): string;
// example: Ident59 becomes Ident1
var
p: Integer;
begin
p:=length(Identifier);
while (p>=1) and (Identifier[p] in ['0'..'9']) do dec(p);
Result:=copy(Identifier,1,p)+'1';
end;
function CreateNextIdentifier(const Identifier: string): string;
// example: Ident59 becomes Ident60
var
p: Integer;
begin
p:=length(Identifier);
while (p>=1) and (Identifier[p] in ['0'..'9']) do dec(p);
Result:=copy(Identifier,1,p)
+IntToStr(1+StrToIntDef(copy(Identifier,p+1,length(Identifier)-p),0));
end;
function IsFontNameDefault(const AName: string): boolean;
begin
Result := CompareText(AName, 'default') = 0;
end;
{ TDebugLCLItems }
constructor TDebugLCLItems.Create(const TheName: string);
begin
FName:=TheName;
FItems:=TAvlTree.Create(@CompareDebugLCLItemInfos);
end;
destructor TDebugLCLItems.Destroy;
begin
FItems.FreeAndClear;
FreeAndNil(FItems);
inherited Destroy;
end;
function TDebugLCLItems.FindInfo(p: Pointer; CreateIfNotExists: boolean): TDebugLCLItemInfo;
var
ANode: TAvlTreeNode;
begin
ANode:=FItems.FindKey(p,@CompareItemWithDebugLCLItemInfo);
if ANode<>nil then
Result:=TDebugLCLItemInfo(ANode.Data)
else begin
// does not yet exists
if CreateIfNotExists then begin
Result:=MarkCreated(p,'TDebugLCLItems.FindInfo');
end else begin
Result:=nil;
end;
end;
end;
function TDebugLCLItems.IsDestroyed(p: Pointer): boolean;
var
Info: TDebugLCLItemInfo;
begin
Info:=FindInfo(p);
if Info=nil then
Result:=false
else
Result:=Info.IsDestroyed;
end;
function TDebugLCLItems.IsCreated(p: Pointer): boolean;
var
Info: TDebugLCLItemInfo;
begin
Info:=FindInfo(p);
if Info=nil then
Result:=false
else
Result:=not Info.IsDestroyed;
end;
procedure TDebugLCLItems.MarkDestroyed(p: Pointer);
var
Info: TDebugLCLItemInfo;
procedure RaiseNotCreated;
begin
DebugLn('TDebugLCLItems.MarkDestroyed not created: p=',dbgs(p));
DumpStack;
RaiseGDBException('TDebugLCLItems.MarkDestroyed');
end;
procedure RaiseDoubleDestroyed;
begin
debugLn('TDebugLCLItems.MarkDestroyed Double destroyed:');
debugln(Info.AsString(true));
debugln('Now:');
DebugLn(GetStackTrace(true));
RaiseGDBException('RaiseDoubleDestroyed');
end;
begin
Info:=FindInfo(p);
if Info=nil then
RaiseNotCreated;
if Info.IsDestroyed then
RaiseDoubleDestroyed;
Info.IsDestroyed:=true;
GetStackTracePointers(Info.DestructionStack);
//DebugLn(['TDebugLCLItems.MarkDestroyed ',dbgs(p)]);
end;
function TDebugLCLItems.GetInfo(p: Pointer; WithStackTraces: boolean): string;
var
Info: TDebugLCLItemInfo;
begin
Info:=FindInfo(p,false);
if Info<>nil then
Result:=Info.AsString(WithStackTraces)
else
Result:='';
end;
function TDebugLCLItems.MarkCreated(p: Pointer;
const InfoText: string): TDebugLCLItemInfo;
var
Info: TDebugLCLItemInfo;
procedure RaiseDoubleCreated;
begin
debugLn('TDebugLCLItems.MarkCreated CREATED TWICE. Old:');
debugln(Info.AsString(true));
debugln(' New=',dbgs(p),' InfoText="',InfoText,'"');
DebugLn(GetStackTrace(true));
RaiseGDBException('RaiseDoubleCreated');
end;
begin
Info:=FindInfo(p);
if Info=nil then begin
Info:=TDebugLCLItemInfo.Create;
Info.Item:=p;
FItems.Add(Info);
end else if not Info.IsDestroyed then begin
RaiseDoubleCreated;
end;
Info.IsDestroyed:=false;
Info.Info:=InfoText;
GetStackTracePointers(Info.CreationStack);
SetLength(Info.DestructionStack,0);
//DebugLn(['TDebugLCLItems.MarkCreated ',Name,' ',dbgs(p),' ',FItems.Count]);
//DebugLn(GetStackTrace(true));
Result:=Info;
end;
{ TDebugLCLItemInfo }
function TDebugLCLItemInfo.AsString(WithStackTraces: boolean): string;
begin
Result:='Item='+Dbgs(Item)+LineEnding
+'Info="'+DbgStr(Info)+LineEnding;
if WithStackTraces then
Result:=Result+'Creation:'+LineEnding+StackTraceAsString(CreationStack,true);
if IsDestroyed then begin
Result:=Result+'Destroyed:'+LineEnding;
if WithStackTraces then
Result:=Result+StackTraceAsString(DestructionStack,true);
end;
end;
destructor TDebugLCLItemInfo.Destroy;
begin
SetLength(CreationStack,0);
SetLength(DestructionStack,0);
inherited Destroy;
end;
initialization
{$IFDEF WithOldDebugln} InitializeDebugOutput; {$ENDIF}
{$ifdef WinCE}
// The stabs based back trace function crashes on wince,
// see http://bugs.freepascal.org/view.php?id=14330
// To prevent crashes, replace it with the default system back trace function
// that just outputs addresses and not source and line number
BackTraceStrFunc := @SysBackTraceStr;
{$endif}
{$ifdef AROS}
{$if FPC_FULLVERSION>=30101}
EnableBackTraceStr;
{$endif}
{$endif}
InterfaceInitializationHandlers := TFPList.Create;
InterfaceFinalizationHandlers := TFPList.Create;
{$IFDEF DebugLCLComponents}
DebugLCLComponents:=TDebugLCLItems.Create('LCLComponents');
{$ENDIF}
finalization
InterfaceInitializationHandlers.Free;
InterfaceInitializationHandlers:=nil;
InterfaceFinalizationHandlers.Free;
InterfaceFinalizationHandlers:=nil;
{$IFDEF DebugLCLComponents}
DebugLCLComponents.Free;
DebugLCLComponents:=nil;
{$ENDIF}
{$IFDEF WithOldDebugln}
FinalizeDebugOutput;
DebugLnNestFreePrefix;
{$ENDIF}
end.
|