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
|
{*****************************************************************************}
{ }
{ Tnt Delphi Unicode Controls }
{ http://tnt.ccci.org/delphi_unicode_controls/ }
{ Version: 2.1.11 }
{ }
{ Copyright (c) 2002-2004, Troy Wolbrink (troy.wolbrink@ccci.org) }
{ }
{*****************************************************************************}
unit TntDbCtrls;
{$INCLUDE TntCompilers.inc}
interface
uses
Forms, Classes, Windows, Messages, DB, DBCtrls, Controls, StdCtrls,
TntClasses, TntStdCtrls, TntControls, TntComCtrls, TntExtCtrls;
type
{TNT-WARN TPaintControl}
TTntPaintControl = class
private
FOwner: TWinControl;
FClassName: WideString;
FHandle: HWnd;
FObjectInstance: Pointer;
FDefWindowProc: Pointer;
FCtl3dButton: Boolean;
function GetHandle: HWnd;
procedure SetCtl3DButton(Value: Boolean);
procedure WndProc(var Message: TMessage);
public
constructor Create(AOwner: TWinControl; const ClassName: WideString);
destructor Destroy; override;
procedure DestroyHandle;
property Ctl3DButton: Boolean read FCtl3dButton write SetCtl3dButton;
property Handle: HWnd read GetHandle;
end;
type
{TNT-WARN TDBEdit}
TTntDBEdit = class(TDBEdit{TNT-ALLOW TDBEdit})
private
InheritedDataChange: TNotifyEvent;
FPasswordChar: WideChar;
procedure DataChange(Sender: TObject);
procedure UpdateData(Sender: TObject);
function GetHint: WideString;
procedure SetHint(const Value: WideString);
function IsHintStored: Boolean;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
function GetTextMargins: TPoint;
function GetPasswordChar: WideChar;
procedure SetPasswordChar(const Value: WideChar);
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
private
function GetSelStart: Integer; reintroduce; virtual;
procedure SetSelStart(const Value: Integer); reintroduce; virtual;
function GetSelLength: Integer; reintroduce; virtual;
procedure SetSelLength(const Value: Integer); reintroduce; virtual;
function GetSelText: WideString; reintroduce;
procedure SetSelText(const Value: WideString);
function GetText: WideString;
procedure SetText(const Value: WideString);
protected
procedure CreateWindowHandle(const Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DefineProperties(Filer: TFiler); override;
function GetActionLinkClass: TControlActionLinkClass; override;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
property SelText: WideString read GetSelText write SetSelText;
property SelStart: Integer read GetSelStart write SetSelStart;
property SelLength: Integer read GetSelLength write SetSelLength;
property Text: WideString read GetText write SetText;
published
property Hint: WideString read GetHint write SetHint stored IsHintStored;
property PasswordChar: WideChar read GetPasswordChar write SetPasswordChar default #0;
end;
{TNT-WARN TDBText}
TTntDBText = class(TDBText{TNT-ALLOW TDBText})
private
FDataLink: TFieldDataLink;
InheritedDataChange: TNotifyEvent;
function GetHint: WideString;
procedure SetHint(const Value: WideString);
function IsHintStored: Boolean;
procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
function GetCaption: TWideCaption;
function IsCaptionStored: Boolean;
procedure SetCaption(const Value: TWideCaption);
function GetFieldText: WideString;
procedure DataChange(Sender: TObject);
protected
procedure DefineProperties(Filer: TFiler); override;
function GetLabelText: WideString; reintroduce; virtual;
function GetActionLinkClass: TControlActionLinkClass; override;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
procedure DoDrawText(var Rect: TRect; Flags: Longint); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Caption: TWideCaption read GetCaption write SetCaption stored IsCaptionStored;
published
property Hint: WideString read GetHint write SetHint stored IsHintStored;
end;
{TNT-WARN TDBComboBox}
TTntCustomDBComboBox = class(TDBComboBox{TNT-ALLOW TDBComboBox},
IWideCustomListControl)
private
FDataLink: TFieldDataLink;
{$IFDEF COMPILER_6_UP}
FFilter: WideString;
FLastTime: Cardinal;
{$ENDIF}
procedure UpdateData(Sender: TObject);
procedure EditingChange(Sender: TObject);
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure SetReadOnly;
function GetHint: WideString;
procedure SetHint(const Value: WideString);
function IsHintStored: Boolean;
procedure WMChar(var Message: TWMChar); message WM_CHAR;
private
FItems: TTntStrings;
FSaveItems: TTntStrings;
FSaveItemIndex: integer;
function GetItems: TTntStrings;
procedure SetItems(const Value: TTntStrings); reintroduce;
function GetSelStart: Integer;
procedure SetSelStart(const Value: Integer);
function GetSelLength: Integer;
procedure SetSelLength(const Value: Integer);
function GetSelText: WideString;
procedure SetSelText(const Value: WideString);
function GetText: WideString;
procedure SetText(const Value: WideString);
procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
protected
procedure DataChange(Sender: TObject);
function GetAutoComplete_UniqueMatchOnly: Boolean; dynamic;
function GetAutoComplete_PreserveDataEntryCase: Boolean; dynamic;
procedure DoEditCharMsg(var Message: TWMChar); virtual;
function GetFieldValue: Variant; virtual;
procedure SetFieldValue(const Value: Variant); virtual;
function GetComboValue: Variant; virtual; abstract;
procedure SetComboValue(const Value: Variant); virtual; abstract;
{$IFDEF DELPHI_7}
function GetItemsClass: TCustomComboBoxStringsClass; override;
{$ENDIF}
protected
procedure CreateWindowHandle(const Params: TCreateParams); override;
procedure DefineProperties(Filer: TFiler); override;
function GetActionLinkClass: TControlActionLinkClass; override;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
procedure WndProc(var Message: TMessage); override;
procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override;
procedure KeyPress(var Key: AnsiChar); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{$IFDEF COMPILER_6_UP}
procedure CopySelection(Destination: TCustomListControl); override;
{$ENDIF}
procedure AddItem(const Item: WideString; AObject: TObject); reintroduce; virtual;
public
property SelText: WideString read GetSelText write SetSelText;
property SelStart: Integer read GetSelStart write SetSelStart;
property SelLength: Integer read GetSelLength write SetSelLength;
property Text: WideString read GetText write SetText;
published
property Hint: WideString read GetHint write SetHint stored IsHintStored;
property Items: TTntStrings read GetItems write SetItems;
end;
TTntDBComboBox = class(TTntCustomDBComboBox)
protected
function GetFieldValue: Variant; override;
procedure SetFieldValue(const Value: Variant); override;
function GetComboValue: Variant; override;
procedure SetComboValue(const Value: Variant); override;
end;
type
{TNT-WARN TDBCheckBox}
TTntDBCheckBox = class(TDBCheckBox{TNT-ALLOW TDBCheckBox})
private
function GetCaption: TWideCaption;
procedure SetCaption(const Value: TWideCaption);
function GetHint: WideString;
procedure SetHint(const Value: WideString);
function IsCaptionStored: Boolean;
function IsHintStored: Boolean;
protected
procedure CreateWindowHandle(const Params: TCreateParams); override;
procedure DefineProperties(Filer: TFiler); override;
function GetActionLinkClass: TControlActionLinkClass; override;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
procedure Toggle; override;
published
property Caption: TWideCaption read GetCaption write SetCaption stored IsCaptionStored;
property Hint: WideString read GetHint write SetHint stored IsHintStored;
end;
{TNT-WARN TDBRichEdit}
TTntDBRichEdit = class(TTntCustomRichEdit)
private
FDataLink: TFieldDataLink;
FAutoDisplay: Boolean;
FFocused: Boolean;
FMemoLoaded: Boolean;
FDataSave: AnsiString;
procedure BeginEditing;
procedure DataChange(Sender: TObject);
procedure EditingChange(Sender: TObject);
function GetDataField: string{TNT-ALLOW string};
function GetDataSource: TDataSource;
function GetField: TField;
function GetReadOnly: Boolean;
procedure SetDataField(const Value: string{TNT-ALLOW string});
procedure SetDataSource(Value: TDataSource);
procedure SetReadOnly(Value: Boolean);
procedure SetAutoDisplay(Value: Boolean);
procedure SetFocused(Value: Boolean);
procedure UpdateData(Sender: TObject);
procedure WMCut(var Message: TMessage); message WM_CUT;
procedure WMPaste(var Message: TMessage); message WM_PASTE;
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
protected
procedure InternalLoadMemo; dynamic;
procedure InternalSaveMemo; dynamic;
protected
procedure Change; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: AnsiChar); override;
procedure Loaded; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ExecuteAction(Action: TBasicAction): Boolean; override;
procedure LoadMemo; virtual;
function UpdateAction(Action: TBasicAction): Boolean; override;
function UseRightToLeftAlignment: Boolean; override;
property Field: TField read GetField;
published
property Align;
property Alignment;
property Anchors;
property AutoDisplay: Boolean read FAutoDisplay write SetAutoDisplay default True;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property DataField: string{TNT-ALLOW string} read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property HideScrollBars;
property ImeMode;
property ImeName;
property MaxLength;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PlainText;
property PopupMenu;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
property ScrollBars;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property WantReturns;
property WantTabs;
property WordWrap;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResizeRequest;
property OnSelectionChange;
property OnProtectChange;
property OnSaveClipboard;
property OnStartDock;
property OnStartDrag;
end;
type
{TNT-WARN TDBMemo}
TTntDBMemo = class(TTntCustomMemo)
private
FDataLink: TFieldDataLink;
FAutoDisplay: Boolean;
FFocused: Boolean;
FMemoLoaded: Boolean;
FPaintControl: TTntPaintControl;
procedure DataChange(Sender: TObject);
procedure EditingChange(Sender: TObject);
function GetDataField: string{TNT-ALLOW string};
function GetDataSource: TDataSource;
function GetField: TField;
function GetReadOnly: Boolean;
procedure SetDataField(const Value: string{TNT-ALLOW string});
procedure SetDataSource(Value: TDataSource);
procedure SetReadOnly(Value: Boolean);
procedure SetAutoDisplay(Value: Boolean);
procedure SetFocused(Value: Boolean);
procedure UpdateData(Sender: TObject);
procedure WMCut(var Message: TMessage); message WM_CUT;
procedure WMPaste(var Message: TMessage); message WM_PASTE;
procedure WMUndo(var Message: TMessage); message WM_UNDO;
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;
protected
procedure Change; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char{TNT-ALLOW Char}); override;
procedure Loaded; override;
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
procedure WndProc(var Message: TMessage); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ExecuteAction(Action: TBasicAction): Boolean; override;
procedure LoadMemo; virtual;
function UpdateAction(Action: TBasicAction): Boolean; override;
function UseRightToLeftAlignment: Boolean; override;
property Field: TField read GetField;
published
property Align;
property Alignment;
property Anchors;
property AutoDisplay: Boolean read FAutoDisplay write SetAutoDisplay default True;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property DataField: string{TNT-ALLOW string} read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property ImeMode;
property ImeName;
property MaxLength;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
property ScrollBars;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property WantReturns;
property WantTabs;
property WordWrap;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
{ TDBRadioGroup }
type
TTntDBRadioGroup = class(TTntCustomRadioGroup)
private
FDataLink: TFieldDataLink;
FValue: WideString;
FValues: TTntStrings;
FInSetValue: Boolean;
FOnChange: TNotifyEvent;
procedure DataChange(Sender: TObject);
procedure UpdateData(Sender: TObject);
function GetDataField: string{TNT-ALLOW string};
function GetDataSource: TDataSource;
function GetField: TField;
function GetReadOnly: Boolean;
function GetButtonValue(Index: Integer): WideString;
procedure SetDataField(const Value: string{TNT-ALLOW string});
procedure SetDataSource(Value: TDataSource);
procedure SetReadOnly(Value: Boolean);
procedure SetValue(const Value: WideString);
procedure SetItems(Value: TTntStrings);
procedure SetValues(Value: TTntStrings);
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;
protected
procedure Change; dynamic;
procedure Click; override;
procedure KeyPress(var Key: Char{TNT-ALLOW Char}); override;
function CanModify: Boolean; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
property DataLink: TFieldDataLink read FDataLink;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ExecuteAction(Action: TBasicAction): Boolean; override;
function UpdateAction(Action: TBasicAction): Boolean; override;
function UseRightToLeftAlignment: Boolean; override;
property Field: TField read GetField;
property ItemIndex;
property Value: WideString read FValue write SetValue;
published
property Align;
property Anchors;
property BiDiMode;
property Caption;
property Color;
property Columns;
property Constraints;
property Ctl3D;
property DataField: string{TNT-ALLOW string} read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property Items write SetItems;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
property ShowHint;
property TabOrder;
property TabStop;
property Values: TTntStrings read FValues write SetValues;
property Visible;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnClick;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnStartDock;
property OnStartDrag;
end;
implementation
uses
SysUtils, Graphics, {$IFDEF COMPILER_6_UP} Variants, {$ENDIF} TntDB,
TntActnList, TntGraphics, TntSysUtils, RichEdit, Mask;
function FieldIsBlobLike(Field: TField): Boolean;
begin
Result := False;
if Assigned(Field) then begin
if Field.IsBlob then
Result := True
else if (Field is TWideStringField{TNT-ALLOW TWideStringField})
and (Field.Size = MaxInt) then
Result := True; { wide string field filling in for a blob field }
end;
end;
{ TTntPaintControl }
type
TAccessWinControl = class(TWinControl);
constructor TTntPaintControl.Create(AOwner: TWinControl; const ClassName: WideString);
begin
FOwner := AOwner;
FClassName := ClassName;
end;
destructor TTntPaintControl.Destroy;
begin
DestroyHandle;
end;
procedure TTntPaintControl.DestroyHandle;
begin
if FHandle <> 0 then DestroyWindow(FHandle);
FreeObjectInstance(FObjectInstance);
FHandle := 0;
FObjectInstance := nil;
end;
function TTntPaintControl.GetHandle: HWnd;
var
Params: TCreateParams;
begin
if FHandle = 0 then
begin
FObjectInstance := MakeObjectInstance(WndProc);
TAccessWinControl(FOwner).CreateParams(Params);
Params.Style := Params.Style and not (WS_HSCROLL or WS_VSCROLL);
if (not Win32PlatformIsUnicode) then begin
with Params do
FHandle := CreateWindowEx(ExStyle, PAnsiChar(AnsiString(FClassName)),
PAnsiChar(TAccessWinControl(FOwner).Text), Style or WS_VISIBLE,
X, Y, Width, Height, Application.Handle, 0, HInstance, nil);
FDefWindowProc := Pointer(GetWindowLong(FHandle, GWL_WNDPROC));
SetWindowLong(FHandle, GWL_WNDPROC, Integer(FObjectInstance));
end else begin
with Params do
FHandle := CreateWindowExW(ExStyle, PWideChar(FClassName),
PWideChar(TntControl_GetText(FOwner)), Style or WS_VISIBLE,
X, Y, Width, Height, Application.Handle, 0, HInstance, nil);
FDefWindowProc := Pointer(GetWindowLongW(FHandle, GWL_WNDPROC));
SetWindowLongW(FHandle, GWL_WNDPROC, Integer(FObjectInstance));
end;
SendMessage(FHandle, WM_SETFONT, TAccessWinControl(FOwner).Font.Handle, 1);
end;
Result := FHandle;
end;
procedure TTntPaintControl.SetCtl3DButton(Value: Boolean);
begin
if FHandle <> 0 then DestroyHandle;
FCtl3DButton := Value;
end;
procedure TTntPaintControl.WndProc(var Message: TMessage);
begin
with Message do
if (Msg >= CN_CTLCOLORMSGBOX) and (Msg <= CN_CTLCOLORSTATIC) then
Result := FOwner.Perform(Msg, WParam, LParam)
else if (not Win32PlatformIsUnicode) then
Result := CallWindowProcA(FDefWindowProc, FHandle, Msg, WParam, LParam)
else
Result := CallWindowProcW(FDefWindowProc, FHandle, Msg, WParam, LParam);
end;
{ THackFieldDataLink }
type
THackFieldDataLink_D5_D6_D7_D9 = class(TDataLink)
protected
FField: TField;
FFieldName: string{TNT-ALLOW string};
FControl: TComponent;
FEditing: Boolean;
FModified: Boolean;
end;
{$IFDEF COMPILER_5}
THackFieldDataLink = THackFieldDataLink_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF COMPILER_6}
THackFieldDataLink = THackFieldDataLink_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF DELPHI_7}
THackFieldDataLink = THackFieldDataLink_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF DELPHI_9}
THackFieldDataLink = THackFieldDataLink_D5_D6_D7_D9;
{$ENDIF}
{ TTntDBEdit }
type
THackDBEdit_D5_D6_D7_D9 = class(TCustomMaskEdit)
protected
FDataLink: TFieldDataLink;
FCanvas: TControlCanvas;
FAlignment: TAlignment;
FFocused: Boolean;
end;
{$IFDEF COMPILER_5}
THackDBEdit = THackDBEdit_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF COMPILER_6}
THackDBEdit = THackDBEdit_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF DELPHI_7}
THackDBEdit = THackDBEdit_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF DELPHI_9}
THackDBEdit = THackDBEdit_D5_D6_D7_D9;
{$ENDIF}
constructor TTntDBEdit.Create(AOwner: TComponent);
begin
inherited;
InheritedDataChange := THackDBEdit(Self).FDataLink.OnDataChange;
THackDBEdit(Self).FDataLink.OnDataChange := DataChange;
THackDBEdit(Self).FDataLink.OnUpdateData := UpdateData;
end;
procedure TTntDBEdit.CreateWindowHandle(const Params: TCreateParams);
begin
CreateUnicodeHandle(Self, Params, 'EDIT');
end;
procedure TTntDBEdit.CreateWnd;
begin
inherited;
TntCustomEdit_AfterInherited_CreateWnd(Self, FPasswordChar);
end;
procedure TTntDBEdit.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
function TTntDBEdit.GetSelStart: Integer;
begin
Result := TntCustomEdit_GetSelStart(Self);
end;
procedure TTntDBEdit.SetSelStart(const Value: Integer);
begin
TntCustomEdit_SetSelStart(Self, Value);
end;
function TTntDBEdit.GetSelLength: Integer;
begin
Result := TntCustomEdit_GetSelLength(Self);
end;
procedure TTntDBEdit.SetSelLength(const Value: Integer);
begin
TntCustomEdit_SetSelLength(Self, Value);
end;
function TTntDBEdit.GetSelText: WideString;
begin
Result := TntCustomEdit_GetSelText(Self);
end;
procedure TTntDBEdit.SetSelText(const Value: WideString);
begin
TntCustomEdit_SetSelText(Self, Value);
end;
function TTntDBEdit.GetPasswordChar: WideChar;
begin
Result := TntCustomEdit_GetPasswordChar(Self, FPasswordChar)
end;
procedure TTntDBEdit.SetPasswordChar(const Value: WideChar);
begin
TntCustomEdit_SetPasswordChar(Self, FPasswordChar, Value);
end;
function TTntDBEdit.GetText: WideString;
begin
Result := TntControl_GetText(Self);
end;
procedure TTntDBEdit.SetText(const Value: WideString);
begin
TntControl_SetText(Self, Value);
end;
procedure TTntDBEdit.DataChange(Sender: TObject);
begin
with THackDBEdit(Self), Self do begin
if Field = nil then
InheritedDataChange(Sender)
else begin
if FAlignment <> Field.Alignment then
begin
EditText := ''; {forces update}
FAlignment := Field.Alignment;
end;
EditMask := Field.EditMask;
if not (csDesigning in ComponentState) then
begin
if (Field.DataType in [ftString, ftWideString]) and (MaxLength = 0) then
MaxLength := Field.Size;
end;
if FFocused and FDataLink.CanModify then
Text := GetWideText(Field)
else
begin
Text := GetWideDisplayText(Field);
if FDataLink.Editing and THackFieldDataLink(FDataLink).FModified then
Modified := True;
end;
end;
end;
end;
procedure TTntDBEdit.UpdateData(Sender: TObject);
begin
ValidateEdit;
SetWideText(Field, Text);
end;
procedure TTntDBEdit.CMEnter(var Message: TCMEnter);
var
SaveFarEast: Boolean;
begin
SaveFarEast := SysLocale.FarEast;
try
SysLocale.FarEast := False;
inherited; // inherited tries to work around Win95 FarEast bug, but introduces others
finally
SysLocale.FarEast := SaveFarEast;
end;
end;
function TTntDBEdit.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self);
end;
function TTntDBEdit.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntDBEdit.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntDBEdit.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
function TTntDBEdit.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
procedure TTntDBEdit.WMPaint(var Message: TWMPaint);
const
AlignStyle : array[Boolean, TAlignment] of DWORD =
((WS_EX_LEFT, WS_EX_RIGHT, WS_EX_LEFT),
(WS_EX_RIGHT, WS_EX_LEFT, WS_EX_LEFT));
var
ALeft: Integer;
Margins: TPoint;
R: TRect;
DC: HDC;
PS: TPaintStruct;
S: WideString;
AAlignment: TAlignment;
I: Integer;
begin
with THackDBEdit(Self), Self do begin
AAlignment := FAlignment;
if UseRightToLeftAlignment then ChangeBiDiModeAlignment(AAlignment);
if ((AAlignment = taLeftJustify) or FFocused) and (not (csPaintCopy in ControlState))
or (not Win32PlatformIsUnicode) then
begin
inherited;
Exit;
end;
{ Since edit controls do not handle justification unless multi-line (and
then only poorly) we will draw right and center justify manually unless
the edit has the focus. }
if FCanvas = nil then
begin
FCanvas := TControlCanvas.Create;
FCanvas.Control := Self;
end;
DC := Message.DC;
if DC = 0 then DC := BeginPaint(Handle, PS);
FCanvas.Handle := DC;
try
FCanvas.Font := Font;
with FCanvas do
begin
R := ClientRect;
if not (NewStyleControls and Ctl3D) and (BorderStyle = bsSingle) then
begin
Brush.Color := clWindowFrame;
FrameRect(R);
InflateRect(R, -1, -1);
end;
Brush.Color := Color;
if not Enabled then
Font.Color := clGrayText;
if (csPaintCopy in ControlState) and (Field <> nil) then
begin
S := GetWideDisplayText(Field);
case CharCase of
ecUpperCase: S := Tnt_WideUpperCase(S);
ecLowerCase: S := Tnt_WideLowerCase(S);
end;
end else
S := Text { EditText? };
if PasswordChar <> #0 then
for I := 1 to Length(S) do S[I] := PasswordChar;
Margins := GetTextMargins;
case AAlignment of
taLeftJustify: ALeft := Margins.X;
taRightJustify: ALeft := ClientWidth - WideCanvasTextWidth(FCanvas, S) - Margins.X - 1;
else
ALeft := (ClientWidth - WideCanvasTextWidth(FCanvas, S)) div 2;
end;
if SysLocale.MiddleEast then UpdateTextFlags;
WideCanvasTextRect(FCanvas, R, ALeft, Margins.Y, S);
end;
finally
FCanvas.Handle := 0;
if Message.DC = 0 then EndPaint(Handle, PS);
end;
end;
end;
function TTntDBEdit.GetTextMargins: TPoint;
var
DC: HDC;
SaveFont: HFont;
I: Integer;
SysMetrics, Metrics: TTextMetric;
begin
if NewStyleControls then
begin
if BorderStyle = bsNone then I := 0 else
if Ctl3D then I := 1 else I := 2;
Result.X := SendMessage(Handle, EM_GETMARGINS, 0, 0) and $0000FFFF + I;
Result.Y := I;
end else
begin
if BorderStyle = bsNone then I := 0 else
begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
I := SysMetrics.tmHeight;
if I > Metrics.tmHeight then I := Metrics.tmHeight;
I := I div 4;
end;
Result.X := I;
Result.Y := I;
end;
end;
{ TTntDBText }
constructor TTntDBText.Create(AOwner: TComponent);
begin
inherited;
FDataLink := TDataLink(Perform(CM_GETDATALINK, 0, 0)) as TFieldDataLink;
InheritedDataChange := FDataLink.OnDataChange;
FDataLink.OnDataChange := DataChange;
end;
destructor TTntDBText.Destroy;
begin
FDataLink := nil;
inherited;
end;
procedure TTntDBText.CMDialogChar(var Message: TCMDialogChar);
begin
TntLabel_CMDialogChar(Self, Message, Caption);
end;
function TTntDBText.IsCaptionStored: Boolean;
begin
Result := TntControl_IsCaptionStored(Self)
end;
function TTntDBText.GetCaption: TWideCaption;
begin
Result := TntControl_GetText(Self);
end;
procedure TTntDBText.SetCaption(const Value: TWideCaption);
begin
TntControl_SetText(Self, Value);
end;
procedure TTntDBText.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
function TTntDBText.GetLabelText: WideString;
begin
if csPaintCopy in ControlState then
Result := GetFieldText
else
Result := Caption;
end;
procedure TTntDBText.DoDrawText(var Rect: TRect; Flags: Integer);
begin
if not TntLabel_DoDrawText(Self, Rect, Flags, GetLabelText) then
inherited;
end;
function TTntDBText.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self);
end;
function TTntDBText.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntDBText.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntDBText.CMHintShow(var Message: TMessage);
begin
ProcessCMHintShowMsg(Message);
inherited;
end;
procedure TTntDBText.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
function TTntDBText.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
function TTntDBText.GetFieldText: WideString;
begin
if Field <> nil then
Result := GetWideDisplayText(Field)
else
if csDesigning in ComponentState then Result := Name else Result := '';
end;
procedure TTntDBText.DataChange(Sender: TObject);
begin
Caption := GetFieldText;
end;
{ TTntCustomDBComboBox }
constructor TTntCustomDBComboBox.Create(AOwner: TComponent);
begin
inherited;
FItems := TTntComboBoxStrings.Create;
TTntComboBoxStrings(FItems).ComboBox := Self;
FDataLink := TDataLink(Perform(CM_GETDATALINK, 0, 0)) as TFieldDataLink;
FDataLink.OnDataChange := DataChange;
FDataLink.OnUpdateData := UpdateData;
FDataLink.OnEditingChange := EditingChange;
end;
destructor TTntCustomDBComboBox.Destroy;
begin
FreeAndNil(FItems);
FreeAndNil(FSaveItems);
FDataLink := nil;
inherited;
end;
procedure TTntCustomDBComboBox.CreateWindowHandle(const Params: TCreateParams);
begin
CreateUnicodeHandle(Self, Params, 'COMBOBOX');
end;
procedure TTntCustomDBComboBox.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
type
TAccessCustomComboBox = class(TCustomComboBox{TNT-ALLOW TCustomComboBox});
procedure TTntCustomDBComboBox.CreateWnd;
var
PreInheritedAnsiText: AnsiString;
begin
PreInheritedAnsiText := TAccessCustomComboBox(Self).Text;
inherited;
TntCombo_AfterInherited_CreateWnd(Self, Items, FSaveItems, FSaveItemIndex, PreInheritedAnsiText);
end;
procedure TTntCustomDBComboBox.DestroyWnd;
begin
TntCombo_BeforeInherited_DestroyWnd(Self, Items, FSaveItems, ItemIndex, FSaveItemIndex);
inherited;
end;
procedure TTntCustomDBComboBox.SetReadOnly;
begin
if (Style in [csDropDown, csSimple]) and HandleAllocated then
SendMessage(EditHandle, EM_SETREADONLY, Ord(not FDataLink.CanModify), 0);
end;
procedure TTntCustomDBComboBox.EditingChange(Sender: TObject);
begin
SetReadOnly;
end;
procedure TTntCustomDBComboBox.CMEnter(var Message: TCMEnter);
var
SaveFarEast: Boolean;
begin
SaveFarEast := SysLocale.FarEast;
try
SysLocale.FarEast := False;
inherited; // inherited tries to work around Win95 FarEast bug, but introduces others
finally
SysLocale.FarEast := SaveFarEast;
end;
end;
procedure TTntCustomDBComboBox.WndProc(var Message: TMessage);
begin
if (not (csDesigning in ComponentState))
and (Message.Msg = CB_SHOWDROPDOWN)
and (Message.WParam = 0)
and (not FDataLink.Editing) then begin
DataChange(Self); {Restore text}
Dispatch(Message); {Do NOT call inherited!}
end else
inherited WndProc(Message);
end;
procedure TTntCustomDBComboBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer);
begin
if not TntCombo_ComboWndProc(Self, Message, ComboWnd, ComboProc, DoEditCharMsg) then
inherited;
end;
procedure TTntCustomDBComboBox.KeyPress(var Key: AnsiChar);
var
SaveAutoComplete: Boolean;
begin
TntCombo_BeforeKeyPress(Self, SaveAutoComplete);
try
inherited;
finally
TntCombo_AfterKeyPress(Self, SaveAutoComplete);
end;
end;
procedure TTntCustomDBComboBox.DoEditCharMsg(var Message: TWMChar);
begin
{$IFDEF COMPILER_6_UP}
TntCombo_AutoCompleteKeyPress(Self, Items, Message,
GetAutoComplete_UniqueMatchOnly, GetAutoComplete_PreserveDataEntryCase);
{$ENDIF}
end;
procedure TTntCustomDBComboBox.WMChar(var Message: TWMChar);
begin
{$IFDEF COMPILER_6_UP}
TntCombo_AutoSearchKeyPress(Self, Items, Message, FFilter, FLastTime);
{$ENDIF}
inherited;
end;
function TTntCustomDBComboBox.GetItems: TTntStrings;
begin
Result := FItems;
end;
procedure TTntCustomDBComboBox.SetItems(const Value: TTntStrings);
begin
FItems.Assign(Value);
DataChange(Self);
end;
function TTntCustomDBComboBox.GetSelStart: Integer;
begin
Result := TntCombo_GetSelStart(Self);
end;
procedure TTntCustomDBComboBox.SetSelStart(const Value: Integer);
begin
TntCombo_SetSelStart(Self, Value);
end;
function TTntCustomDBComboBox.GetSelLength: Integer;
begin
Result := TntCombo_GetSelLength(Self);
end;
procedure TTntCustomDBComboBox.SetSelLength(const Value: Integer);
begin
TntCombo_SetSelLength(Self, Value);
end;
function TTntCustomDBComboBox.GetSelText: WideString;
begin
Result := TntCombo_GetSelText(Self);
end;
procedure TTntCustomDBComboBox.SetSelText(const Value: WideString);
begin
TntCombo_SetSelText(Self, Value);
end;
function TTntCustomDBComboBox.GetText: WideString;
begin
Result := TntControl_GetText(Self);
end;
procedure TTntCustomDBComboBox.SetText(const Value: WideString);
begin
TntControl_SetText(Self, Value);
end;
procedure TTntCustomDBComboBox.CNCommand(var Message: TWMCommand);
begin
if not TntCombo_CNCommand(Self, Items, Message) then
inherited;
end;
function TTntCustomDBComboBox.GetFieldValue: Variant;
begin
Result := Field.Value;
end;
procedure TTntCustomDBComboBox.SetFieldValue(const Value: Variant);
begin
Field.Value := Value;
end;
procedure TTntCustomDBComboBox.DataChange(Sender: TObject);
begin
if not (Style = csSimple) and DroppedDown then Exit;
if Field <> nil then
SetComboValue(GetFieldValue)
else
if csDesigning in ComponentState then
SetComboValue(Name)
else
SetComboValue(Null);
end;
procedure TTntCustomDBComboBox.UpdateData(Sender: TObject);
begin
SetFieldValue(GetComboValue);
end;
function TTntCustomDBComboBox.GetAutoComplete_PreserveDataEntryCase: Boolean;
begin
Result := True;
end;
function TTntCustomDBComboBox.GetAutoComplete_UniqueMatchOnly: Boolean;
begin
Result := False;
end;
function TTntCustomDBComboBox.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self);
end;
function TTntCustomDBComboBox.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntCustomDBComboBox.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntCustomDBComboBox.AddItem(const Item: WideString; AObject: TObject);
begin
TntComboBox_AddItem(Items, Item, AObject);
end;
{$IFDEF COMPILER_6_UP}
procedure TTntCustomDBComboBox.CopySelection(Destination: TCustomListControl);
begin
TntComboBox_CopySelection(Items, ItemIndex, Destination);
end;
{$ENDIF}
procedure TTntCustomDBComboBox.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
function TTntCustomDBComboBox.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
{$IFDEF DELPHI_7}
function TTntCustomDBComboBox.GetItemsClass: TCustomComboBoxStringsClass;
begin
Result := TD7PatchedComboBoxStrings;
end;
{$ENDIF}
{ TTntDBComboBox }
function TTntDBComboBox.GetFieldValue: Variant;
begin
Result := GetWideText(Field);
end;
procedure TTntDBComboBox.SetFieldValue(const Value: Variant);
begin
SetWideText(Field, Value);
end;
procedure TTntDBComboBox.SetComboValue(const Value: Variant);
var
I: Integer;
Redraw: Boolean;
OldValue: WideString;
NewValue: WideString;
begin
OldValue := VarToWideStr(GetComboValue);
NewValue := VarToWideStr(Value);
if NewValue <> OldValue then
begin
if Style <> csDropDown then
begin
Redraw := (Style <> csSimple) and HandleAllocated;
if Redraw then Items.BeginUpdate;
try
if NewValue = '' then I := -1 else I := Items.IndexOf(NewValue);
ItemIndex := I;
finally
Items.EndUpdate;
end;
if I >= 0 then Exit;
end;
if Style in [csDropDown, csSimple] then Text := NewValue;
end;
end;
function TTntDBComboBox.GetComboValue: Variant;
var
I: Integer;
begin
if Style in [csDropDown, csSimple] then Result := Text else
begin
I := ItemIndex;
if I < 0 then Result := '' else Result := Items[I];
end;
end;
{ TTntDBCheckBox }
procedure TTntDBCheckBox.CreateWindowHandle(const Params: TCreateParams);
begin
CreateUnicodeHandle(Self, Params, 'BUTTON');
end;
procedure TTntDBCheckBox.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
function TTntDBCheckBox.IsCaptionStored: Boolean;
begin
Result := TntControl_IsCaptionStored(Self);
end;
function TTntDBCheckBox.GetCaption: TWideCaption;
begin
Result := TntControl_GetText(Self)
end;
procedure TTntDBCheckBox.SetCaption(const Value: TWideCaption);
begin
TntControl_SetText(Self, Value);
end;
function TTntDBCheckBox.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self);
end;
function TTntDBCheckBox.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntDBCheckBox.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntDBCheckBox.Toggle;
var
FDataLink: TDataLink;
begin
inherited;
FDataLink := TDataLink(Perform(CM_GETDATALINK, 0, 0)) as TFieldDataLink;
FDataLink.UpdateRecord;
end;
procedure TTntDBCheckBox.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
function TTntDBCheckBox.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
{ TTntDBRichEdit }
constructor TTntDBRichEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
inherited ReadOnly := True;
FAutoDisplay := True;
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnEditingChange := EditingChange;
FDataLink.OnUpdateData := UpdateData;
end;
destructor TTntDBRichEdit.Destroy;
begin
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
procedure TTntDBRichEdit.Loaded;
begin
inherited Loaded;
if (csDesigning in ComponentState) then
DataChange(Self)
end;
procedure TTntDBRichEdit.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (FDataLink <> nil) and
(AComponent = DataSource) then DataSource := nil;
end;
function TTntDBRichEdit.UseRightToLeftAlignment: Boolean;
begin
Result := DBUseRightToLeftAlignment(Self, Field);
end;
procedure TTntDBRichEdit.BeginEditing;
begin
if not FDataLink.Editing then
try
if FieldIsBlobLike(Field) then
FDataSave := Field.AsString{TNT-ALLOW AsString};
FDataLink.Edit;
finally
FDataSave := '';
end;
end;
procedure TTntDBRichEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
if FMemoLoaded then
begin
if (Key = VK_DELETE) or (Key = VK_BACK) or
((Key = VK_INSERT) and (ssShift in Shift)) or
(((Key = Ord('V')) or (Key = Ord('X'))) and (ssCtrl in Shift)) then
BeginEditing;
end;
end;
procedure TTntDBRichEdit.KeyPress(var Key: AnsiChar);
begin
inherited KeyPress(Key);
if FMemoLoaded then
begin
if (Key in [#32..#255]) and (Field <> nil) and
not Field.IsValidChar(Key) then
begin
MessageBeep(0);
Key := #0;
end;
case Key of
^H, ^I, ^J, ^M, ^V, ^X, #32..#255:
BeginEditing;
#27:
FDataLink.Reset;
end;
end else
begin
if Key = #13 then LoadMemo;
Key := #0;
end;
end;
procedure TTntDBRichEdit.Change;
begin
if FMemoLoaded then
FDataLink.Modified;
FMemoLoaded := True;
inherited Change;
end;
procedure TTntDBRichEdit.CNNotify(var Message: TWMNotify);
begin
inherited;
if Message.NMHdr^.code = EN_PROTECTED then
Message.Result := 0 { allow the operation (otherwise the control might appear stuck) }
end;
function TTntDBRichEdit.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TTntDBRichEdit.SetDataSource(Value: TDataSource);
begin
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
end;
function TTntDBRichEdit.GetDataField: string{TNT-ALLOW string};
begin
Result := FDataLink.FieldName;
end;
procedure TTntDBRichEdit.SetDataField(const Value: string{TNT-ALLOW string});
begin
FDataLink.FieldName := Value;
end;
function TTntDBRichEdit.GetReadOnly: Boolean;
begin
Result := FDataLink.ReadOnly;
end;
procedure TTntDBRichEdit.SetReadOnly(Value: Boolean);
begin
FDataLink.ReadOnly := Value;
end;
function TTntDBRichEdit.GetField: TField;
begin
Result := FDataLink.Field;
end;
procedure TTntDBRichEdit.InternalLoadMemo;
var
Stream: TStringStream{TNT-ALLOW TStringStream};
begin
Stream := TStringStream{TNT-ALLOW TStringStream}.Create(Field.AsString{TNT-ALLOW AsString});
try
Lines.LoadFromStream(Stream);
finally
Stream.Free;
end;
end;
procedure TTntDBRichEdit.LoadMemo;
begin
if not FMemoLoaded and Assigned(Field) and FieldIsBlobLike(Field) then
begin
try
InternalLoadMemo;
FMemoLoaded := True;
except
{ Rich Edit Load failure }
on E:EOutOfResources do
Lines.Text := WideFormat('(%s)', [E.Message]);
end;
EditingChange(Self);
end;
end;
procedure TTntDBRichEdit.DataChange(Sender: TObject);
begin
if Field <> nil then
if FieldIsBlobLike(Field) then
begin
if FAutoDisplay or (FDataLink.Editing and FMemoLoaded) then
begin
{ Check if the data has changed since we read it the first time }
if (FDataSave <> '') and (FDataSave = Field.AsString{TNT-ALLOW AsString}) then Exit;
FMemoLoaded := False;
LoadMemo;
end else
begin
Text := WideFormat('(%s)', [Field.DisplayLabel]);
FMemoLoaded := False;
end;
end else
begin
if FFocused and FDataLink.CanModify then
Text := GetWideText(Field)
else
Text := GetWideDisplayText(Field);
FMemoLoaded := True;
end
else
begin
if csDesigning in ComponentState then Text := Name else Text := '';
FMemoLoaded := False;
end;
if HandleAllocated then
RedrawWindow(Handle, nil, 0, RDW_INVALIDATE or RDW_ERASE or RDW_FRAME);
end;
procedure TTntDBRichEdit.EditingChange(Sender: TObject);
begin
inherited ReadOnly := not (FDataLink.Editing and FMemoLoaded);
end;
procedure TTntDBRichEdit.InternalSaveMemo;
var
Stream: TStringStream{TNT-ALLOW TStringStream};
begin
Stream := TStringStream{TNT-ALLOW TStringStream}.Create('');
try
Lines.SaveToStream(Stream);
Field.AsString{TNT-ALLOW AsString} := Stream.DataString;
finally
Stream.Free;
end;
end;
procedure TTntDBRichEdit.UpdateData(Sender: TObject);
begin
if FieldIsBlobLike(Field) then
InternalSaveMemo
else
SetAsWideString(Field, Text);
end;
procedure TTntDBRichEdit.SetFocused(Value: Boolean);
begin
if FFocused <> Value then
begin
FFocused := Value;
if not Assigned(Field) or not FieldIsBlobLike(Field) then
FDataLink.Reset;
end;
end;
procedure TTntDBRichEdit.CMEnter(var Message: TCMEnter);
begin
SetFocused(True);
inherited;
end;
procedure TTntDBRichEdit.CMExit(var Message: TCMExit);
begin
try
FDataLink.UpdateRecord;
except
SetFocus;
raise;
end;
SetFocused(False);
inherited;
end;
procedure TTntDBRichEdit.SetAutoDisplay(Value: Boolean);
begin
if FAutoDisplay <> Value then
begin
FAutoDisplay := Value;
if Value then LoadMemo;
end;
end;
procedure TTntDBRichEdit.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
if not FMemoLoaded then LoadMemo else inherited;
end;
procedure TTntDBRichEdit.WMCut(var Message: TMessage);
begin
BeginEditing;
inherited;
end;
procedure TTntDBRichEdit.WMPaste(var Message: TMessage);
begin
BeginEditing;
inherited;
end;
procedure TTntDBRichEdit.CMGetDataLink(var Message: TMessage);
begin
Message.Result := Integer(FDataLink);
end;
function TTntDBRichEdit.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or (FDataLink <> nil) and
FDataLink.ExecuteAction(Action);
end;
function TTntDBRichEdit.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or (FDataLink <> nil) and
FDataLink.UpdateAction(Action);
end;
{ TTntDBMemo }
constructor TTntDBMemo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
inherited ReadOnly := True;
ControlStyle := ControlStyle + [csReplicatable];
FAutoDisplay := True;
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnEditingChange := EditingChange;
FDataLink.OnUpdateData := UpdateData;
FPaintControl := TTntPaintControl.Create(Self, 'EDIT');
end;
destructor TTntDBMemo.Destroy;
begin
FPaintControl.Free;
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
procedure TTntDBMemo.Loaded;
begin
inherited Loaded;
if (csDesigning in ComponentState) then DataChange(Self);
end;
procedure TTntDBMemo.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (FDataLink <> nil) and
(AComponent = DataSource) then DataSource := nil;
end;
function TTntDBMemo.UseRightToLeftAlignment: Boolean;
begin
Result := DBUseRightToLeftAlignment(Self, Field);
end;
procedure TTntDBMemo.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
if FMemoLoaded then
begin
if (Key = VK_DELETE) or ((Key = VK_INSERT) and (ssShift in Shift)) then
FDataLink.Edit;
end;
end;
procedure TTntDBMemo.KeyPress(var Key: Char{TNT-ALLOW Char});
begin
inherited KeyPress(Key);
if FMemoLoaded then
begin
if (Key in [#32..#255]) and (FDataLink.Field <> nil) and
not FDataLink.Field.IsValidChar(Key) then
begin
MessageBeep(0);
Key := #0;
end;
case Key of
^H, ^I, ^J, ^M, ^V, ^X, #32..#255:
FDataLink.Edit;
#27:
FDataLink.Reset;
end;
end else
begin
if Key = #13 then LoadMemo;
Key := #0;
end;
end;
procedure TTntDBMemo.Change;
begin
if FMemoLoaded then FDataLink.Modified;
FMemoLoaded := True;
inherited Change;
end;
function TTntDBMemo.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TTntDBMemo.SetDataSource(Value: TDataSource);
begin
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
end;
function TTntDBMemo.GetDataField: string{TNT-ALLOW string};
begin
Result := FDataLink.FieldName;
end;
procedure TTntDBMemo.SetDataField(const Value: string{TNT-ALLOW string});
begin
FDataLink.FieldName := Value;
end;
function TTntDBMemo.GetReadOnly: Boolean;
begin
Result := FDataLink.ReadOnly;
end;
procedure TTntDBMemo.SetReadOnly(Value: Boolean);
begin
FDataLink.ReadOnly := Value;
end;
function TTntDBMemo.GetField: TField;
begin
Result := FDataLink.Field;
end;
procedure TTntDBMemo.LoadMemo;
begin
if not FMemoLoaded and Assigned(FDataLink.Field) and FieldIsBlobLike(FDataLink.Field) then
begin
try
Lines.Text := GetAsWideString(FDataLink.Field);
FMemoLoaded := True;
except
{ Memo too large }
on E:EInvalidOperation do
Lines.Text := WideFormat('(%s)', [E.Message]);
end;
EditingChange(Self);
end;
end;
procedure TTntDBMemo.DataChange(Sender: TObject);
begin
if FDataLink.Field <> nil then
if FieldIsBlobLike(FDataLink.Field) then
begin
if FAutoDisplay or (FDataLink.Editing and FMemoLoaded) then
begin
FMemoLoaded := False;
LoadMemo;
end else
begin
Text := WideFormat('(%s)', [FDataLink.Field.DisplayLabel]);
FMemoLoaded := False;
EditingChange(Self);
end;
end else
begin
if FFocused and FDataLink.CanModify then
Text := GetWideText(FDataLink.Field)
else
Text := GetWideDisplayText(FDataLink.Field);
FMemoLoaded := True;
end
else
begin
if csDesigning in ComponentState then Text := Name else Text := '';
FMemoLoaded := False;
end;
if HandleAllocated then
RedrawWindow(Handle, nil, 0, RDW_INVALIDATE or RDW_ERASE or RDW_FRAME);
end;
procedure TTntDBMemo.EditingChange(Sender: TObject);
begin
inherited ReadOnly := not (FDataLink.Editing and FMemoLoaded);
end;
procedure TTntDBMemo.UpdateData(Sender: TObject);
begin
SetAsWideString(FDataLink.Field, Text);
end;
procedure TTntDBMemo.SetFocused(Value: Boolean);
begin
if FFocused <> Value then
begin
FFocused := Value;
if not Assigned(FDataLink.Field) or not FieldIsBlobLike(FDataLink.Field) then
FDataLink.Reset;
end;
end;
procedure TTntDBMemo.WndProc(var Message: TMessage);
begin
with Message do
if (Msg = WM_CREATE) or (Msg = WM_WINDOWPOSCHANGED) or
(Msg = CM_FONTCHANGED) then FPaintControl.DestroyHandle;
inherited;
end;
procedure TTntDBMemo.CMEnter(var Message: TCMEnter);
begin
SetFocused(True);
inherited;
end;
procedure TTntDBMemo.CMExit(var Message: TCMExit);
begin
try
FDataLink.UpdateRecord;
except
SetFocus;
raise;
end;
SetFocused(False);
inherited;
end;
procedure TTntDBMemo.SetAutoDisplay(Value: Boolean);
begin
if FAutoDisplay <> Value then
begin
FAutoDisplay := Value;
if Value then LoadMemo;
end;
end;
procedure TTntDBMemo.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
if not FMemoLoaded then LoadMemo else inherited;
end;
procedure TTntDBMemo.WMCut(var Message: TMessage);
begin
FDataLink.Edit;
inherited;
end;
procedure TTntDBMemo.WMUndo(var Message: TMessage);
begin
FDataLink.Edit;
inherited;
end;
procedure TTntDBMemo.WMPaste(var Message: TMessage);
begin
FDataLink.Edit;
inherited;
end;
procedure TTntDBMemo.CMGetDataLink(var Message: TMessage);
begin
Message.Result := Integer(FDataLink);
end;
procedure TTntDBMemo.WMPaint(var Message: TWMPaint);
var
S: WideString;
begin
if not (csPaintCopy in ControlState) then
inherited
else begin
if FDataLink.Field <> nil then
if FieldIsBlobLike(FDataLink.Field) then
begin
if FAutoDisplay then
S := TntAdjustLineBreaks(GetAsWideString(FDataLink.Field)) else
S := WideFormat('(%s)', [FDataLink.Field.DisplayLabel]);
end else
S := GetWideDisplayText(FDataLink.Field);
if (not Win32PlatformIsUnicode) then
SendMessageA(FPaintControl.Handle, WM_SETTEXT, 0, Integer(PAnsiChar(AnsiString(S))))
else
SendMessageW(FPaintControl.Handle, WM_SETTEXT, 0, Integer(PWideChar(S)));
SendMessage(FPaintControl.Handle, WM_ERASEBKGND, Message.DC, 0);
SendMessage(FPaintControl.Handle, WM_PAINT, Message.DC, 0);
end;
end;
function TTntDBMemo.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or (FDataLink <> nil) and
FDataLink.ExecuteAction(Action);
end;
function TTntDBMemo.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or (FDataLink <> nil) and
FDataLink.UpdateAction(Action);
end;
{ TTntDBRadioGroup }
constructor TTntDBRadioGroup.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnUpdateData := UpdateData;
FValues := TTntStringList.Create;
end;
destructor TTntDBRadioGroup.Destroy;
begin
FDataLink.Free;
FDataLink := nil;
FValues.Free;
inherited Destroy;
end;
procedure TTntDBRadioGroup.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (FDataLink <> nil) and
(AComponent = DataSource) then DataSource := nil;
end;
function TTntDBRadioGroup.UseRightToLeftAlignment: Boolean;
begin
Result := inherited UseRightToLeftAlignment;
end;
procedure TTntDBRadioGroup.DataChange(Sender: TObject);
begin
if FDataLink.Field <> nil then
Value := GetWideText(FDataLink.Field) else
Value := '';
end;
procedure TTntDBRadioGroup.UpdateData(Sender: TObject);
begin
if FDataLink.Field <> nil then
SetWideText(FDataLink.Field, Value);
end;
function TTntDBRadioGroup.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TTntDBRadioGroup.SetDataSource(Value: TDataSource);
begin
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
end;
function TTntDBRadioGroup.GetDataField: string{TNT-ALLOW string};
begin
Result := FDataLink.FieldName;
end;
procedure TTntDBRadioGroup.SetDataField(const Value: string{TNT-ALLOW string});
begin
FDataLink.FieldName := Value;
end;
function TTntDBRadioGroup.GetReadOnly: Boolean;
begin
Result := FDataLink.ReadOnly;
end;
procedure TTntDBRadioGroup.SetReadOnly(Value: Boolean);
begin
FDataLink.ReadOnly := Value;
end;
function TTntDBRadioGroup.GetField: TField;
begin
Result := FDataLink.Field;
end;
function TTntDBRadioGroup.GetButtonValue(Index: Integer): WideString;
begin
if (Index < FValues.Count) and (FValues[Index] <> '') then
Result := FValues[Index]
else if Index < Items.Count then
Result := Items[Index]
else
Result := '';
end;
procedure TTntDBRadioGroup.SetValue(const Value: WideString);
var
WasFocused: Boolean;
I, Index: Integer;
begin
if FValue <> Value then
begin
FInSetValue := True;
try
WasFocused := (ItemIndex > -1) and (Buttons[ItemIndex].Focused);
Index := -1;
for I := 0 to Items.Count - 1 do
if Value = GetButtonValue(I) then
begin
Index := I;
Break;
end;
ItemIndex := Index;
// Move the focus rect along with the selected index
if WasFocused then
Buttons[ItemIndex].SetFocus;
finally
FInSetValue := False;
end;
FValue := Value;
Change;
end;
end;
procedure TTntDBRadioGroup.CMExit(var Message: TCMExit);
begin
try
FDataLink.UpdateRecord;
except
if ItemIndex >= 0 then
(Controls[ItemIndex] as TTntRadioButton).SetFocus else
(Controls[0] as TTntRadioButton).SetFocus;
raise;
end;
inherited;
end;
procedure TTntDBRadioGroup.CMGetDataLink(var Message: TMessage);
begin
Message.Result := Integer(FDataLink);
end;
procedure TTntDBRadioGroup.Click;
begin
if not FInSetValue then
begin
inherited Click;
if ItemIndex >= 0 then Value := GetButtonValue(ItemIndex);
if FDataLink.Editing then FDataLink.Modified;
end;
end;
procedure TTntDBRadioGroup.SetItems(Value: TTntStrings);
begin
Items.Assign(Value);
DataChange(Self);
end;
procedure TTntDBRadioGroup.SetValues(Value: TTntStrings);
begin
FValues.Assign(Value);
DataChange(Self);
end;
procedure TTntDBRadioGroup.Change;
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TTntDBRadioGroup.KeyPress(var Key: Char{TNT-ALLOW Char});
begin
inherited KeyPress(Key);
case Key of
#8, ' ': FDataLink.Edit;
#27: FDataLink.Reset;
end;
end;
function TTntDBRadioGroup.CanModify: Boolean;
begin
Result := FDataLink.Edit;
end;
function TTntDBRadioGroup.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or (DataLink <> nil) and
DataLink.ExecuteAction(Action);
end;
function TTntDBRadioGroup.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or (DataLink <> nil) and
DataLink.UpdateAction(Action);
end;
end.
|