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
|
{
This file is part of the Free Pascal Run Time Library (rtl)
Copyright (c) 1999-2008 by Michael Van Canneyt, Florian Klaempfl,
and Micha Nelissen
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{$H+}
{$ifdef CLASSESINLINE}{$inline on}{$endif}
type
{ extra types to compile with FPC }
HRSRC = TFPResourceHandle deprecated;
TComponentName = string;
THandle = System.THandle;
TPoint=Types.TPoint;
TRect=Types.TRect;
TSmallPoint=Types.TSmallPoint;
{$ifndef FPC_HAS_FEATURE_DYNLIBS}
HMODULE = ptrint;
{$else}
HModule = System.HModule;
{$endif}
const
{ Maximum TList size }
{$ifdef cpu16}
MaxListSize = {Maxint div 16}1024;
{$else cpu16}
MaxListSize = Maxint div 16;
{$endif cpu16}
{ values for TShortCut }
scShift = $2000;
scCtrl = $4000;
scAlt = $8000;
scNone = 0;
{ TStream seek origins }
const
soFromBeginning = 0;
soFromCurrent = 1;
soFromEnd = 2;
type
TSeekOrigin = (soBeginning, soCurrent, soEnd);
TDuplicates = Types.TDuplicates;
// For Delphi and backwards compatibility.
const
dupIgnore = Types.dupIgnore;
dupAccept = Types.dupAccept;
dupError = Types.dupError;
{ TFileStream create mode }
const
fmCreate = $FF00;
fmOpenRead = 0;
fmOpenWrite = 1;
fmOpenReadWrite = 2;
{ TParser special tokens }
toEOF = Char(0);
toSymbol = Char(1);
toString = Char(2);
toInteger = Char(3);
toFloat = Char(4);
toWString = Char(5);
Const
FilerSignature : Array[1..4] of char = 'TPF0';
type
{ Text alignment types }
TAlignment = (taLeftJustify, taRightJustify, taCenter);
TLeftRight = taLeftJustify..taRightJustify;
TVerticalAlignment = (taAlignTop, taAlignBottom, taVerticalCenter);
TTopBottom = taAlignTop..taAlignBottom;
TBiDiMode = (bdLeftToRight,bdRightToLeft,bdRightToLeftNoAlign,bdRightToLeftReadingOnly);
{ Types used by standard events }
TShiftStateEnum = (ssShift, ssAlt, ssCtrl,
ssLeft, ssRight, ssMiddle, ssDouble,
// Extra additions
ssMeta, ssSuper, ssHyper, ssAltGr, ssCaps, ssNum,
ssScroll,ssTriple,ssQuad,ssExtra1,ssExtra2);
{$packset 1}
TShiftState = set of TShiftStateEnum;
{$packset default}
THelpContext = -MaxLongint..MaxLongint;
THelpType = (htKeyword, htContext);
TShortCut = Low(Word)..High(Word);
{ Standard events }
TNotifyEvent = procedure(Sender: TObject) of object;
THelpEvent = function (Command: Word; Data: Longint;
var CallHelp: Boolean): Boolean of object;
TGetStrProc = procedure(const S: string) of object;
{ Exception classes }
EStreamError = class(Exception);
EFCreateError = class(EStreamError);
EFOpenError = class(EStreamError);
EFilerError = class(EStreamError);
EReadError = class(EFilerError);
EWriteError = class(EFilerError);
EClassNotFound = class(EFilerError);
EMethodNotFound = class(EFilerError);
EInvalidImage = class(EFilerError);
EResNotFound = class(Exception);
{$ifdef FPC_TESTGENERICS}
EListError = fgl.EListError;
{$else}
EListError = class(Exception);
{$endif}
EBitsError = class(Exception);
EStringListError = class(Exception);
EComponentError = class(Exception);
EParserError = class(Exception);
EOutOfResources = class(EOutOfMemory);
EInvalidOperation = class(Exception);
TExceptionClass = Class of Exception;
{ ---------------------------------------------------------------------
Free Pascal Observer support
---------------------------------------------------------------------}
Const
SGUIDObserved = '{663C603C-3F3C-4CC5-823C-AC8079F979E5}';
SGUIDObserver = '{BC7376EA-199C-4C2A-8684-F4805F0691CA}';
Type
// Notification operations :
// Observer has changed, is freed, item added to/deleted from list, custom event.
TFPObservedOperation = (ooChange,ooFree,ooAddItem,ooDeleteItem,ooCustom);
{$INTERFACES CORBA}
{ IFPObserved }
IFPObserved = Interface [SGUIDObserved]
// attach a new observer
Procedure FPOAttachObserver(AObserver : TObject);
// Detach an observer
Procedure FPODetachObserver(AObserver : TObject);
// Notify all observers of a change.
Procedure FPONotifyObservers(ASender : TObject; AOperation : TFPObservedOperation; Data : Pointer);
end;
{ IFPObserver }
IFPObserver = Interface [SGUIDObserver]
// Called by observed when observers are notified.
Procedure FPOObservedChanged(ASender : TObject; Operation : TFPObservedOperation; Data : Pointer);
end;
{$INTERFACES COM}
EObserver = Class(Exception);
{ Forward class declarations }
TStream = class;
TFiler = class;
TReader = class;
TWriter = class;
TComponent = class;
{ TFPList class }
PPointerList = ^TPointerList;
TPointerList = array[0..MaxListSize - 1] of Pointer;
TListSortCompare = function (Item1, Item2: Pointer): Integer;
TListCallback = Types.TListCallback;
TListStaticCallback = Types.TListStaticCallback;
{$IFNDEF FPC_TESTGENERICS}
TListAssignOp = (laCopy, laAnd, laOr, laXor, laSrcUnique, laDestUnique);
TFPList = class;
TFPListEnumerator = class
private
FList: TFPList;
FPosition: Integer;
public
constructor Create(AList: TFPList);
function GetCurrent: Pointer;
function MoveNext: Boolean;
property Current: Pointer read GetCurrent;
end;
TFPList = class(TObject)
private
FList: PPointerList;
FCount: Integer;
FCapacity: Integer;
procedure CopyMove (aList : TFPList);
procedure MergeMove (aList : TFPList);
procedure DoCopy(ListA, ListB : TFPList);
procedure DoSrcUnique(ListA, ListB : TFPList);
procedure DoAnd(ListA, ListB : TFPList);
procedure DoDestUnique(ListA, ListB : TFPList);
procedure DoOr(ListA, ListB : TFPList);
procedure DoXOr(ListA, ListB : TFPList);
protected
function Get(Index: Integer): Pointer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
procedure Put(Index: Integer; Item: Pointer); {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
procedure SetCapacity(NewCapacity: Integer);
procedure SetCount(NewCount: Integer);
Procedure RaiseIndexError(Index: Integer); deprecated;
Procedure CheckIndex(AIndex : Integer); {$ifdef CLASSESINLINE} inline;{$ENDIF}
public
Type
TDirection = (FromBeginning, FromEnd);
destructor Destroy; override;
Procedure AddList(AList : TFPList);
function Add(Item: Pointer): Integer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
procedure Clear;
procedure Delete(Index: Integer); {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
class procedure Error(const Msg: string; Data: PtrInt);
procedure Exchange(Index1, Index2: Integer);
function Expand: TFPList; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function Extract(Item: Pointer): Pointer;
function First: Pointer;
function GetEnumerator: TFPListEnumerator;
function IndexOf(Item: Pointer): Integer;
function IndexOfItem(Item: Pointer; Direction: TDirection): Integer;
procedure Insert(Index: Integer; Item: Pointer); {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function Last: Pointer;
procedure Move(CurIndex, NewIndex: Integer);
procedure Assign (ListA: TFPList; AOperator: TListAssignOp=laCopy; ListB: TFPList=nil);
function Remove(Item: Pointer): Integer;
procedure Pack;
procedure Sort(Compare: TListSortCompare);
procedure ForEachCall(proc2call:TListCallback;arg:pointer);
procedure ForEachCall(proc2call:TListStaticCallback;arg:pointer);
property Capacity: Integer read FCapacity write SetCapacity;
property Count: Integer read FCount write SetCount;
property Items[Index: Integer]: Pointer read Get write Put; default;
property List: PPointerList read FList;
end;
{$else}
TFPPtrList = specialize TFPGList<Pointer>;
TFPList = class(TFPPtrList)
public
procedure Assign(Source: TFPList);
procedure Sort(Compare: TListSortCompare);
procedure ForEachCall(Proc2call: TListCallback; Arg: Pointer);
procedure ForEachCall(Proc2call: TListStaticCallback; Arg: Pointer);
end;
{$endif}
{ TList class}
TListNotification = (lnAdded, lnExtracted, lnDeleted);
TList = class;
TListEnumerator = class
private
FList: TList;
FPosition: Integer;
public
constructor Create(AList: TList);
function GetCurrent: Pointer;
function MoveNext: Boolean;
property Current: Pointer read GetCurrent;
end;
TList = class(TObject,IFPObserved)
private
FList: TFPList;
FObservers : TFPList;
procedure CopyMove (aList : TList);
procedure MergeMove (aList : TList);
procedure DoCopy(ListA, ListB : TList);
procedure DoSrcUnique(ListA, ListB : TList);
procedure DoAnd(ListA, ListB : TList);
procedure DoDestUnique(ListA, ListB : TList);
procedure DoOr(ListA, ListB : TList);
procedure DoXOr(ListA, ListB : TList);
protected
function Get(Index: Integer): Pointer;
procedure Grow; virtual;
procedure Put(Index: Integer; Item: Pointer);
procedure Notify(Ptr: Pointer; Action: TListNotification); virtual;
procedure SetCapacity(NewCapacity: Integer);
function GetCapacity: integer;
procedure SetCount(NewCount: Integer);
function GetCount: integer;
function GetList: PPointerList;
public
constructor Create;
destructor Destroy; override;
Procedure FPOAttachObserver(AObserver : TObject);
Procedure FPODetachObserver(AObserver : TObject);
Procedure FPONotifyObservers(ASender : TObject; AOperation : TFPObservedOperation; Data : Pointer);
Procedure AddList(AList : TList);
function Add(Item: Pointer): Integer;
procedure Clear; virtual;
procedure Delete(Index: Integer);
class procedure Error(const Msg: string; Data: PtrInt); virtual;
procedure Exchange(Index1, Index2: Integer);
function Expand: TList;
function Extract(item: Pointer): Pointer;
function First: Pointer;
function GetEnumerator: TListEnumerator;
function IndexOf(Item: Pointer): Integer;
procedure Insert(Index: Integer; Item: Pointer);
function Last: Pointer;
procedure Move(CurIndex, NewIndex: Integer);
procedure Assign (ListA: TList; AOperator: TListAssignOp=laCopy; ListB: TList=nil);
function Remove(Item: Pointer): Integer;
procedure Pack;
procedure Sort(Compare: TListSortCompare);
property Capacity: Integer read GetCapacity write SetCapacity;
property Count: Integer read GetCount write SetCount;
property Items[Index: Integer]: Pointer read Get write Put; default;
property List: PPointerList read GetList;
end;
{ TThreadList class }
TThreadList = class
private
FList: TList;
FDuplicates: TDuplicates;
FLock: TRTLCriticalSection;
public
constructor Create;
destructor Destroy; override;
procedure Add(Item: Pointer);
procedure Clear;
function LockList: TList;
procedure Remove(Item: Pointer);
procedure UnlockList;
property Duplicates: TDuplicates read FDuplicates write FDuplicates;
end;
{TBits Class}
const
BITSHIFT = 5;
MASK = 31; {for longs that are 32-bit in size}
// to further increase, signed integer limits have to be researched.
{$ifdef cpu16}
MaxBitFlags = $7FE0;
{$else cpu16}
MaxBitFlags = $7FFFFFE0;
{$endif cpu16}
MaxBitRec = MaxBitFlags Div (SizeOf(cardinal)*8);
type
TBitArray = array[0..MaxBitRec - 1] of cardinal;
TBits = class(TObject)
private
{ Private declarations }
FBits : ^TBitArray;
FSize : longint; { total longints currently allocated }
FBSize: longint; {total bits currently allocated}
findIndex : longint;
findState : boolean;
{ functions and properties to match TBits class }
procedure SetBit(bit : longint; value : Boolean);
procedure SetSize(value : longint);
Protected
procedure CheckBitIndex (Bit : longint;CurrentSize : Boolean);
public
{ Public declarations }
constructor Create(TheSize : longint = 0); virtual;
destructor Destroy; override;
function GetFSize : longint;
procedure SetOn(Bit : longint);
procedure Clear(Bit : longint);
procedure Clearall;
procedure CopyBits(BitSet : TBits);
procedure AndBits(BitSet : TBits);
procedure OrBits(BitSet : TBits);
procedure XorBits(BitSet : TBits);
procedure NotBits(BitSet : TBits);
function Get(Bit : longint) : boolean;
procedure Grow(NBit : longint);
function Equals(Obj : TObject): Boolean; override; overload;
function Equals(BitSet : TBits) : Boolean; overload;
procedure SetIndex(Index : longint);
function FindFirstBit(State : boolean) : longint;
function FindNextBit : longint;
function FindPrevBit : longint;
{ functions and properties to match TBits class }
function OpenBit: longint;
property Bits[Bit: longint]: Boolean read get write SetBit; default;
property Size: longint read FBSize write setSize;
end;
{ TPersistent abstract class }
{$M+}
TPersistent = class(TObject,IFPObserved)
private
FObservers : TFPList;
procedure AssignError(Source: TPersistent);
protected
procedure AssignTo(Dest: TPersistent); virtual;
procedure DefineProperties(Filer: TFiler); virtual;
function GetOwner: TPersistent; dynamic;
public
Destructor Destroy; override;
procedure Assign(Source: TPersistent); virtual;
Procedure FPOAttachObserver(AObserver : TObject);
Procedure FPODetachObserver(AObserver : TObject);
Procedure FPONotifyObservers(ASender : TObject; AOperation : TFPObservedOperation; Data : Pointer);
function GetNamePath: string; virtual; {dynamic;}
end;
{$M-}
{ TPersistent class reference type }
TPersistentClass = class of TPersistent;
{ TInterfaced Persistent }
TInterfacedPersistent = class(TPersistent, IInterface)
private
FOwnerInterface: IInterface;
protected
{ IInterface }
function _AddRef: Longint; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
function _Release: Longint; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
public
function QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} IID: TGUID; out Obj): HResult; virtual; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
procedure AfterConstruction; override;
end;
{ TRecall class }
TRecall = class(TObject)
private
FStorage, FReference: TPersistent;
public
constructor Create(AStorage, AReference: TPersistent);
destructor Destroy; override;
procedure Store;
procedure Forget;
property Reference: TPersistent read FReference;
end;
{ TCollection class }
TCollection = class;
TCollectionItem = class(TPersistent)
private
FCollection: TCollection;
FID: Integer;
FUpdateCount: Integer;
function GetIndex: Integer;
protected
procedure SetCollection(Value: TCollection);virtual;
procedure Changed(AllItems: Boolean);
function GetOwner: TPersistent; override;
function GetDisplayName: string; virtual;
procedure SetIndex(Value: Integer); virtual;
procedure SetDisplayName(const Value: string); virtual;
property UpdateCount: Integer read FUpdateCount;
public
constructor Create(ACollection: TCollection); virtual;
destructor Destroy; override;
function GetNamePath: string; override;
property Collection: TCollection read FCollection write SetCollection;
property ID: Integer read FID;
property Index: Integer read GetIndex write SetIndex;
property DisplayName: string read GetDisplayName write SetDisplayName;
end;
TCollectionEnumerator = class
private
FCollection: TCollection;
FPosition: Integer;
public
constructor Create(ACollection: TCollection);
function GetCurrent: TCollectionItem;
function MoveNext: Boolean;
property Current: TCollectionItem read GetCurrent;
end;
TCollectionItemClass = class of TCollectionItem;
TCollectionNotification = (cnAdded, cnExtracting, cnDeleting);
TCollectionSortCompare = function (Item1, Item2: TCollectionItem): Integer;
TCollection = class(TPersistent)
private
FItemClass: TCollectionItemClass;
FItems: TFpList;
FUpdateCount: Integer;
FNextID: Integer;
FPropName: string;
function GetCount: Integer;
function GetPropName: string;
procedure InsertItem(Item: TCollectionItem);
procedure RemoveItem(Item: TCollectionItem);
procedure DoClear;
protected
{ Design-time editor support }
function GetAttrCount: Integer; dynamic;
function GetAttr(Index: Integer): string; dynamic;
function GetItemAttr(Index, ItemIndex: Integer): string; dynamic;
procedure Changed;
function GetItem(Index: Integer): TCollectionItem;
procedure SetItem(Index: Integer; Value: TCollectionItem);
procedure SetItemName(Item: TCollectionItem); virtual;
procedure SetPropName; virtual;
procedure Update(Item: TCollectionItem); virtual;
procedure Notify(Item: TCollectionItem;Action: TCollectionNotification); virtual;
property PropName: string read GetPropName write FPropName;
property UpdateCount: Integer read FUpdateCount;
public
constructor Create(AItemClass: TCollectionItemClass);
destructor Destroy; override;
function Owner: TPersistent;
function Add: TCollectionItem;
procedure Assign(Source: TPersistent); override;
procedure BeginUpdate; virtual;
procedure Clear;
procedure EndUpdate; virtual;
procedure Delete(Index: Integer);
function GetEnumerator: TCollectionEnumerator;
function GetNamePath: string; override;
function Insert(Index: Integer): TCollectionItem;
function FindItemID(ID: Integer): TCollectionItem;
procedure Exchange(Const Index1, index2: integer);
procedure Move(Const Index1, index2: integer);
procedure Sort(Const Compare : TCollectionSortCompare);
property Count: Integer read GetCount;
property ItemClass: TCollectionItemClass read FItemClass;
property Items[Index: Integer]: TCollectionItem read GetItem write SetItem;
end;
TOwnedCollection = class(TCollection)
private
FOwner: TPersistent;
protected
Function GetOwner: TPersistent; override;
public
Constructor Create(AOwner: TPersistent;AItemClass: TCollectionItemClass);
end;
TStrings = class;
{ IStringsAdapter interface }
{ Maintains link between TStrings and IStrings implementations }
IStringsAdapter = interface ['{739C2F34-52EC-11D0-9EA6-0020AF3D82DA}']
procedure ReferenceStrings(S: TStrings);
procedure ReleaseStrings;
end;
{ TStringsEnumerator class }
TStringsEnumerator = class
private
FStrings: TStrings;
FPosition: Integer;
public
constructor Create(AStrings: TStrings);
function GetCurrent: String;
function MoveNext: Boolean;
property Current: String read GetCurrent;
end;
{ TStrings class }
TStringsFilterMethod = function(const s: string): boolean of object;
TStringsReduceMethod = function(const s1, s2: string): string of object;
TStringsMapMethod = function(const s: string): string of object;
TStringsForEachMethodExObj = procedure(const CurrentValue: string; const index: integer; Obj : TObject) of object;
TStringsForEachMethodEx = procedure(const CurrentValue: string; const index: integer) of object;
TStringsForEachMethod = procedure(const CurrentValue: string) of object;
TMissingNameValueSeparatorAction = (mnvaValue,mnvaName,mnvaEmpty,mnvaError);
TMissingNameValueSeparatorActions = set of TMissingNameValueSeparatorAction;
TStringsOption = (soStrictDelimiter,soWriteBOM,soTrailingLineBreak,soUseLocale,soPreserveBOM);
TStringsOptions = set of TStringsOption;
TStrings = class(TPersistent)
private
FDefaultEncoding: TEncoding;
FEncoding: TEncoding;
FMissingNameValueSeparatorAction: TMissingNameValueSeparatorAction;
FSpecialCharsInited : boolean;
FAlwaysQuote: Boolean;
FQuoteChar : Char;
FDelimiter : Char;
FNameValueSeparator : Char;
FUpdateCount: Integer;
FAdapter: IStringsAdapter;
FLBS : TTextLineBreakStyle;
FOptions : TStringsOptions;
FLineBreak : String;
function GetCommaText: string;
function GetLineBreakCharLBS: string;
function GetMissingNameValueSeparatorAction: TMissingNameValueSeparatorAction;
function GetName(Index: Integer): string;
function GetStrictDelimiter: Boolean;
function GetTrailingLineBreak: Boolean;
function GetUseLocale: Boolean;
function GetValue(const Name: string): string;
function GetWriteBOM: Boolean;
Function GetLBS : TTextLineBreakStyle;
procedure SetDefaultEncoding(const ADefaultEncoding: TEncoding);
procedure SetEncoding(const AEncoding: TEncoding);
Procedure SetLBS (AValue : TTextLineBreakStyle);
procedure ReadData(Reader: TReader);
procedure SetCommaText(const Value: string);
procedure SetMissingNameValueSeparatorAction(AValue: TMissingNameValueSeparatorAction);
procedure SetStringsAdapter(const Value: IStringsAdapter);
procedure SetStrictDelimiter(AValue: Boolean);
procedure SetTrailingLineBreak(AValue: Boolean);
procedure SetUseLocale(AValue: Boolean);
procedure SetWriteBOM(AValue: Boolean);
procedure SetValue(const Name, Value: string);
procedure SetDelimiter(c:Char);
procedure SetQuoteChar(c:Char);
procedure SetNameValueSeparator(c:Char);
procedure WriteData(Writer: TWriter);
procedure DoSetTextStr(const Value: string; DoClear : Boolean);
Function GetDelimiter : Char;
Function GetNameValueSeparator : Char;
Function GetQuoteChar: Char;
Function GetLineBreak : String;
procedure SetLineBreak(const S : String);
Function GetSkipLastLineBreak : Boolean;
procedure SetSkipLastLineBreak(const AValue : Boolean);
Procedure DoSetDelimitedText(const AValue: string; DoClear,aStrictDelimiter : Boolean; aQuoteChar,aDelimiter : Char);
protected
function CompareStrings(const s1,s2 : string) : Integer; virtual;
procedure DefineProperties(Filer: TFiler); override;
procedure Error(const Msg: string; Data: Integer);
procedure Error(const Msg: pstring; Data: Integer);
function Get(Index: Integer): string; virtual; abstract;
function GetCapacity: Integer; virtual;
function GetCount: Integer; virtual; abstract;
function GetObject(Index: Integer): TObject; virtual;
function GetTextStr: string; virtual;
procedure Put(Index: Integer; const S: string); virtual;
procedure PutObject(Index: Integer; AObject: TObject); virtual;
procedure SetCapacity(NewCapacity: Integer); virtual;
procedure SetTextStr(const Value: string); virtual;
procedure SetUpdateState(Updating: Boolean); virtual;
property UpdateCount: Integer read FUpdateCount;
Function DoCompareText(const s1,s2 : string) : PtrInt; virtual;
Function GetDelimitedText: string;
Procedure SetDelimitedText(Const AValue: string);
Function GetValueFromIndex(Index: Integer): string;
Procedure SetValueFromIndex(Index: Integer; const Value: string);
Procedure CheckSpecialChars;
Class Function GetNextLine (Const Value : String; Var S : String; Var P : SizeInt) : Boolean;
Function GetNextLinebreak (Const Value : String; Var S : String; Var P : SizeInt) : Boolean;
{$IF (SizeOf(Integer) < SizeOf(SizeInt)) }
class function GetNextLine(const Value: string; var S: string; var P: Integer) : Boolean; deprecated;
function GetNextLineBreak(const Value: string; var S: string; var P: Integer) : Boolean; deprecated;
{$IFEND}
public
constructor Create;
destructor Destroy; override;
function ToObjectArray(aStart,aEnd : Integer) : TObjectDynArray; overload;
function ToObjectArray: TObjectDynArray; overload;
function ToStringArray(aStart,aEnd : Integer) : TStringDynArray; overload;
function ToStringArray: TStringDynArray; overload;
function Add(const S: string): Integer; virtual; overload;
function AddObject(const S: string; AObject: TObject): Integer; virtual; overload;
function Add(const Fmt : string; const Args : Array of const): Integer; overload;
function AddObject(const Fmt: string; Args : Array of const; AObject: TObject): Integer; overload;
function AddPair(const AName, AValue: string): TStrings; overload; {$IFDEF CLASSESINLINE}inline;{$ENDIF}
function AddPair(const AName, AValue: string; AObject: TObject): TStrings; overload;
procedure AddStrings(TheStrings: TStrings); overload; virtual;
procedure AddStrings(TheStrings: TStrings; ClearFirst : Boolean); overload;
procedure AddStrings(const TheStrings: array of string); overload; virtual;
procedure AddStrings(const TheStrings: array of string; ClearFirst : Boolean); overload;
procedure SetStrings(TheStrings: TStrings); overload; virtual;
procedure SetStrings(TheStrings: array of string); overload; virtual;
Procedure AddText(Const S : String); virtual;
procedure AddCommaText(const S: String);
procedure AddDelimitedText(const S: String; ADelimiter: char; AStrictDelimiter: Boolean); overload;
procedure AddDelimitedtext(const S: String); overload;
procedure Append(const S: string);
procedure Assign(Source: TPersistent); override;
procedure BeginUpdate;
procedure Clear; virtual; abstract;
procedure Delete(Index: Integer); virtual; abstract;
procedure EndUpdate;
function Equals(Obj: TObject): Boolean; override; overload;
function Equals(TheStrings: TStrings): Boolean; overload;
procedure Exchange(Index1, Index2: Integer); virtual;
function ExtractName(Const S:String):String;
Procedure Filter(aFilter: TStringsFilterMethod; aList : TStrings);
Function Filter(aFilter: TStringsFilterMethod) : TStrings;
Procedure Fill(const aValue : String; aStart,aEnd : Integer);
procedure ForEach(aCallback: TStringsForeachMethod);
procedure ForEach(aCallback: TStringsForeachMethodEx);
procedure ForEach(aCallback: TStringsForeachMethodExObj);
function GetEnumerator: TStringsEnumerator;
procedure GetNameValue(Index : Integer; Out AName,AValue : String);
function GetText: PChar; virtual;
function IndexOf(const S: string): Integer; virtual;
function IndexOf(const S: string; aStart : Integer): Integer; virtual;
function IndexOfName(const Name: string): Integer; virtual;
function IndexOfObject(AObject: TObject): Integer; virtual;
procedure Insert(Index: Integer; const S: string); virtual; abstract;
procedure InsertObject(Index: Integer; const S: string; AObject: TObject);
function LastIndexOf(const S: string; aStart : Integer): Integer; virtual;
function LastIndexOf(const S: string): Integer;
procedure LoadFromFile(const FileName: string); overload; virtual;
procedure LoadFromFile(const FileName: string; IgnoreEncoding : Boolean);
procedure LoadFromFile(const FileName: string; AEncoding: TEncoding); overload; virtual;
procedure LoadFromStream(Stream: TStream); overload; virtual;
procedure LoadFromStream(Stream: TStream; IgnoreEncoding : Boolean); overload;
procedure LoadFromStream(Stream: TStream; AEncoding: TEncoding); overload; virtual;
Procedure Map(aMap: TStringsMapMethod; aList : TStrings);
Function Map(aMap: TStringsMapMethod) : TStrings;
procedure Move(CurIndex, NewIndex: Integer); virtual;
Function Pop : String;
function Reduce(aReduceMethod: TStringsReduceMethod; const startingValue: string): string;
Function Reverse : TStrings;
Procedure Reverse(aList : TStrings);
procedure SaveToFile(const FileName: string); overload; virtual;
procedure SaveToFile(const FileName: string; IgnoreEncoding : Boolean); overload;
procedure SaveToFile(const FileName: string; AEncoding: TEncoding); overload; virtual;
procedure SaveToStream(Stream: TStream); overload; virtual;
procedure SaveToStream(Stream: TStream; IgnoreEncoding : Boolean); overload;
procedure SaveToStream(Stream: TStream; AEncoding: TEncoding); overload; virtual;
function Shift : String;
Procedure Slice(fromIndex: integer; aList : TStrings);
Function Slice(fromIndex: integer) : TStrings;
procedure SetText(TheText: PChar); virtual;
property AlwaysQuote: Boolean read FAlwaysQuote write FAlwaysQuote;
property Capacity: Integer read GetCapacity write SetCapacity;
property CommaText: string read GetCommaText write SetCommaText;
property Count: Integer read GetCount;
property DefaultEncoding: TEncoding read FDefaultEncoding write SetDefaultEncoding;
property DelimitedText: string read GetDelimitedText write SetDelimitedText;
property Delimiter: Char read GetDelimiter write SetDelimiter;
property Encoding: TEncoding read FEncoding;
property LineBreak : string Read GetLineBreak write SetLineBreak;
Property MissingNameValueSeparatorAction : TMissingNameValueSeparatorAction Read GetMissingNameValueSeparatorAction Write SetMissingNameValueSeparatorAction;
property Names[Index: Integer]: string read GetName;
Property NameValueSeparator : Char Read GetNameValueSeparator Write SetNameValueSeparator;
property Objects[Index: Integer]: TObject read GetObject write PutObject;
property Options: TStringsOptions read FOptions write FOptions;
property QuoteChar: Char read GetQuoteChar write SetQuoteChar;
Property SkipLastLineBreak : Boolean Read GetSkipLastLineBreak Write SetSkipLastLineBreak;
// Same as SkipLastLineBreak but for Delphi compatibility. Note it has opposite meaning.
Property TrailingLineBreak : Boolean Read GetTrailingLineBreak Write SetTrailingLineBreak;
Property StrictDelimiter : Boolean Read GetStrictDelimiter Write SetStrictDelimiter;
property Strings[Index: Integer]: string read Get write Put; default;
property StringsAdapter: IStringsAdapter read FAdapter write SetStringsAdapter;
property Text: string read GetTextStr write SetTextStr;
Property TextLineBreakStyle : TTextLineBreakStyle Read GetLBS Write SetLBS;
Property UseLocale : Boolean Read GetUseLocale Write SetUseLocale;
property ValueFromIndex[Index: Integer]: string read GetValueFromIndex write SetValueFromIndex;
property Values[const Name: string]: string read GetValue write SetValue;
property WriteBOM: Boolean read GetWriteBOM write SetWriteBOM;
end;
TStringsClass = Class of TStrings;
{ TStringList class }
TStringList = class;
TStringListSortCompare = function(List: TStringList; Index1, Index2: Integer): Integer;
{$IFNDEF FPC_TESTGENERICS}
PStringItem = ^TStringItem;
TStringItem = record
FString: string;
FObject: TObject;
end;
PStringItemList = ^TStringItemList;
TStringItemList = array[0..MaxListSize] of TStringItem;
TStringsSortStyle = (sslNone,sslUser,sslAuto);
TStringsSortStyles = Set of TStringsSortStyle;
TStringList = class(TStrings)
private
FList: PStringItemList;
FCount: Integer;
FCapacity: Integer;
FOnChange: TNotifyEvent;
FOnChanging: TNotifyEvent;
FDuplicates: TDuplicates;
FCaseSensitive : Boolean;
FForceSort : Boolean;
FOwnsObjects : Boolean;
FSortStyle: TStringsSortStyle;
procedure ExchangeItemsInt(Index1, Index2: Integer); inline;
function GetSorted: Boolean;
procedure Grow;
procedure InternalClear(FromIndex : Integer = 0; ClearOnly : Boolean = False);
procedure QuickSort(L, R: Integer; CompareFn: TStringListSortCompare);
procedure SetSorted(Value: Boolean);
procedure SetCaseSensitive(b : boolean);
procedure SetSortStyle(AValue: TStringsSortStyle);
protected
Procedure CheckIndex(AIndex : Integer); inline;
procedure ExchangeItems(Index1, Index2: Integer); virtual;
procedure Changed; virtual;
procedure Changing; virtual;
function Get(Index: Integer): string; override;
function GetCapacity: Integer; override;
function GetCount: Integer; override;
function GetObject(Index: Integer): TObject; override;
procedure Put(Index: Integer; const S: string); override;
procedure PutObject(Index: Integer; AObject: TObject); override;
procedure SetCapacity(NewCapacity: Integer); override;
procedure SetUpdateState(Updating: Boolean); override;
procedure InsertItem(Index: Integer; const S: string); virtual;
procedure InsertItem(Index: Integer; const S: string; O: TObject); virtual;
Function DoCompareText(const s1,s2 : string) : PtrInt; override;
public
destructor Destroy; override;
function Add(const S: string): Integer; override;
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Exchange(Index1, Index2: Integer); override;
function Find(const S: string; Out Index: Integer): Boolean; virtual;
function IndexOf(const S: string): Integer; override;
procedure Insert(Index: Integer; const S: string); override;
procedure Sort; virtual;
procedure CustomSort(CompareFn: TStringListSortCompare); virtual;
property Duplicates: TDuplicates read FDuplicates write FDuplicates;
property Sorted: Boolean read GetSorted write SetSorted;
property CaseSensitive: Boolean read FCaseSensitive write SetCaseSensitive;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChanging: TNotifyEvent read FOnChanging write FOnChanging;
property OwnsObjects : boolean read FOwnsObjects write FOwnsObjects;
Property SortStyle : TStringsSortStyle Read FSortStyle Write SetSortStyle;
end;
{$else}
TFPStrObjMap = specialize TFPGMap<string, TObject>;
TStringListTextCompare = function(const s1, s2: string): PtrInt of object;
TStringList = class(TStrings)
private
FMap: TFPStrObjMap;
FCaseSensitive: Boolean;
FOnChange: TNotifyEvent;
FOnChanging: TNotifyEvent;
FOnCompareText: TStringListTextCompare;
FOwnsObjects : Boolean;
procedure SetCaseSensitive(NewSensitive: Boolean);
protected
procedure Changed; virtual;
procedure Changing; virtual;
function DefaultCompareText(const s1, s2: string): PtrInt;
function DoCompareText(const s1, s2: string): PtrInt; override;
function Get(Index: Integer): string; override;
function GetCapacity: Integer; override;
function GetDuplicates: TDuplicates;
function GetCount: Integer; override;
function GetObject(Index: Integer): TObject; override;
function GetSorted: Boolean; {$ifdef CLASSESINLINE} inline; {$endif}
function MapPtrCompare(Key1, Key2: Pointer): Integer;
procedure Put(Index: Integer; const S: string); override;
procedure PutObject(Index: Integer; AObject: TObject); override;
procedure QuickSort(L, R: Integer; CompareFn: TStringListSortCompare);
procedure SetCapacity(NewCapacity: Integer); override;
procedure SetDuplicates(NewDuplicates: TDuplicates);
procedure SetSorted(NewSorted: Boolean); {$ifdef CLASSESINLINE} inline; {$endif}
procedure SetUpdateState(Updating: Boolean); override;
public
constructor Create;
destructor Destroy; override;
function Add(const S: string): Integer; override;
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Exchange(Index1, Index2: Integer); override;
function Find(const S: string; var Index: Integer): Boolean; virtual;
function IndexOf(const S: string): Integer; override;
procedure Insert(Index: Integer; const S: string); override;
procedure Sort; virtual;
procedure CustomSort(CompareFn: TStringListSortCompare);
property Duplicates: TDuplicates read GetDuplicates write SetDuplicates;
property Sorted: Boolean read GetSorted write SetSorted;
property CaseSensitive: Boolean read FCaseSensitive write SetCaseSensitive;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChanging: TNotifyEvent read FOnChanging write FOnChanging;
property OnCompareText: TStringListTextCompare read FOnCompareText write FOnCompareText;
property OwnsObjects : boolean read FOwnsObjects write FOwnsObjects;
end;
{$endif}
{ TStream abstract class }
TStream = class(TObject)
private
protected
procedure InvalidSeek; virtual;
procedure Discard(const Count: Int64);
procedure DiscardLarge(Count: int64; const MaxBufferSize: Longint);
procedure FakeSeekForward(Offset: Int64; const Origin: TSeekOrigin; const Pos: Int64);
function GetPosition: Int64; virtual;
procedure SetPosition(const Pos: Int64); virtual;
function GetSize: Int64; virtual;
procedure SetSize64(const NewSize: Int64); virtual;
procedure SetSize(NewSize: Longint); virtual;overload;
procedure SetSize(const NewSize: Int64); virtual;overload;
procedure ReadNotImplemented;
procedure WriteNotImplemented;
public
function Read(var Buffer; Count: Longint): Longint; virtual; overload;
function Write(const Buffer; Count: Longint): Longint; virtual; overload;
function Seek(Offset: Longint; Origin: Word): Longint; virtual; overload;
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; virtual; overload;
procedure ReadBuffer(var Buffer; Count: Longint);
procedure WriteBuffer(const Buffer; Count: Longint);
function CopyFrom(Source: TStream; Count: Int64): Int64;
function ReadComponent(Instance: TComponent): TComponent;
function ReadComponentRes(Instance: TComponent): TComponent;
procedure WriteComponent(Instance: TComponent);
procedure WriteComponentRes(const ResName: string; Instance: TComponent);
procedure WriteDescendent(Instance, Ancestor: TComponent);
procedure WriteDescendentRes(const ResName: string; Instance, Ancestor: TComponent);
procedure WriteResourceHeader(const ResName: string; {!!!:out} var FixupInfo: Longint);
procedure FixupResourceHeader(FixupInfo: Longint);
procedure ReadResHeader;
function ReadByte : Byte;
function ReadWord : Word;
function ReadDWord : Cardinal;
function ReadQWord : QWord;
function ReadAnsiString : String;
procedure WriteByte(b : Byte);
procedure WriteWord(w : Word);
procedure WriteDWord(d : Cardinal);
procedure WriteQWord(q : QWord);
Procedure WriteAnsiString (const S : String); virtual;
property Position: Int64 read GetPosition write SetPosition;
property Size: Int64 read GetSize write SetSize64;
end;
TProxyStream = class(TStream)
private
FStream: IStream;
protected
function GetIStream: IStream;
public
constructor Create(const Stream: IStream);
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
function Seek(const Offset: int64; Origin: TSeekOrigin): int64; override;
procedure Check(err:integer); virtual;
end;
{ TOwnerStream }
TOwnerStream = Class(TStream)
Protected
FOwner : Boolean;
FSource : TStream;
Public
Constructor Create(ASource : TStream);
Destructor Destroy; override;
Property Source : TStream Read FSource;
Property SourceOwner : Boolean Read Fowner Write FOwner;
end;
IStreamPersist = interface ['{B8CD12A3-267A-11D4-83DA-00C04F60B2DD}']
procedure LoadFromStream(Stream: TStream);
procedure SaveToStream(Stream: TStream);
end;
{ THandleStream class }
THandleStream = class(TStream)
private
FHandle: THandle;
protected
procedure SetSize(NewSize: Longint); override;
procedure SetSize(const NewSize: Int64); override;
public
constructor Create(AHandle: THandle);
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;
property Handle: THandle read FHandle;
end;
{ TFileStream class }
TFileStream = class(THandleStream)
Private
FFileName : String;
public
constructor Create(const AFileName: string; Mode: Word);
constructor Create(const AFileName: string; Mode: Word; Rights: Cardinal);
destructor Destroy; override;
property FileName : String Read FFilename;
end;
{ TCustomMemoryStream abstract class }
TCustomMemoryStream = class(TStream)
private
FMemory: Pointer;
FSize, FPosition: PtrInt;
protected
Function GetSize : Int64; Override;
function GetPosition: Int64; Override;
procedure SetPointer(Ptr: Pointer; ASize: PtrInt);
public
function Read(var Buffer; Count: LongInt): LongInt; override;
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;
procedure SaveToStream(Stream: TStream);
procedure SaveToFile(const FileName: string);
property Memory: Pointer read FMemory;
end;
{ TMemoryStream }
TMemoryStream = class(TCustomMemoryStream)
private
FCapacity: PtrInt;
procedure SetCapacity(NewCapacity: PtrInt);
protected
function Realloc(var NewCapacity: PtrInt): Pointer; virtual;
property Capacity: PtrInt read FCapacity write SetCapacity;
public
destructor Destroy; override;
procedure Clear;
procedure LoadFromStream(Stream: TStream);
procedure LoadFromFile(const FileName: string);
procedure SetSize({$ifdef CPU64}const NewSize: Int64{$else}NewSize: LongInt{$endif}); override;
function Write(const Buffer; Count: LongInt): LongInt; override;
end;
{ TBytesStream }
TBytesStream = class(TMemoryStream)
private
FBytes: TBytes;
protected
function Realloc(var NewCapacity: PtrInt): Pointer; override;
public
constructor Create(const ABytes: TBytes); virtual; overload;
property Bytes: TBytes read FBytes;
end;
{ TStringStream }
TStringStream = class(TBytesStream)
private
FEncoding: TEncoding;
FOwnsEncoding : Boolean;
function GetDataString: string;
function GetUnicodeDataString: UnicodeString;
protected
public
constructor Create(const ABytes: TBytes); override; overload;
constructor Create(const AString: string = ''); overload;
constructor CreateRaw(const AString: RawByteString); overload;
constructor Create(const AString: string; AEncoding: TEncoding; AOwnsEncoding: Boolean = True); overload;
constructor Create(const AString: string; ACodePage: Integer); overload;
// UnicodeString versions
constructor Create(const AString: UnicodeString); overload;
constructor Create(const AString: UnicodeString; AEncoding: TEncoding; AOwnsEncoding: Boolean = True); overload;
constructor Create(const AString: UnicodeString; ACodePage: Integer); overload;
Destructor Destroy; override;
function ReadUnicodeString(Count: Longint): UnicodeString;
procedure WriteUnicodeString(const AString: UnicodeString);
function ReadAnsiString(Count: Longint): AnsiString; overload;
procedure WriteAnsiString(const AString: AnsiString); override;
function ReadString(Count: Longint): string;
procedure WriteString(const AString: string);
property DataString: string read GetDataString;
Property UnicodeDataString : UnicodeString Read GetUnicodeDataString;
Property OwnsEncoding : Boolean Read FOwnsEncoding;
Property Encoding : TEncoding Read FEncoding;
end;
{ TRawByteStringStream }
TRawByteStringStream = Class(TBytesStream)
public
Constructor Create (const aData : RawByteString); overload;
function DataString: RawByteString;
function ReadString(Count: Longint): RawByteString;
procedure WriteString(const AString: RawByteString);
end;
{ TResourceStream }
{$ifdef FPC_OS_UNICODE}
TResourceStream = class(TCustomMemoryStream)
private
Res: TFPResourceHandle;
Handle: TFPResourceHGLOBAL;
procedure Initialize(Instance: TFPResourceHMODULE; Name, ResType: PWideChar; NameIsID: Boolean);
public
constructor Create(Instance: TFPResourceHMODULE; const ResName: WideString; ResType: PWideChar);
constructor CreateFromID(Instance: TFPResourceHMODULE; ResID: Integer; ResType: PWideChar);
destructor Destroy; override;
end;
{$else}
TResourceStream = class(TCustomMemoryStream)
private
Res: TFPResourceHandle;
Handle: TFPResourceHGLOBAL;
procedure Initialize(Instance: TFPResourceHMODULE; Name, ResType: PChar; NameIsID: Boolean);
public
constructor Create(Instance: TFPResourceHMODULE; const ResName: string; ResType: PChar);
constructor CreateFromID(Instance: TFPResourceHMODULE; ResID: Integer; ResType: PChar);
destructor Destroy; override;
end;
{$endif FPC_OS_UNICODE}
{ TStreamAdapter }
TStreamOwnership = (soReference, soOwned);
{ Implements OLE IStream on TStream }
TStreamAdapter = class(TInterfacedObject, IStream)
private
FStream : TStream;
FOwnership : TStreamOwnership;
m_bReverted: Boolean;
public
constructor Create(Stream: TStream; Ownership: TStreamOwnership = soReference);
destructor Destroy; override;
function Read(pv: Pointer; cb: DWORD; pcbRead: PDWORD): HResult; virtual; stdcall;
function Write(pv: Pointer; cb: DWORD; pcbWritten: PDWORD): HResult; virtual; stdcall;
function Seek(dlibMove: LargeInt; dwOrigin: DWORD; out libNewPosition: LargeUint): HResult; virtual; stdcall;
function SetSize(libNewSize: LargeUint): HResult; virtual; stdcall;
function CopyTo(stm: IStream; cb: LargeUint; out cbRead: LargeUint; out cbWritten: LargeUint): HResult; virtual; stdcall;
function Commit(grfCommitFlags: DWORD): HResult; virtual; stdcall;
function Revert: HResult; virtual; stdcall;
function LockRegion(libOffset: LargeUint; cb: LargeUint; dwLockType: DWORD): HResult; virtual; stdcall;
function UnlockRegion(libOffset: LargeUint; cb: LargeUint; dwLockType: DWORD): HResult; virtual; stdcall;
function Stat(out statstg: TStatStg; grfStatFlag: DWORD): HResult; virtual; stdcall;
function Clone(out stm: IStream): HResult; virtual; stdcall;
property Stream: TStream read FStream;
property StreamOwnership: TStreamOwnership read FOwnership write FOwnership;
end;
{ TFiler }
TValueType = (vaNull, vaList, vaInt8, vaInt16, vaInt32, vaExtended,
vaString, vaIdent, vaFalse, vaTrue, vaBinary, vaSet, vaLString,
vaNil, vaCollection, vaSingle, vaCurrency, vaDate, vaWString, vaInt64,
vaUTF8String, vaUString, vaQWord);
TFilerFlag = (ffInherited, ffChildPos, ffInline);
TFilerFlags = set of TFilerFlag;
TReaderProc = procedure(Reader: TReader) of object;
TWriterProc = procedure(Writer: TWriter) of object;
TStreamProc = procedure(Stream: TStream) of object;
TFiler = class(TObject)
private
FRoot: TComponent;
FLookupRoot: TComponent;
FAncestor: TPersistent;
FIgnoreChildren: Boolean;
protected
procedure SetRoot(ARoot: TComponent); virtual;
public
procedure DefineProperty(const Name: string;
ReadData: TReaderProc; WriteData: TWriterProc;
HasData: Boolean); virtual; abstract;
procedure DefineBinaryProperty(const Name: string;
ReadData, WriteData: TStreamProc;
HasData: Boolean); virtual; abstract;
Procedure FlushBuffer; virtual; abstract;
property Root: TComponent read FRoot write SetRoot;
property LookupRoot: TComponent read FLookupRoot;
property Ancestor: TPersistent read FAncestor write FAncestor;
property IgnoreChildren: Boolean read FIgnoreChildren write FIgnoreChildren;
end;
{ TComponent class reference type }
TComponentClass = class of TComponent;
{ TReader }
{ TAbstractObjectReader }
TAbstractObjectReader = class
public
Procedure FlushBuffer; virtual;
function NextValue: TValueType; virtual; abstract;
function ReadValue: TValueType; virtual; abstract;
procedure BeginRootComponent; virtual; abstract;
procedure BeginComponent(var Flags: TFilerFlags; var AChildPos: Integer;
var CompClassName, CompName: String); virtual; abstract;
function BeginProperty: String; virtual; abstract;
//Please don't use read, better use ReadBinary whenever possible
procedure Read(var Buf; Count: LongInt); virtual; abstract;
{ All ReadXXX methods are called _after_ the value type has been read! }
procedure ReadBinary(const DestData: TMemoryStream); virtual; abstract;
{$ifndef FPUNONE}
function ReadFloat: Extended; virtual; abstract;
function ReadSingle: Single; virtual; abstract;
function ReadDate: TDateTime; virtual; abstract;
{$endif}
function ReadCurrency: Currency; virtual; abstract;
function ReadIdent(ValueType: TValueType): String; virtual; abstract;
function ReadInt8: ShortInt; virtual; abstract;
function ReadInt16: SmallInt; virtual; abstract;
function ReadInt32: LongInt; virtual; abstract;
function ReadInt64: Int64; virtual; abstract;
function ReadSet(EnumType: Pointer): Integer; virtual; abstract;
procedure ReadSignature; virtual; abstract;
function ReadStr: String; virtual; abstract;
function ReadString(StringType: TValueType): String; virtual; abstract;
function ReadWideString: WideString;virtual;abstract;
function ReadUnicodeString: UnicodeString;virtual;abstract;
procedure SkipComponent(SkipComponentInfos: Boolean); virtual; abstract;
procedure SkipValue; virtual; abstract;
end;
{ TBinaryObjectReader }
TBinaryObjectReader = class(TAbstractObjectReader)
protected
FStream: TStream;
FBuffer: Pointer;
FBufSize: Integer;
FBufPos: Integer;
FBufEnd: Integer;
function ReadWord : word; {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
function ReadDWord : longword; {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
function ReadQWord : qword; {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
{$ifndef FPUNONE}
function ReadExtended : extended; {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
{$endif}
procedure SkipProperty;
procedure SkipSetBody;
public
constructor Create(Stream: TStream; BufSize: Integer);
destructor Destroy; override;
function NextValue: TValueType; override;
function ReadValue: TValueType; override;
procedure BeginRootComponent; override;
procedure BeginComponent(var Flags: TFilerFlags; var AChildPos: Integer;
var CompClassName, CompName: String); override;
function BeginProperty: String; override;
//Please don't use read, better use ReadBinary whenever possible
procedure Read(var Buf; Count: LongInt); override;
procedure ReadBinary(const DestData: TMemoryStream); override;
{$ifndef FPUNONE}
function ReadFloat: Extended; override;
function ReadSingle: Single; override;
function ReadDate: TDateTime; override;
{$endif}
function ReadCurrency: Currency; override;
function ReadIdent(ValueType: TValueType): String; override;
function ReadInt8: ShortInt; override;
function ReadInt16: SmallInt; override;
function ReadInt32: LongInt; override;
function ReadInt64: Int64; override;
function ReadSet(EnumType: Pointer): Integer; override;
procedure ReadSignature; override;
function ReadStr: String; override;
function ReadString(StringType: TValueType): String; override;
function ReadWideString: WideString;override;
function ReadUnicodeString: UnicodeString;override;
procedure SkipComponent(SkipComponentInfos: Boolean); override;
procedure SkipValue; override;
end;
TFindMethodEvent = procedure(Reader: TReader; const MethodName: string;
var Address: CodePointer; var Error: Boolean) of object;
TSetMethodPropertyEvent = procedure(Reader: TReader; Instance: TPersistent;
PropInfo: PPropInfo; const TheMethodName: string;
var Handled: boolean) of object;
TSetNameEvent = procedure(Reader: TReader; Component: TComponent;
var Name: string) of object;
TReferenceNameEvent = procedure(Reader: TReader; var Name: string) of object;
TAncestorNotFoundEvent = procedure(Reader: TReader; const ComponentName: string;
ComponentClass: TPersistentClass; var Component: TComponent) of object;
TReadComponentsProc = procedure(Component: TComponent) of object;
TReaderError = procedure(Reader: TReader; const Message: string;
var Handled: Boolean) of object;
TPropertyNotFoundEvent = procedure(Reader: TReader; Instance: TPersistent;
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean) of object;
TFindComponentClassEvent = procedure(Reader: TReader; const ClassName: string;
var ComponentClass: TComponentClass) of object;
TCreateComponentEvent = procedure(Reader: TReader;
ComponentClass: TComponentClass; var Component: TComponent) of object;
TReadWriteStringPropertyEvent = procedure(Sender:TObject;
const Instance: TPersistent; PropInfo: PPropInfo;
var Content:string) of object;
{ TReader }
TReader = class(TFiler)
private
FDriver: TAbstractObjectReader;
FOwner: TComponent;
FParent: TComponent;
FFixups: TObject;
FLoaded: TFpList;
FLock: TRTLCriticalSection;
FOnFindMethod: TFindMethodEvent;
FOnSetMethodProperty: TSetMethodPropertyEvent;
FOnSetName: TSetNameEvent;
FOnReferenceName: TReferenceNameEvent;
FOnAncestorNotFound: TAncestorNotFoundEvent;
FOnError: TReaderError;
FOnPropertyNotFound: TPropertyNotFoundEvent;
FOnFindComponentClass: TFindComponentClassEvent;
FOnCreateComponent: TCreateComponentEvent;
FPropName: string;
FCanHandleExcepts: Boolean;
FOnReadStringProperty:TReadWriteStringPropertyEvent;
procedure DoFixupReferences;
function FindComponentClass(const AClassName: string): TComponentClass;
procedure Lock;
procedure Unlock;
protected
function Error(const Message: string): Boolean; virtual;
function FindMethod(ARoot: TComponent; const AMethodName: string): CodePointer; virtual;
procedure ReadProperty(AInstance: TPersistent);
procedure ReadPropValue(Instance: TPersistent; PropInfo: Pointer);
procedure PropertyError;
procedure ReadData(Instance: TComponent);
property PropName: string read FPropName;
property CanHandleExceptions: Boolean read FCanHandleExcepts;
function CreateDriver(Stream: TStream; BufSize: Integer): TAbstractObjectReader; virtual;
public
constructor Create(Stream: TStream; BufSize: Integer);
destructor Destroy; override;
Procedure FlushBuffer; override;
procedure BeginReferences;
procedure CheckValue(Value: TValueType);
procedure DefineProperty(const Name: string;
AReadData: TReaderProc; WriteData: TWriterProc;
HasData: Boolean); override;
procedure DefineBinaryProperty(const Name: string;
AReadData, WriteData: TStreamProc;
HasData: Boolean); override;
function EndOfList: Boolean;
procedure EndReferences;
procedure FixupReferences;
function NextValue: TValueType;
//Please don't use read, better use ReadBinary whenever possible
//uuups, ReadBinary is protected ..
procedure Read(var Buf; Count: LongInt); virtual;
function ReadBoolean: Boolean;
function ReadChar: Char;
function ReadWideChar: WideChar;
function ReadUnicodeChar: UnicodeChar;
procedure ReadCollection(Collection: TCollection);
function ReadComponent(Component: TComponent): TComponent;
procedure ReadComponents(AOwner, AParent: TComponent;
Proc: TReadComponentsProc);
{$ifndef FPUNONE}
function ReadFloat: Extended;
function ReadSingle: Single;
function ReadDate: TDateTime;
{$endif}
function ReadCurrency: Currency;
function ReadIdent: string;
function ReadInteger: Longint;
function ReadInt64: Int64;
function ReadSet(EnumType: Pointer): Integer;
procedure ReadListBegin;
procedure ReadListEnd;
function ReadRootComponent(ARoot: TComponent): TComponent;
function ReadVariant: Variant;
procedure ReadSignature;
function ReadString: string;
function ReadWideString: WideString;
function ReadUnicodeString: UnicodeString;
function ReadValue: TValueType;
procedure CopyValue(Writer: TWriter);
property Driver: TAbstractObjectReader read FDriver;
property Owner: TComponent read FOwner write FOwner;
property Parent: TComponent read FParent write FParent;
property OnError: TReaderError read FOnError write FOnError;
property OnPropertyNotFound: TPropertyNotFoundEvent read FOnPropertyNotFound write FOnPropertyNotFound;
property OnFindMethod: TFindMethodEvent read FOnFindMethod write FOnFindMethod;
property OnSetMethodProperty: TSetMethodPropertyEvent read FOnSetMethodProperty write FOnSetMethodProperty;
property OnSetName: TSetNameEvent read FOnSetName write FOnSetName;
property OnReferenceName: TReferenceNameEvent read FOnReferenceName write FOnReferenceName;
property OnAncestorNotFound: TAncestorNotFoundEvent read FOnAncestorNotFound write FOnAncestorNotFound;
property OnCreateComponent: TCreateComponentEvent read FOnCreateComponent write FOnCreateComponent;
property OnFindComponentClass: TFindComponentClassEvent read FOnFindComponentClass write FOnFindComponentClass;
property OnReadStringProperty: TReadWriteStringPropertyEvent read FOnReadStringProperty write FOnReadStringProperty;
end;
{ TWriter }
{ TAbstractObjectWriter }
TAbstractObjectWriter = class
public
{ Begin/End markers. Those ones who don't have an end indicator, use
"EndList", after the occurrence named in the comment. Note that this
only counts for "EndList" calls on the same level; each BeginXXX call
increases the current level. }
procedure BeginCollection; virtual; abstract; { Ends with the next "EndList" }
procedure BeginComponent(Component: TComponent; Flags: TFilerFlags;
ChildPos: Integer); virtual; abstract; { Ends after the second "EndList" }
procedure WriteSignature; virtual; abstract;
procedure BeginList; virtual; abstract;
procedure EndList; virtual; abstract;
procedure BeginProperty(const PropName: String); virtual; abstract;
procedure EndProperty; virtual; abstract;
Procedure FlushBuffer; virtual;
//Please don't use write, better use WriteBinary whenever possible
procedure Write(const Buffer; Count: Longint); virtual;abstract;
procedure WriteBinary(const Buffer; Count: Longint); virtual; abstract;
procedure WriteBoolean(Value: Boolean); virtual; abstract;
// procedure WriteChar(Value: Char);
{$ifndef FPUNONE}
procedure WriteFloat(const Value: Extended); virtual; abstract;
procedure WriteSingle(const Value: Single); virtual; abstract;
procedure WriteDate(const Value: TDateTime); virtual; abstract;
{$endif}
procedure WriteCurrency(const Value: Currency); virtual; abstract;
procedure WriteIdent(const Ident: string); virtual; abstract;
procedure WriteInteger(Value: Int64); virtual; abstract;
procedure WriteUInt64(Value: QWord); virtual; abstract;
procedure WriteVariant(const Value: Variant); virtual; abstract;
procedure WriteMethodName(const Name: String); virtual; abstract;
procedure WriteSet(Value: LongInt; SetType: Pointer); virtual; abstract;
procedure WriteString(const Value: String); virtual; abstract;
procedure WriteWideString(const Value: WideString);virtual;abstract;
procedure WriteUnicodeString(const Value: UnicodeString);virtual;abstract;
end;
{ TBinaryObjectWriter }
TBinaryObjectWriter = class(TAbstractObjectWriter)
protected
FStream: TStream;
FBuffer: Pointer;
FBufSize: Integer;
FBufPos: Integer;
FBufEnd: Integer;
procedure WriteWord(w : word); {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
procedure WriteDWord(lw : longword); {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
procedure WriteQWord(qw : qword); {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
{$ifndef FPUNONE}
procedure WriteExtended(e : extended); {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
{$endif}
procedure WriteValue(Value: TValueType);
public
constructor Create(Stream: TStream; BufSize: Integer);
destructor Destroy; override;
procedure WriteSignature; override;
procedure FlushBuffer; override;
procedure BeginCollection; override;
procedure BeginComponent(Component: TComponent; Flags: TFilerFlags;
ChildPos: Integer); override;
procedure BeginList; override;
procedure EndList; override;
procedure BeginProperty(const PropName: String); override;
procedure EndProperty; override;
//Please don't use write, better use WriteBinary whenever possible
procedure Write(const Buffer; Count: Longint); override;
procedure WriteBinary(const Buffer; Count: LongInt); override;
procedure WriteBoolean(Value: Boolean); override;
{$ifndef FPUNONE}
procedure WriteFloat(const Value: Extended); override;
procedure WriteSingle(const Value: Single); override;
procedure WriteDate(const Value: TDateTime); override;
{$endif}
procedure WriteCurrency(const Value: Currency); override;
procedure WriteIdent(const Ident: string); override;
procedure WriteInteger(Value: Int64); override;
procedure WriteUInt64(Value: QWord); override;
procedure WriteMethodName(const Name: String); override;
procedure WriteSet(Value: LongInt; SetType: Pointer); override;
procedure WriteStr(const Value: String);
procedure WriteString(const Value: String); override;
procedure WriteWideString(const Value: WideString); override;
procedure WriteUnicodeString(const Value: UnicodeString); override;
procedure WriteVariant(const VarValue: Variant);override;
end;
TTextObjectWriter = class(TAbstractObjectWriter)
end;
TFindAncestorEvent = procedure (Writer: TWriter; Component: TComponent;
const Name: string; var Ancestor, RootAncestor: TComponent) of object;
TWriteMethodPropertyEvent = procedure (Writer: TWriter; Instance: TPersistent;
PropInfo: PPropInfo;
const MethodValue, DefMethodValue: TMethod;
var Handled: boolean) of object;
TWriter = class(TFiler)
private
FDriver: TAbstractObjectWriter;
FDestroyDriver: Boolean;
FRootAncestor: TComponent;
FPropPath: String;
FAncestors: TStringList;
FAncestorPos: Integer;
FCurrentPos: Integer;
FOnFindAncestor: TFindAncestorEvent;
FOnWriteMethodProperty: TWriteMethodPropertyEvent;
FOnWriteStringProperty:TReadWriteStringPropertyEvent;
procedure AddToAncestorList(Component: TComponent);
procedure WriteComponentData(Instance: TComponent);
Procedure DetermineAncestor(Component: TComponent);
procedure DoFindAncestor(Component : TComponent);
protected
procedure SetRoot(ARoot: TComponent); override;
procedure WriteBinary(AWriteData: TStreamProc);
procedure WriteProperty(Instance: TPersistent; PropInfo: Pointer);
procedure WriteProperties(Instance: TPersistent);
procedure WriteChildren(Component: TComponent);
function CreateDriver(Stream: TStream; BufSize: Integer): TAbstractObjectWriter; virtual;
public
constructor Create(ADriver: TAbstractObjectWriter);
constructor Create(Stream: TStream; BufSize: Integer);
destructor Destroy; override;
Procedure FlushBuffer; override;
procedure DefineProperty(const Name: string;
ReadData: TReaderProc; AWriteData: TWriterProc;
HasData: Boolean); override;
procedure DefineBinaryProperty(const Name: string;
ReadData, AWriteData: TStreamProc;
HasData: Boolean); override;
//Please don't use write, better use WriteBinary whenever possible
//uuups, WriteBinary is protected ..
procedure Write(const Buffer; Count: Longint); virtual;
procedure WriteBoolean(Value: Boolean);
procedure WriteCollection(Value: TCollection);
procedure WriteComponent(Component: TComponent);
procedure WriteChar(Value: Char);
procedure WriteWideChar(Value: WideChar);
procedure WriteDescendent(ARoot: TComponent; AAncestor: TComponent);
{$ifndef FPUNONE}
procedure WriteFloat(const Value: Extended);
procedure WriteSingle(const Value: Single);
procedure WriteDate(const Value: TDateTime);
{$endif}
procedure WriteCurrency(const Value: Currency);
procedure WriteIdent(const Ident: string);
procedure WriteInteger(Value: Longint); overload;
procedure WriteInteger(Value: Int64); overload;
procedure WriteSet(Value: LongInt; SetType: Pointer);
procedure WriteListBegin;
procedure WriteListEnd;
Procedure WriteSignature;
procedure WriteRootComponent(ARoot: TComponent);
procedure WriteString(const Value: string);
procedure WriteWideString(const Value: WideString);
procedure WriteUnicodeString(const Value: UnicodeString);
procedure WriteVariant(const VarValue: Variant);
property RootAncestor: TComponent read FRootAncestor write FRootAncestor;
property OnFindAncestor: TFindAncestorEvent read FOnFindAncestor write FOnFindAncestor;
property OnWriteMethodProperty: TWriteMethodPropertyEvent read FOnWriteMethodProperty write FOnWriteMethodProperty;
property OnWriteStringProperty: TReadWriteStringPropertyEvent read FOnWriteStringProperty write FOnWriteStringProperty;
property Driver: TAbstractObjectWriter read FDriver;
property PropertyPath: string read FPropPath;
end;
{ TParser }
TParser = class(TObject)
private
fStream : TStream;
fBuf : pchar;
fBufLen : integer;
fPos : integer;
fDeltaPos : integer;
fFloatType : char;
fSourceLine : integer;
fToken : char;
fEofReached : boolean;
fLastTokenStr : string;
fLastTokenWStr : widestring;
function GetTokenName(aTok : char) : string;
procedure LoadBuffer;
procedure CheckLoadBuffer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
procedure ProcessChar; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function IsNumber : boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function IsHexNum : boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function IsAlpha : boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function IsAlphaNum : boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function GetHexValue(c : char) : byte; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function GetAlphaNum : string;
procedure HandleNewLine;
procedure SkipBOM;
procedure SkipSpaces;
procedure SkipWhitespace;
procedure HandleEof;
procedure HandleAlphaNum;
procedure HandleNumber;
procedure HandleHexNumber;
function HandleQuotedString : string;
procedure HandleDecimalCharacter(var ascii : boolean;
out WideChr: widechar; out StringChr: char);
procedure HandleString;
procedure HandleMinus;
procedure HandleUnknown;
public
constructor Create(Stream: TStream);
destructor Destroy; override;
procedure CheckToken(T: Char);
procedure CheckTokenSymbol(const S: string);
procedure Error(const Ident: string);
procedure ErrorFmt(const Ident: string; const Args: array of const);
procedure ErrorStr(const Message: string);
procedure HexToBinary(Stream: TStream);
function NextToken: Char;
function SourcePos: Longint;
function TokenComponentIdent: string;
{$ifndef FPUNONE}
function TokenFloat: Extended;
{$endif}
function TokenInt: Int64;
function TokenString: string;
function TokenWideString: WideString;
function TokenSymbolIs(const S: string): Boolean;
property FloatType: Char read fFloatType;
property SourceLine: Integer read fSourceLine;
property Token: Char read fToken;
end;
{ TThread }
TThread = Class;
EThread = class(Exception);
EThreadExternalException = class(EThread);
EThreadDestroyCalled = class(EThread);
TSynchronizeProcVar = procedure;
TThreadMethod = procedure of object;
TThreadReportStatus = Procedure(Const status : String) of Object;
TThreadStatusNotifyEvent = Procedure(Sender : TThread; Const status : String) of Object;
TThreadExecuteHandler = TThreadMethod;
TThreadExecuteStatusHandler = Procedure(ReportStatus : TThreadReportStatus) of object;
TNotifyCallBack = Procedure(Sender : TObject; AData : Pointer);
TThreadStatusNotifyCallBack = Procedure(Sender : TThread; AData : Pointer; Const status : String);
TThreadExecuteCallBack = Procedure(AData : Pointer);
TThreadExecuteStatusCallBack = Procedure(AData : Pointer; ReportStatus : TThreadReportStatus);
TThreadPriority = (tpIdle, tpLowest, tpLower, tpNormal, tpHigher, tpHighest,
tpTimeCritical);
TThread = class
private type
PThreadQueueEntry = ^TThreadQueueEntry;
TThreadQueueEntry = record
Method: TThreadMethod;
// uncomment once closures are supported
//ThreadProc: TThreadProcedure;
Thread: TThread;
ThreadID: TThreadID;
Exception: TObject;
SyncEvent: PRtlEvent;
Next: PThreadQueueEntry;
end;
public type
TSystemTimes = record
IdleTime: QWord;
UserTime: QWord;
KernelTime: QWord;
NiceTime: QWord;
end;
private
class var FProcessorCount: LongWord;
private
FHandle: TThreadID;
FTerminated: Boolean;
FFreeOnTerminate: Boolean;
FFinished: Boolean;
FSuspended: LongBool;
FReturnValue: Integer;
FOnTerminate: TNotifyEvent;
FFatalException: TObject;
FExternalThread: Boolean;
FSynchronizeEntry: PThreadQueueEntry;
class function GetCurrentThread: TThread; static;
class function GetIsSingleProcessor: Boolean; static; inline;
class procedure InternalQueue(aThread: TThread; aMethod: TThreadMethod; aQueueIfMain: Boolean); static;
procedure CallOnTerminate;
function GetPriority: TThreadPriority;
procedure SetPriority(Value: TThreadPriority);
procedure SetSuspended(Value: Boolean);
function GetSuspended: Boolean;
procedure InitSynchronizeEvent;
procedure DoneSynchronizeEvent;
{ these two need to be implemented per platform }
procedure SysCreate(CreateSuspended: Boolean;
const StackSize: SizeUInt);
procedure SysDestroy;
protected
FThreadID: TThreadID; // someone might need it for pthread_* calls
procedure DoTerminate; virtual;
procedure TerminatedSet; virtual;
procedure Execute; virtual; abstract;
procedure Synchronize(AMethod: TThreadMethod);
procedure Queue(aMethod: TThreadMethod);
procedure ForceQueue(aMethod: TThreadMethod); inline;
property ReturnValue: Integer read FReturnValue write FReturnValue;
property Terminated: Boolean read FTerminated;
{$if defined(windows) or defined(OS2)}
private
FInitialSuspended: boolean;
{$endif}
{$ifdef Unix}
private
// see tthread.inc, ThreadFunc and TThread.Resume
FSuspendEvent: PRTLEvent;
FInitialSuspended: boolean;
FSuspendedInternal: longbool;
FThreadReaped: boolean;
{$endif}
{$ifdef netwlibc}
private
// see tthread.inc, ThreadFunc and TThread.Resume
FSem: Pointer;
FInitialSuspended: boolean;
FSuspendedExternal: boolean;
FPid: LongInt;
{$endif}
{$if defined(hasamiga)}
private
FInitialSuspended: boolean;
{$endif}
{$ifdef beos}
FSem : pointer;
FSuspendedExternal: boolean;
{$endif}
public
constructor Create(CreateSuspended: Boolean;
const StackSize: SizeUInt = DefaultStackSize);
destructor Destroy; override;
{ Note: Once closures are supported aProc will be changed to TProc }
class function CreateAnonymousThread(aProc: TProcedure): TThread; static;
class procedure NameThreadForDebugging(aThreadName: UnicodeString; aThreadID: TThreadID = TThreadID(-1)); static; inline;
class procedure NameThreadForDebugging(aThreadName: AnsiString; aThreadID: TThreadID = TThreadID(-1)); static; inline;
class procedure SetReturnValue(aValue: Integer); static;
class function CheckTerminated: Boolean; static;
class procedure Synchronize(AThread: TThread; AMethod: TThreadMethod);
class procedure Queue(aThread: TThread; aMethod: TThreadMethod); static;
class procedure ForceQueue(aThread: TThread; aMethod: TThreadMethod); inline; static;
class procedure RemoveQueuedEvents(aThread: TThread; aMethod: TThreadMethod); static;
class procedure RemoveQueuedEvents(aMethod: TThreadMethod); static;
class procedure RemoveQueuedEvents(aThread: TThread); static;
class procedure SpinWait(aIterations: LongWord); static;
class procedure Sleep(aMilliseconds: Cardinal); static;
class procedure Yield; static;
{ use HAS_TTHREAD_GETSYSTEMTIMES to implement a platform specific variant
which does not return a zeroed record }
class procedure GetSystemTimes(out aSystemTimes: TSystemTimes); static;
class function GetTickCount: LongWord; static; deprecated 'Use TThread.GetTickCount64 instead';
class function GetTickCount64: QWord; static;
// Object based
Class Function ExecuteInThread(AMethod : TThreadExecuteHandler; AOnTerminate : TNotifyEvent = Nil) : TThread; overload; static;
Class Function ExecuteInThread(AMethod : TThreadExecuteStatusHandler; AOnStatus : TThreadStatusNotifyEvent; AOnTerminate : TNotifyEvent = Nil) : TThread; overload;static;
// Plain methods.
Class Function ExecuteInThread(AMethod : TThreadExecuteCallback; AData : Pointer = Nil; AOnTerminate: TNotifyCallBack = Nil) : TThread; overload;static;
Class Function ExecuteInThread(AMethod : TThreadExecuteStatusCallback; AOnStatus : TThreadStatusNotifyCallback; AData : Pointer = Nil; AOnTerminate : TNotifyCallBack = Nil) : TThread; overload;static;
procedure AfterConstruction; override;
procedure Start;
procedure Resume; deprecated;
procedure Suspend; deprecated;
procedure Terminate;
function WaitFor: Integer;
class property CurrentThread: TThread read GetCurrentThread;
class property ProcessorCount: LongWord read FProcessorCount;
class property IsSingleProcessor: Boolean read GetIsSingleProcessor;
property FreeOnTerminate: Boolean read FFreeOnTerminate write FFreeOnTerminate;
property Handle: TThreadID read FHandle;
property ExternalThread: Boolean read FExternalThread;
property Priority: TThreadPriority read GetPriority write SetPriority;
property Suspended: Boolean read GetSuspended write SetSuspended;
property Finished: Boolean read FFinished;
property ThreadID: TThreadID read FThreadID;
property OnTerminate: TNotifyEvent read FOnTerminate write FOnTerminate;
property FatalException: TObject read FFatalException;
end;
{ TComponent class }
TOperation = (opInsert, opRemove);
TComponentState = set of (csLoading, csReading, csWriting, csDestroying,
csDesigning, csAncestor, csUpdating, csFixups, csFreeNotification,
csInline, csDesignInstance);
TComponentStyle = set of (csInheritable, csCheckPropAvail, csSubComponent,
csTransient);
TGetChildProc = procedure (Child: TComponent) of object;
IVCLComObject = interface
['{E07892A0-F52F-11CF-BD2F-0020AF0E5B81}']
function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
function GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
function SafeCallException(ExceptObject: TObject; ExceptAddr: CodePointer): HResult;
procedure FreeOnRelease;
end;
IInterfaceComponentReference = interface
['{3FEEC8E1-E400-4A24-BCAC-1F01476439B1}']
function GetComponent:TComponent;
end;
IDesignerNotify = interface
['{B971E807-E3A6-11D1-AAB1-00C04FB16FBC}']
procedure Modified;
procedure Notification(AnObject: TPersistent; Operation: TOperation);
end;
TComponentEnumerator = class
private
FComponent: TComponent;
FPosition: Integer;
public
constructor Create(AComponent: TComponent);
function GetCurrent: TComponent;
function MoveNext: Boolean;
property Current: TComponent read GetCurrent;
end;
TBasicAction = class;
{ TComponent }
TComponent = class(TPersistent,IUnknown,IInterfaceComponentReference)
private
FOwner: TComponent;
FName: TComponentName;
FTag: Ptrint;
FComponents: TFpList;
FFreeNotifies: TFpList;
FDesignInfo: Longint;
FVCLComObject: Pointer;
FComponentState: TComponentState;
function GetComObject: IUnknown;
function GetComponent(AIndex: Integer): TComponent;
function GetComponentCount: Integer;
function GetComponentIndex: Integer;
procedure Insert(AComponent: TComponent);
procedure ReadLeft(Reader: TReader);
procedure ReadTop(Reader: TReader);
procedure Remove(AComponent: TComponent);
procedure RemoveNotification(AComponent: TComponent);
procedure SetComponentIndex(Value: Integer);
procedure SetReference(Enable: Boolean);
procedure WriteLeft(Writer: TWriter);
procedure WriteTop(Writer: TWriter);
protected
FComponentStyle: TComponentStyle;
procedure ChangeName(const NewName: TComponentName);
procedure DefineProperties(Filer: TFiler); override;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); dynamic;
function GetChildOwner: TComponent; dynamic;
function GetChildParent: TComponent; dynamic;
function GetOwner: TPersistent; override;
procedure Loaded; virtual;
procedure Loading; virtual;
procedure Notification(AComponent: TComponent;
Operation: TOperation); virtual;
procedure PaletteCreated; dynamic;
procedure ReadState(Reader: TReader); virtual;
procedure SetAncestor(Value: Boolean);
procedure SetDesigning(Value: Boolean; SetChildren : Boolean = True);
procedure SetDesignInstance(Value: Boolean);
procedure SetInline(Value: Boolean);
procedure SetName(const NewName: TComponentName); virtual;
procedure SetChildOrder(Child: TComponent; Order: Integer); dynamic;
procedure SetParentComponent(Value: TComponent); dynamic;
procedure Updating; dynamic;
procedure Updated; dynamic;
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); dynamic;
procedure ValidateRename(AComponent: TComponent;
const CurName, NewName: string); virtual;
procedure ValidateContainer(AComponent: TComponent); dynamic;
procedure ValidateInsert(AComponent: TComponent); dynamic;
{ IUnknown }
function QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} IID: TGUID; out Obj): Hresult; virtual; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
function _AddRef: Longint; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
function _Release: Longint; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
function iicrGetComponent: TComponent;
{ IDispatch }
function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
function GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
public
//!! Moved temporary
// fpdoc doesn't handle this yet :(
{$ifndef fpdocsystem}
function IInterfaceComponentReference.GetComponent=iicrgetcomponent;
{$endif}
procedure WriteState(Writer: TWriter); virtual;
constructor Create(AOwner: TComponent); virtual;
destructor Destroy; override;
procedure BeforeDestruction; override;
procedure DestroyComponents;
procedure Destroying;
function ExecuteAction(Action: TBasicAction): Boolean; dynamic;
function FindComponent(const AName: string): TComponent;
procedure FreeNotification(AComponent: TComponent);
procedure RemoveFreeNotification(AComponent: TComponent);
procedure FreeOnRelease;
function GetEnumerator: TComponentEnumerator;
function GetNamePath: string; override;
function GetParentComponent: TComponent; dynamic;
function HasParent: Boolean; dynamic;
procedure InsertComponent(AComponent: TComponent);
procedure RemoveComponent(AComponent: TComponent);
function SafeCallException(ExceptObject: TObject;
ExceptAddr: CodePointer): HResult; override;
procedure SetSubComponent(ASubComponent: Boolean);
function UpdateAction(Action: TBasicAction): Boolean; dynamic;
property ComObject: IUnknown read GetComObject;
function IsImplementorOf (const Intf:IInterface):boolean;
procedure ReferenceInterface(const intf:IInterface;op:TOperation);
property Components[Index: Integer]: TComponent read GetComponent;
property ComponentCount: Integer read GetComponentCount;
property ComponentIndex: Integer read GetComponentIndex write SetComponentIndex;
property ComponentState: TComponentState read FComponentState;
property ComponentStyle: TComponentStyle read FComponentStyle;
property DesignInfo: Longint read FDesignInfo write FDesignInfo;
property Owner: TComponent read FOwner;
property VCLComObject: Pointer read FVCLComObject write FVCLComObject;
published
property Name: TComponentName read FName write SetName stored False;
property Tag: PtrInt read FTag write FTag default 0;
end;
{ TBasicActionLink }
TBasicActionLink = class(TObject)
private
FOnChange: TNotifyEvent;
protected
FAction: TBasicAction;
procedure AssignClient(AClient: TObject); virtual;
procedure Change; virtual;
function IsOnExecuteLinked: Boolean; virtual;
procedure SetAction(Value: TBasicAction); virtual;
procedure SetOnExecute(Value: TNotifyEvent); virtual;
public
constructor Create(AClient: TObject); virtual;
destructor Destroy; override;
function Execute(AComponent: TComponent = nil): Boolean; virtual;
function Update: Boolean; virtual;
property Action: TBasicAction read FAction write SetAction;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
TBasicActionLinkClass = class of TBasicActionLink;
{ TBasicAction }
TBasicAction = class(TComponent)
private
FActionComponent: TComponent;
FOnChange: TNotifyEvent;
FOnExecute: TNotifyEvent;
FOnUpdate: TNotifyEvent;
protected
FClients: TFpList;
procedure Change; virtual;
procedure SetOnExecute(Value: TNotifyEvent); virtual;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function HandlesTarget(Target: TObject): Boolean; virtual;
procedure UpdateTarget(Target: TObject); virtual;
procedure ExecuteTarget(Target: TObject); virtual;
function Execute: Boolean; dynamic;
procedure RegisterChanges(Value: TBasicActionLink);
procedure UnRegisterChanges(Value: TBasicActionLink);
function Update: Boolean; virtual;
property ActionComponent: TComponent read FActionComponent write FActionComponent;
property OnExecute: TNotifyEvent read FOnExecute write SetOnExecute;
property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate;
end;
{ TBasicAction class reference type }
TBasicActionClass = class of TBasicAction;
{ Component registration handlers }
TActiveXRegType = (axrComponentOnly, axrIncludeDescendants);
IInterfaceList = interface ['{285DEA8A-B865-11D1-AAA7-00C04FB17A72}']
function Get(i : Integer) : IUnknown;
function GetCapacity : Integer;
function GetCount : Integer;
procedure Put(i : Integer;item : IUnknown);
procedure SetCapacity(NewCapacity : Integer);
procedure SetCount(NewCount : Integer);
procedure Clear;
procedure Delete(index : Integer);
procedure Exchange(index1,index2 : Integer);
function First : IUnknown;
function IndexOf(const item : IUnknown) : Integer;
function Add(item : IUnknown) : Integer;
procedure Insert(i : Integer;item : IUnknown);
function Last : IUnknown;
function Remove(item : IUnknown): Integer;
procedure Lock;
procedure Unlock;
property Capacity : Integer read GetCapacity write SetCapacity;
property Count : Integer read GetCount write SetCount;
property Items[index : Integer] : IUnknown read Get write Put;default;
end;
TInterfaceList = class;
TInterfaceListEnumerator = class
private
FList: TInterfaceList;
FPosition: Integer;
public
constructor Create(AList: TInterfaceList);
function GetCurrent: IUnknown;
function MoveNext: Boolean;
property Current: IUnknown read GetCurrent;
end;
TInterfaceList = class(TInterfacedObject,IInterfaceList)
private
FList : TThreadList;
protected
function Get(i : Integer) : IUnknown;
function GetCapacity : Integer;
function GetCount : Integer;
procedure Put(i : Integer;item : IUnknown);
procedure SetCapacity(NewCapacity : Integer);
procedure SetCount(NewCount : Integer);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Delete(index : Integer);
procedure Exchange(index1,index2 : Integer);
function First : IUnknown;
function GetEnumerator: TInterfaceListEnumerator;
function IndexOf(const item : IUnknown) : Integer;
function Add(item : IUnknown) : Integer;
procedure Insert(i : Integer;item : IUnknown);
function Last : IUnknown;
function Remove(item : IUnknown): Integer;
procedure Lock;
procedure Unlock;
function Expand : TInterfaceList;
property Capacity : Integer read GetCapacity write SetCapacity;
property Count : Integer read GetCount write SetCount;
property Items[Index : Integer] : IUnknown read Get write Put;default;
end;
{ ---------------------------------------------------------------------
TDatamodule support
---------------------------------------------------------------------}
TDataModule = class(TComponent)
private
FDPos: TPoint;
FDSize: TPoint;
FDPPI: Integer;
FOnCreate: TNotifyEvent;
FOnDestroy: TNotifyEvent;
FOldOrder : Boolean;
Procedure ReadP(Reader: TReader);
Procedure WriteP(Writer: TWriter);
Procedure ReadT(Reader: TReader);
Procedure WriteT(Writer: TWriter);
Procedure ReadL(Reader: TReader);
Procedure WriteL(Writer: TWriter);
Procedure ReadW(Reader: TReader);
Procedure WriteW(Writer: TWriter);
Procedure ReadH(Reader: TReader);
Procedure WriteH(Writer: TWriter);
protected
Procedure DoCreate; virtual;
Procedure DoDestroy; virtual;
Procedure DefineProperties(Filer: TFiler); override;
Procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
Function HandleCreateException: Boolean; virtual;
Procedure ReadState(Reader: TReader); override;
public
constructor Create(AOwner: TComponent); override;
Constructor CreateNew(AOwner: TComponent);
Constructor CreateNew(AOwner: TComponent; CreateMode: Integer); virtual;
destructor Destroy; override;
Procedure AfterConstruction; override;
Procedure BeforeDestruction; override;
property DesignOffset: TPoint read FDPos write FDPos;
property DesignSize: TPoint read FDSize write FDSize;
property DesignPPI: Integer read FDPPI write FDPPI;
published
property OnCreate: TNotifyEvent read FOnCreate write FOnCreate;
property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
property OldCreateOrder: Boolean read FOldOrder write FOldOrder;
end;
TDataModuleClass = Class of TDataModule;
var
// IDE hooks for TDatamodule support.
AddDataModule : procedure (DataModule: TDataModule) of object;
RemoveDataModule : procedure (DataModule: TDataModule) of object;
ApplicationHandleException : procedure (Sender: TObject) of object;
ApplicationShowException : procedure (E: Exception) of object;
{ ---------------------------------------------------------------------
tthread helpers
---------------------------------------------------------------------}
{ function to be called when gui thread is ready to execute method
result is true if a method has been executed
}
function CheckSynchronize(timeout : longint=0) : boolean;
var
{ method proc that is called to trigger gui thread to execute a
method }
WakeMainThread : TNotifyEvent = nil;
{ ---------------------------------------------------------------------
General streaming and registration routines
---------------------------------------------------------------------}
var
RegisterComponentsProc: procedure(const Page: string;
ComponentClasses: array of TComponentClass);
RegisterNoIconProc: procedure(ComponentClasses: array of TComponentClass);
{!!!! RegisterNonActiveXProc: procedure(ComponentClasses: array of TComponentClass;
AxRegType: TActiveXRegType) = nil;
CurrentGroup: Integer = -1;}
CreateVCLComObjectProc: procedure(Component: TComponent) = nil;
{ Point and rectangle constructors }
function Point(AX, AY: Integer): TPoint;
function SmallPoint(AX, AY: SmallInt): TSmallPoint;
function Rect(ALeft, ATop, ARight, ABottom: Integer): TRect;
function Bounds(ALeft, ATop, AWidth, AHeight: Integer): TRect;
function PointsEqual(const P1, P2: TPoint): Boolean; {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
function PointsEqual(const P1, P2: TSmallPoint): Boolean; {$ifdef CLASSESINLINE}inline;{$endif CLASSESINLINE}
function InvalidPoint(X, Y: Integer): Boolean;
function InvalidPoint(const At: TPoint): Boolean;
function InvalidPoint(const At: TSmallPoint): Boolean;
{ Class registration routines }
procedure RegisterClass(AClass: TPersistentClass);
procedure RegisterClasses(AClasses: array of TPersistentClass);
procedure RegisterClassAlias(AClass: TPersistentClass; const Alias: string);
procedure UnRegisterClass(AClass: TPersistentClass);
procedure UnRegisterClasses(AClasses: array of TPersistentClass);
procedure UnRegisterModuleClasses(Module: HMODULE);
function FindClass(const AClassName: string): TPersistentClass;
function GetClass(const AClassName: string): TPersistentClass;
procedure StartClassGroup(AClass: TPersistentClass);
procedure GroupDescendentsWith(AClass, AClassGroup: TPersistentClass);
function ActivateClassGroup(AClass: TPersistentClass): TPersistentClass;
function ClassGroupOf(AClass: TPersistentClass): TPersistentClass;
function ClassGroupOf(Instance: TPersistent): TPersistentClass;
{ Component registration routines }
procedure RegisterComponents(const Page: string;
ComponentClasses: array of TComponentClass);
procedure RegisterNoIcon(ComponentClasses: array of TComponentClass);
procedure RegisterNonActiveX(ComponentClasses: array of TComponentClass;
AxRegType: TActiveXRegType);
var
GlobalNameSpace: IReadWriteSync;
{ Object filing routines }
type
TIdentMapEntry = record
Value: Integer;
Name: String;
end;
TIdentToInt = function(const Ident: string; var Int: Longint): Boolean;
TIntToIdent = function(Int: Longint; var Ident: string): Boolean;
TFindGlobalComponent = function(const Name: string): TComponent;
TInitComponentHandler = function(Instance: TComponent; RootAncestor : TClass): boolean;
var
MainThreadID: TThreadID;
procedure RegisterIntegerConsts(IntegerType: Pointer; IdentToIntFn: TIdentToInt;
IntToIdentFn: TIntToIdent);
function IdentToInt(const Ident: string; out Int: Longint; const Map: array of TIdentMapEntry): Boolean;
function IntToIdent(Int: Longint; var Ident: string; const Map: array of TIdentMapEntry): Boolean;
function FindIntToIdent(AIntegerType: Pointer): TIntToIdent;
function FindIdentToInt(AIntegerType: Pointer): TIdentToInt;
procedure RegisterFindGlobalComponentProc(AFindGlobalComponent: TFindGlobalComponent);
procedure UnregisterFindGlobalComponentProc(AFindGlobalComponent: TFindGlobalComponent);
function FindGlobalComponent(const Name: string): TComponent;
function InitInheritedComponent(Instance: TComponent; RootAncestor: TClass): Boolean;
function InitComponentRes(const ResName: string; Instance: TComponent): Boolean;
function ReadComponentRes(const ResName: string; Instance: TComponent): TComponent;
function ReadComponentResEx(HInstance: THandle; const ResName: string): TComponent;
function ReadComponentResFile(const FileName: string; Instance: TComponent): TComponent;
procedure WriteComponentResFile(const FileName: string; Instance: TComponent);
procedure RegisterInitComponentHandler(ComponentClass: TComponentClass; Handler: TInitComponentHandler);
procedure GlobalFixupReferences;
procedure GetFixupReferenceNames(Root: TComponent; Names: TStrings);
procedure GetFixupInstanceNames(Root: TComponent;
const ReferenceRootName: string; Names: TStrings);
procedure RedirectFixupReferences(Root: TComponent; const OldRootName,
NewRootName: string);
procedure RemoveFixupReferences(Root: TComponent; const RootName: string);
procedure RemoveFixups(Instance: TPersistent);
Function FindNestedComponent(Root : TComponent; APath : String; CStyle : Boolean = True) : TComponent;
procedure BeginGlobalLoading;
procedure NotifyGlobalLoading;
procedure EndGlobalLoading;
function CollectionsEqual(C1, C2: TCollection): Boolean;
function CollectionsEqual(C1, C2: TCollection; Owner1, Owner2: TComponent): Boolean;
{ Object conversion routines }
type
TObjectTextEncoding = (
oteDFM,
oteLFM
);
procedure ObjectBinaryToText(Input, Output: TStream; Encoding: TObjectTextEncoding);
procedure ObjectBinaryToText(Input, Output: TStream);
procedure ObjectTextToBinary(Input, Output: TStream);
procedure ObjectResourceToText(Input, Output: TStream);
procedure ObjectTextToResource(Input, Output: TStream);
{ Utility routines }
function LineStart(Buffer, BufPos: PChar): PChar;
procedure BinToHex(BinValue, HexValue: PChar; BinBufSize: Integer);
function HexToBin(HexValue, BinValue: PChar; BinBufSize: Integer): Integer;
function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings; AddEmptyStrings : Boolean = False): Integer;
|