├── .gitignore ├── CompInstall.ini ├── DzMiniTable.dcr ├── DzMiniTable.dpk ├── DzMiniTable.dproj ├── DzMiniTable.pas ├── DzMiniTable.res ├── Example ├── DATA.TXT ├── MiniTable_Example.dpr ├── MiniTable_Example.dproj ├── MiniTable_Example.res ├── UFrmEdit.dfm ├── UFrmEdit.pas ├── UFrmExample.dfm └── UFrmExample.pas ├── LICENSE.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.identcache 2 | *.local 3 | *.stat 4 | /Win32 5 | /Win64 6 | /Design 7 | */Win32 8 | -------------------------------------------------------------------------------- /CompInstall.ini: -------------------------------------------------------------------------------- 1 | [General] 2 | Name=Digao Dalpiaz - DzMiniTable component 3 | Version=1.8 4 | DelphiVersions=XE3;XE4;XE5;XE6;XE7;XE8;10;10.1;10.2;10.3;10.4;11 5 | Packages=DzMiniTable 6 | AddLibrary=1 7 | 8 | [P_DzMiniTable] 9 | Allow64bit=1 10 | Install=1 11 | 12 | [GitHub] 13 | Repository=digao-dalpiaz/DzMiniTable 14 | -------------------------------------------------------------------------------- /DzMiniTable.dcr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digao-dalpiaz/DzMiniTable/5ac9c4c0f65a3d342598f80d39afcb088509b7b5/DzMiniTable.dcr -------------------------------------------------------------------------------- /DzMiniTable.dpk: -------------------------------------------------------------------------------- 1 | package DzMiniTable; 2 | 3 | {$R *.res} 4 | {$R 'DzMiniTable.dcr'} 5 | {$IFDEF IMPLICITBUILDING This IFDEF should not be used by users} 6 | {$ALIGN 8} 7 | {$ASSERTIONS ON} 8 | {$BOOLEVAL OFF} 9 | {$DEBUGINFO OFF} 10 | {$EXTENDEDSYNTAX ON} 11 | {$IMPORTEDDATA ON} 12 | {$IOCHECKS ON} 13 | {$LOCALSYMBOLS OFF} 14 | {$LONGSTRINGS ON} 15 | {$OPENSTRINGS ON} 16 | {$OPTIMIZATION ON} 17 | {$OVERFLOWCHECKS OFF} 18 | {$RANGECHECKS OFF} 19 | {$REFERENCEINFO OFF} 20 | {$SAFEDIVIDE OFF} 21 | {$STACKFRAMES OFF} 22 | {$TYPEDADDRESS OFF} 23 | {$VARSTRINGCHECKS ON} 24 | {$WRITEABLECONST OFF} 25 | {$MINENUMSIZE 1} 26 | {$IMAGEBASE $400000} 27 | {$DEFINE RELEASE} 28 | {$ENDIF IMPLICITBUILDING} 29 | {$DESCRIPTION 'Digao Dalpiaz - DzMiniTable component'} 30 | {$IMPLICITBUILD ON} 31 | 32 | requires 33 | rtl; 34 | 35 | contains 36 | DzMiniTable in 'DzMiniTable.pas'; 37 | 38 | end. 39 | -------------------------------------------------------------------------------- /DzMiniTable.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {A9673B4A-EEFB-41C9-A4B8-AFE42267A378} 4 | DzMiniTable.dpk 5 | 18.8 6 | None 7 | True 8 | Release 9 | Win32 10 | 1 11 | Package 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Cfg_1 29 | true 30 | true 31 | 32 | 33 | true 34 | Base 35 | true 36 | 37 | 38 | true 39 | Cfg_2 40 | true 41 | true 42 | 43 | 44 | .\$(Platform)\$(Config) 45 | .\$(Platform)\$(Config) 46 | false 47 | false 48 | false 49 | false 50 | false 51 | true 52 | true 53 | System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) 54 | 1046 55 | DzMiniTable 56 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 57 | 58 | 59 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 60 | Debug 61 | true 62 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 63 | 1033 64 | rtl;$(DCC_UsePackage) 65 | 66 | 67 | DEBUG;$(DCC_Define) 68 | true 69 | false 70 | true 71 | true 72 | true 73 | 74 | 75 | false 76 | 77 | 78 | false 79 | RELEASE;$(DCC_Define) 80 | 0 81 | 82 | 83 | true 84 | 1033 85 | Digao Dalpiaz - DzMiniTable component 86 | 87 | 88 | 89 | MainSource 90 | 91 | 92 | 93 | 94 | 95 | Cfg_2 96 | Base 97 | 98 | 99 | Base 100 | 101 | 102 | Cfg_1 103 | Base 104 | 105 | 106 | 107 | Delphi.Personality.12 108 | Package 109 | 110 | 111 | 112 | DzMiniTable.dpk 113 | 114 | 115 | Microsoft Office 2000 Sample Automation Server Wrapper Components 116 | Microsoft Office XP Sample Automation Server Wrapper Components 117 | 118 | 119 | 120 | 121 | 122 | true 123 | 124 | 125 | 126 | 127 | true 128 | 129 | 130 | 131 | 132 | true 133 | 134 | 135 | 136 | 137 | true 138 | 139 | 140 | 141 | 142 | true 143 | 144 | 145 | 146 | 147 | true 148 | 149 | 150 | 151 | 152 | DzMiniTable.bpl 153 | true 154 | 155 | 156 | 157 | 158 | 1 159 | 160 | 161 | 0 162 | 163 | 164 | 165 | 166 | classes 167 | 1 168 | 169 | 170 | classes 171 | 1 172 | 173 | 174 | 175 | 176 | res\xml 177 | 1 178 | 179 | 180 | res\xml 181 | 1 182 | 183 | 184 | 185 | 186 | library\lib\armeabi-v7a 187 | 1 188 | 189 | 190 | 191 | 192 | library\lib\armeabi 193 | 1 194 | 195 | 196 | library\lib\armeabi 197 | 1 198 | 199 | 200 | 201 | 202 | library\lib\armeabi-v7a 203 | 1 204 | 205 | 206 | 207 | 208 | library\lib\mips 209 | 1 210 | 211 | 212 | library\lib\mips 213 | 1 214 | 215 | 216 | 217 | 218 | library\lib\armeabi-v7a 219 | 1 220 | 221 | 222 | library\lib\arm64-v8a 223 | 1 224 | 225 | 226 | 227 | 228 | library\lib\armeabi-v7a 229 | 1 230 | 231 | 232 | 233 | 234 | res\drawable 235 | 1 236 | 237 | 238 | res\drawable 239 | 1 240 | 241 | 242 | 243 | 244 | res\values 245 | 1 246 | 247 | 248 | res\values 249 | 1 250 | 251 | 252 | 253 | 254 | res\values-v21 255 | 1 256 | 257 | 258 | res\values-v21 259 | 1 260 | 261 | 262 | 263 | 264 | res\values 265 | 1 266 | 267 | 268 | res\values 269 | 1 270 | 271 | 272 | 273 | 274 | res\drawable 275 | 1 276 | 277 | 278 | res\drawable 279 | 1 280 | 281 | 282 | 283 | 284 | res\drawable-xxhdpi 285 | 1 286 | 287 | 288 | res\drawable-xxhdpi 289 | 1 290 | 291 | 292 | 293 | 294 | res\drawable-ldpi 295 | 1 296 | 297 | 298 | res\drawable-ldpi 299 | 1 300 | 301 | 302 | 303 | 304 | res\drawable-mdpi 305 | 1 306 | 307 | 308 | res\drawable-mdpi 309 | 1 310 | 311 | 312 | 313 | 314 | res\drawable-hdpi 315 | 1 316 | 317 | 318 | res\drawable-hdpi 319 | 1 320 | 321 | 322 | 323 | 324 | res\drawable-xhdpi 325 | 1 326 | 327 | 328 | res\drawable-xhdpi 329 | 1 330 | 331 | 332 | 333 | 334 | res\drawable-mdpi 335 | 1 336 | 337 | 338 | res\drawable-mdpi 339 | 1 340 | 341 | 342 | 343 | 344 | res\drawable-hdpi 345 | 1 346 | 347 | 348 | res\drawable-hdpi 349 | 1 350 | 351 | 352 | 353 | 354 | res\drawable-xhdpi 355 | 1 356 | 357 | 358 | res\drawable-xhdpi 359 | 1 360 | 361 | 362 | 363 | 364 | res\drawable-xxhdpi 365 | 1 366 | 367 | 368 | res\drawable-xxhdpi 369 | 1 370 | 371 | 372 | 373 | 374 | res\drawable-xxxhdpi 375 | 1 376 | 377 | 378 | res\drawable-xxxhdpi 379 | 1 380 | 381 | 382 | 383 | 384 | res\drawable-small 385 | 1 386 | 387 | 388 | res\drawable-small 389 | 1 390 | 391 | 392 | 393 | 394 | res\drawable-normal 395 | 1 396 | 397 | 398 | res\drawable-normal 399 | 1 400 | 401 | 402 | 403 | 404 | res\drawable-large 405 | 1 406 | 407 | 408 | res\drawable-large 409 | 1 410 | 411 | 412 | 413 | 414 | res\drawable-xlarge 415 | 1 416 | 417 | 418 | res\drawable-xlarge 419 | 1 420 | 421 | 422 | 423 | 424 | res\values 425 | 1 426 | 427 | 428 | res\values 429 | 1 430 | 431 | 432 | 433 | 434 | 1 435 | 436 | 437 | 1 438 | 439 | 440 | 0 441 | 442 | 443 | 444 | 445 | 1 446 | .framework 447 | 448 | 449 | 1 450 | .framework 451 | 452 | 453 | 0 454 | 455 | 456 | 457 | 458 | 1 459 | .dylib 460 | 461 | 462 | 1 463 | .dylib 464 | 465 | 466 | 0 467 | .dll;.bpl 468 | 469 | 470 | 471 | 472 | 1 473 | .dylib 474 | 475 | 476 | 1 477 | .dylib 478 | 479 | 480 | 1 481 | .dylib 482 | 483 | 484 | 1 485 | .dylib 486 | 487 | 488 | 1 489 | .dylib 490 | 491 | 492 | 0 493 | .bpl 494 | 495 | 496 | 497 | 498 | 0 499 | 500 | 501 | 0 502 | 503 | 504 | 0 505 | 506 | 507 | 0 508 | 509 | 510 | 0 511 | 512 | 513 | 0 514 | 515 | 516 | 0 517 | 518 | 519 | 0 520 | 521 | 522 | 523 | 524 | 1 525 | 526 | 527 | 1 528 | 529 | 530 | 1 531 | 532 | 533 | 534 | 535 | 1 536 | 537 | 538 | 1 539 | 540 | 541 | 1 542 | 543 | 544 | 545 | 546 | 1 547 | 548 | 549 | 1 550 | 551 | 552 | 1 553 | 554 | 555 | 556 | 557 | 1 558 | 559 | 560 | 1 561 | 562 | 563 | 1 564 | 565 | 566 | 567 | 568 | 1 569 | 570 | 571 | 1 572 | 573 | 574 | 1 575 | 576 | 577 | 578 | 579 | 1 580 | 581 | 582 | 1 583 | 584 | 585 | 1 586 | 587 | 588 | 589 | 590 | 1 591 | 592 | 593 | 1 594 | 595 | 596 | 1 597 | 598 | 599 | 600 | 601 | 1 602 | 603 | 604 | 1 605 | 606 | 607 | 1 608 | 609 | 610 | 611 | 612 | 1 613 | 614 | 615 | 1 616 | 617 | 618 | 1 619 | 620 | 621 | 622 | 623 | 1 624 | 625 | 626 | 1 627 | 628 | 629 | 1 630 | 631 | 632 | 633 | 634 | 1 635 | 636 | 637 | 1 638 | 639 | 640 | 1 641 | 642 | 643 | 644 | 645 | 1 646 | 647 | 648 | 1 649 | 650 | 651 | 1 652 | 653 | 654 | 655 | 656 | 1 657 | 658 | 659 | 1 660 | 661 | 662 | 1 663 | 664 | 665 | 666 | 667 | 1 668 | 669 | 670 | 1 671 | 672 | 673 | 1 674 | 675 | 676 | 677 | 678 | 1 679 | 680 | 681 | 1 682 | 683 | 684 | 1 685 | 686 | 687 | 688 | 689 | 1 690 | 691 | 692 | 1 693 | 694 | 695 | 1 696 | 697 | 698 | 699 | 700 | 1 701 | 702 | 703 | 1 704 | 705 | 706 | 1 707 | 708 | 709 | 710 | 711 | 1 712 | 713 | 714 | 1 715 | 716 | 717 | 1 718 | 719 | 720 | 721 | 722 | 1 723 | 724 | 725 | 1 726 | 727 | 728 | 1 729 | 730 | 731 | 732 | 733 | 1 734 | 735 | 736 | 1 737 | 738 | 739 | 1 740 | 741 | 742 | 743 | 744 | 1 745 | 746 | 747 | 1 748 | 749 | 750 | 1 751 | 752 | 753 | 754 | 755 | 1 756 | 757 | 758 | 1 759 | 760 | 761 | 1 762 | 763 | 764 | 765 | 766 | 1 767 | 768 | 769 | 1 770 | 771 | 772 | 1 773 | 774 | 775 | 776 | 777 | 1 778 | 779 | 780 | 1 781 | 782 | 783 | 1 784 | 785 | 786 | 787 | 788 | 1 789 | 790 | 791 | 1 792 | 793 | 794 | 1 795 | 796 | 797 | 798 | 799 | 1 800 | 801 | 802 | 1 803 | 804 | 805 | 1 806 | 807 | 808 | 809 | 810 | 1 811 | 812 | 813 | 1 814 | 815 | 816 | 1 817 | 818 | 819 | 820 | 821 | 1 822 | 823 | 824 | 1 825 | 826 | 827 | 1 828 | 829 | 830 | 831 | 832 | 1 833 | 834 | 835 | 1 836 | 837 | 838 | 839 | 840 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 841 | 1 842 | 843 | 844 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 845 | 1 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 1 854 | 855 | 856 | 1 857 | 858 | 859 | 1 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | Contents\Resources 868 | 1 869 | 870 | 871 | Contents\Resources 872 | 1 873 | 874 | 875 | 876 | 877 | library\lib\armeabi-v7a 878 | 1 879 | 880 | 881 | library\lib\arm64-v8a 882 | 1 883 | 884 | 885 | 1 886 | 887 | 888 | 1 889 | 890 | 891 | 1 892 | 893 | 894 | 1 895 | 896 | 897 | 1 898 | 899 | 900 | 1 901 | 902 | 903 | 0 904 | 905 | 906 | 907 | 908 | library\lib\armeabi-v7a 909 | 1 910 | 911 | 912 | 913 | 914 | 1 915 | 916 | 917 | 1 918 | 919 | 920 | 921 | 922 | Assets 923 | 1 924 | 925 | 926 | Assets 927 | 1 928 | 929 | 930 | 931 | 932 | Assets 933 | 1 934 | 935 | 936 | Assets 937 | 1 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | True 953 | 954 | 955 | 12 956 | 957 | 958 | 959 | 960 | 961 | -------------------------------------------------------------------------------- /DzMiniTable.pas: -------------------------------------------------------------------------------- 1 | {------------------------------------------------------------------------------ 2 | TDzMiniTable component 3 | Developed by Rodrigo Depine Dalpiaz (digao dalpiaz) 4 | To use as a small dynamic table stored as text file 5 | 6 | https://github.com/digao-dalpiaz/DzMiniTable 7 | 8 | Please, read the documentation at GitHub link. 9 | 10 | File structure example: 11 | ID=1,Nome=Jhon 12 | ID=2,Nome=Mary 13 | ------------------------------------------------------------------------------} 14 | 15 | unit DzMiniTable; 16 | 17 | interface 18 | 19 | uses System.Classes; 20 | 21 | type 22 | TRecordStore = class 23 | private 24 | S: TStringList; 25 | 26 | procedure LoadRecordFromString(const Data: string); 27 | function GetRecordAsString: string; 28 | 29 | function ReadField(const FieldName: string): string; 30 | procedure WriteField(const FieldName, Value: string); 31 | public 32 | constructor Create; 33 | destructor Destroy; override; 34 | end; 35 | 36 | TDzMiniTable = class(TComponent) 37 | private 38 | FAbout: string; 39 | 40 | FFileName: string; 41 | FJumpOpen: Boolean; //JumpOpen - if file not exists, bypass open method (load blank table) 42 | FAutoSave: Boolean; 43 | 44 | FSelIndex: Integer; 45 | 46 | Tb: TStringList; 47 | CurRecord: TRecordStore; 48 | 49 | function GetField(const FieldName: string): Variant; 50 | procedure SetField(const FieldName: string; const Value: Variant); 51 | 52 | function GetCount: Integer; 53 | 54 | procedure Reset; 55 | 56 | procedure CheckAutoSave; 57 | function GetMemString: string; 58 | procedure SetMemString(const Value: string); 59 | procedure CheckInRecord; 60 | public 61 | constructor Create(AOwner: TComponent); override; 62 | destructor Destroy; override; 63 | 64 | property Lines: TStringList read Tb; 65 | 66 | property MemString: string read GetMemString write SetMemString; 67 | property SelIndex: Integer read FSelIndex; 68 | property Count: Integer read GetCount; 69 | property F[const FieldName: string]: Variant read GetField write SetField; 70 | 71 | procedure SelReset; 72 | function InRecord: Boolean; 73 | 74 | procedure Open; 75 | procedure Save; 76 | procedure EmptyTable; 77 | procedure EmptyRecord; 78 | function IsEmpty: Boolean; 79 | procedure Select(Index: Integer); 80 | procedure First; 81 | procedure Last; 82 | function Next: Boolean; 83 | procedure New; 84 | procedure Insert(Index: Integer); 85 | procedure Post; 86 | procedure Delete; 87 | procedure MoveDown; 88 | procedure MoveUp; 89 | 90 | function FieldExists(const FieldName: string): Boolean; 91 | function ReadDef(const FieldName: string; const Default: Variant): Variant; 92 | 93 | function FindIndex(const FieldName: string; const Value: Variant): Integer; 94 | function Locate(const FieldName: string; const Value: Variant): Boolean; 95 | function ContainsValue(const FieldName: string; const Value: Variant): Boolean; 96 | published 97 | property About: string read FAbout; 98 | 99 | property FileName: string read FFileName write FFileName; 100 | property AutoSave: Boolean read FAutoSave write FAutoSave default False; 101 | property JumpOpen: Boolean read FJumpOpen write FJumpOpen default True; 102 | end; 103 | 104 | procedure Register; 105 | 106 | implementation 107 | 108 | uses System.SysUtils; 109 | 110 | const STR_VERSION = '1.8'; 111 | 112 | procedure Register; 113 | begin 114 | RegisterComponents('Digao', [TDzMiniTable]); 115 | end; 116 | 117 | // 118 | 119 | constructor TRecordStore.Create; 120 | begin 121 | inherited; 122 | S := TStringList.Create; 123 | end; 124 | 125 | destructor TRecordStore.Destroy; 126 | begin 127 | S.Free; 128 | inherited; 129 | end; 130 | 131 | procedure TRecordStore.LoadRecordFromString(const Data: string); 132 | begin 133 | S.CommaText := Data; 134 | end; 135 | 136 | function TRecordStore.GetRecordAsString: string; 137 | begin 138 | Result := S.CommaText; 139 | end; 140 | 141 | function TRecordStore.ReadField(const FieldName: string): string; 142 | begin 143 | Result := S.Values[FieldName]; 144 | end; 145 | 146 | procedure TRecordStore.WriteField(const FieldName, Value: string); 147 | begin 148 | S.Values[FieldName] := Value; 149 | end; 150 | 151 | // 152 | 153 | constructor TDzMiniTable.Create(AOwner: TComponent); 154 | begin 155 | inherited; 156 | 157 | FAbout := 'Digao Dalpiaz / Version '+STR_VERSION; 158 | 159 | FJumpOpen := True; //default 160 | 161 | Tb := TStringList.Create; //full table 162 | CurRecord := TRecordStore.Create; //selected record 163 | 164 | FSelIndex := -1; 165 | end; 166 | 167 | destructor TDzMiniTable.Destroy; 168 | begin 169 | Tb.Free; 170 | CurRecord.Free; 171 | 172 | inherited; 173 | end; 174 | 175 | function TDzMiniTable.InRecord: Boolean; 176 | begin 177 | Result := FSelIndex<>-1; 178 | end; 179 | 180 | procedure TDzMiniTable.CheckInRecord; 181 | begin 182 | if not InRecord then 183 | raise Exception.Create('No record selected'); 184 | end; 185 | 186 | procedure TDzMiniTable.SelReset; 187 | begin 188 | if FSelIndex=-1 then Exit; 189 | 190 | CurRecord.S.Clear; //clear selected record 191 | FSelIndex := -1; 192 | end; 193 | 194 | procedure TDzMiniTable.Reset; 195 | begin 196 | Tb.Clear; 197 | SelReset; 198 | end; 199 | 200 | procedure TDzMiniTable.Open; 201 | begin 202 | Reset; //clear stringlist's and selection set 203 | 204 | if FJumpOpen then 205 | if not FileExists(FFileName) then Exit; 206 | 207 | Tb.LoadFromFile(FFileName); 208 | end; 209 | 210 | procedure TDzMiniTable.Save; 211 | begin 212 | Tb.SaveToFile(FFileName); 213 | end; 214 | 215 | function TDzMiniTable.GetMemString: string; 216 | begin 217 | Result := Tb.Text; 218 | end; 219 | 220 | procedure TDzMiniTable.SetMemString(const Value: string); 221 | begin 222 | Reset; 223 | 224 | Tb.Text := Value; 225 | end; 226 | 227 | 228 | function TDzMiniTable.GetCount: Integer; 229 | begin 230 | Result := Tb.Count; 231 | end; 232 | 233 | function TDzMiniTable.IsEmpty: Boolean; 234 | begin 235 | Result := ( Count = 0 ); 236 | end; 237 | 238 | function TDzMiniTable.GetField(const FieldName: string): Variant; 239 | begin 240 | CheckInRecord; 241 | 242 | Result := CurRecord.ReadField(FieldName); 243 | end; 244 | 245 | procedure TDzMiniTable.SetField(const FieldName: string; const Value: Variant); 246 | begin 247 | CheckInRecord; 248 | 249 | CurRecord.WriteField(FieldName, Value); 250 | end; 251 | 252 | procedure TDzMiniTable.Select(Index: Integer); 253 | begin 254 | if Index>Count-1 then raise Exception.CreateFmt('Record of index %d does not exist', [Index]); 255 | 256 | CurRecord.LoadRecordFromString(Tb[Index]); 257 | FSelIndex := Index; 258 | end; 259 | 260 | function TDzMiniTable.Next: Boolean; 261 | begin 262 | Result := ( FSelIndex < Count-1 ); 263 | 264 | if Result then 265 | Select(FSelIndex+1) 266 | else 267 | SelReset; 268 | end; 269 | 270 | procedure TDzMiniTable.First; 271 | begin 272 | if IsEmpty then raise Exception.Create('There is no record to select'); 273 | 274 | Select(0); 275 | end; 276 | 277 | procedure TDzMiniTable.Last; 278 | begin 279 | if IsEmpty then raise Exception.Create('There is no record to select'); 280 | 281 | Select(Count-1); 282 | end; 283 | 284 | procedure TDzMiniTable.New; 285 | begin 286 | Tb.Add(string.Empty); 287 | Last; 288 | end; 289 | 290 | procedure TDzMiniTable.Insert(Index: Integer); 291 | begin 292 | Tb.Insert(Index, string.Empty); 293 | Select(Index); 294 | end; 295 | 296 | procedure TDzMiniTable.EmptyRecord; 297 | begin 298 | CheckInRecord; 299 | 300 | CurRecord.S.Clear; 301 | end; 302 | 303 | procedure TDzMiniTable.Post; 304 | begin 305 | CheckInRecord; 306 | 307 | Tb[FSelIndex] := CurRecord.GetRecordAsString; 308 | 309 | CheckAutoSave; 310 | end; 311 | 312 | procedure TDzMiniTable.Delete; 313 | begin 314 | CheckInRecord; 315 | 316 | Tb.Delete(FSelIndex); 317 | SelReset; 318 | 319 | CheckAutoSave; 320 | end; 321 | 322 | procedure TDzMiniTable.MoveUp; 323 | begin 324 | CheckInRecord; 325 | 326 | if FSelIndex=0 then raise Exception.Create('Already at first record'); 327 | 328 | Tb.Exchange(FSelIndex, FSelIndex-1); 329 | Dec(FSelIndex); 330 | 331 | CheckAutoSave; 332 | end; 333 | 334 | procedure TDzMiniTable.MoveDown; 335 | begin 336 | CheckInRecord; 337 | 338 | if FSelIndex=Count-1 then raise Exception.Create('Already at last record'); 339 | 340 | Tb.Exchange(FSelIndex, FSelIndex+1); 341 | Inc(FSelIndex); 342 | 343 | CheckAutoSave; 344 | end; 345 | 346 | procedure TDzMiniTable.EmptyTable; 347 | begin 348 | Reset; //clear stringlist's and selection set 349 | 350 | CheckAutoSave; 351 | end; 352 | 353 | procedure TDzMiniTable.CheckAutoSave; 354 | begin 355 | if FAutoSave then Save; 356 | end; 357 | 358 | function TDzMiniTable.FieldExists(const FieldName: string): Boolean; 359 | begin 360 | CheckInRecord; 361 | 362 | Result := ( CurRecord.S.IndexOfName(FieldName) <> -1 ); 363 | end; 364 | 365 | function TDzMiniTable.ReadDef(const FieldName: string; const Default: Variant): Variant; 366 | begin 367 | if FieldExists(FieldName) then 368 | Result := F[FieldName] 369 | else 370 | Result := Default; 371 | end; 372 | 373 | function TDzMiniTable.FindIndex(const FieldName: string; const Value: Variant): Integer; 374 | var 375 | I: Integer; 376 | R: TRecordStore; 377 | begin 378 | Result := -1; 379 | 380 | R := TRecordStore.Create; 381 | try 382 | for I := 0 to Tb.Count-1 do 383 | begin 384 | R.LoadRecordFromString(Tb[I]); 385 | if R.ReadField(FieldName) = Value then 386 | begin 387 | Result := I; 388 | Break; 389 | end; 390 | end; 391 | finally 392 | R.Free; 393 | end; 394 | end; 395 | 396 | function TDzMiniTable.Locate(const FieldName: string; const Value: Variant): Boolean; 397 | var 398 | Idx: Integer; 399 | begin 400 | Result := False; 401 | 402 | Idx := FindIndex(FieldName, Value); 403 | if Idx <> -1 then 404 | begin 405 | Select(Idx); 406 | Result := True; 407 | end; 408 | end; 409 | 410 | function TDzMiniTable.ContainsValue(const FieldName: string; const Value: Variant): Boolean; 411 | begin 412 | Result := FindIndex(FieldName, Value) <> -1; 413 | end; 414 | 415 | end. 416 | -------------------------------------------------------------------------------- /DzMiniTable.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digao-dalpiaz/DzMiniTable/5ac9c4c0f65a3d342598f80d39afcb088509b7b5/DzMiniTable.res -------------------------------------------------------------------------------- /Example/DATA.TXT: -------------------------------------------------------------------------------- 1 | NAME=Jhon,"GROUP=Group 1",AMOUNT=180000 2 | NAME=Fred,"GROUP=Group 2",AMOUNT=120000 3 | NAME=Isac,"GROUP=Group 3",AMOUNT=56000 4 | NAME=Robert,"GROUP=Group 4",AMOUNT=79000 5 | -------------------------------------------------------------------------------- /Example/MiniTable_Example.dpr: -------------------------------------------------------------------------------- 1 | program MiniTable_Example; 2 | 3 | uses 4 | Vcl.Forms, 5 | UFrmEdit in 'UFrmEdit.pas' {FrmEdit}, 6 | UFrmExample in 'UFrmExample.pas' {FrmExample}; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.MainFormOnTaskbar := True; 13 | Application.CreateForm(TFrmExample, FrmExample); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /Example/MiniTable_Example.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {14BC5B37-9291-4A7A-8513-5FA035555028} 4 | 18.8 5 | VCL 6 | MiniTable_Example.dpr 7 | True 8 | Debug 9 | Win32 10 | 1 11 | Application 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Cfg_1 29 | true 30 | true 31 | 32 | 33 | true 34 | Base 35 | true 36 | 37 | 38 | true 39 | Cfg_2 40 | true 41 | true 42 | 43 | 44 | .\$(Platform)\$(Config) 45 | .\$(Platform)\$(Config) 46 | false 47 | false 48 | false 49 | false 50 | false 51 | System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) 52 | $(BDS)\bin\delphi_PROJECTICON.ico 53 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png 54 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png 55 | MiniTable_Example 56 | 57 | 58 | DBXSqliteDriver;IndyIPCommon;RESTComponents;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;vclFireDAC;IndySystem;tethering;svnui;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDAC;vcltouch;vcldb;bindcompfmx;svn;FireDACSqliteDriver;FireDACPgDriver;inetdb;DzMiniTable;FMXTee;soaprtl;DbxCommonDriver;FmxTeeUI;fmx;FireDACIBDriver;fmxdae;xmlrtl;soapmidas;Tee;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;FireDACCommon;IndyIPClient;bindcompvcl;SynEdit_R;RESTBackendComponents;TeeUI;VCLRESTComponents;soapserver;dbxcds;VclSmp;adortl;DzListHeader;DzHTMLText;vclie;bindengine;DBXMySQLDriver;CloudService;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;DzNotepad;FireDACCommonODBC;FireDACCommonDriver;DamPackage;inet;fmxase;$(DCC_UsePackage) 59 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 60 | Debug 61 | true 62 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 63 | 1033 64 | $(BDS)\bin\default_app.manifest 65 | 66 | 67 | DEBUG;$(DCC_Define) 68 | true 69 | false 70 | true 71 | true 72 | true 73 | 74 | 75 | false 76 | true 77 | PerMonitorV2 78 | true 79 | 1033 80 | 81 | 82 | false 83 | RELEASE;$(DCC_Define) 84 | 0 85 | 0 86 | 87 | 88 | true 89 | PerMonitorV2 90 | 91 | 92 | 93 | MainSource 94 | 95 | 96 |
FrmEdit
97 | dfm 98 |
99 | 100 |
FrmExample
101 | dfm 102 |
103 | 104 | Cfg_2 105 | Base 106 | 107 | 108 | Base 109 | 110 | 111 | Cfg_1 112 | Base 113 | 114 |
115 | 116 | Delphi.Personality.12 117 | Application 118 | 119 | 120 | 121 | MiniTable_Example.dpr 122 | 123 | 124 | Microsoft Office 2000 Sample Automation Server Wrapper Components 125 | Microsoft Office XP Sample Automation Server Wrapper Components 126 | 127 | 128 | 129 | 130 | 131 | MiniTable_Example.exe 132 | true 133 | 134 | 135 | 136 | 137 | 1 138 | 139 | 140 | Contents\MacOS 141 | 1 142 | 143 | 144 | 0 145 | 146 | 147 | 148 | 149 | classes 150 | 1 151 | 152 | 153 | classes 154 | 1 155 | 156 | 157 | 158 | 159 | res\xml 160 | 1 161 | 162 | 163 | res\xml 164 | 1 165 | 166 | 167 | 168 | 169 | library\lib\armeabi-v7a 170 | 1 171 | 172 | 173 | 174 | 175 | library\lib\armeabi 176 | 1 177 | 178 | 179 | library\lib\armeabi 180 | 1 181 | 182 | 183 | 184 | 185 | library\lib\armeabi-v7a 186 | 1 187 | 188 | 189 | 190 | 191 | library\lib\mips 192 | 1 193 | 194 | 195 | library\lib\mips 196 | 1 197 | 198 | 199 | 200 | 201 | library\lib\armeabi-v7a 202 | 1 203 | 204 | 205 | library\lib\arm64-v8a 206 | 1 207 | 208 | 209 | 210 | 211 | library\lib\armeabi-v7a 212 | 1 213 | 214 | 215 | 216 | 217 | res\drawable 218 | 1 219 | 220 | 221 | res\drawable 222 | 1 223 | 224 | 225 | 226 | 227 | res\values 228 | 1 229 | 230 | 231 | res\values 232 | 1 233 | 234 | 235 | 236 | 237 | res\values-v21 238 | 1 239 | 240 | 241 | res\values-v21 242 | 1 243 | 244 | 245 | 246 | 247 | res\values 248 | 1 249 | 250 | 251 | res\values 252 | 1 253 | 254 | 255 | 256 | 257 | res\drawable 258 | 1 259 | 260 | 261 | res\drawable 262 | 1 263 | 264 | 265 | 266 | 267 | res\drawable-xxhdpi 268 | 1 269 | 270 | 271 | res\drawable-xxhdpi 272 | 1 273 | 274 | 275 | 276 | 277 | res\drawable-ldpi 278 | 1 279 | 280 | 281 | res\drawable-ldpi 282 | 1 283 | 284 | 285 | 286 | 287 | res\drawable-mdpi 288 | 1 289 | 290 | 291 | res\drawable-mdpi 292 | 1 293 | 294 | 295 | 296 | 297 | res\drawable-hdpi 298 | 1 299 | 300 | 301 | res\drawable-hdpi 302 | 1 303 | 304 | 305 | 306 | 307 | res\drawable-xhdpi 308 | 1 309 | 310 | 311 | res\drawable-xhdpi 312 | 1 313 | 314 | 315 | 316 | 317 | res\drawable-mdpi 318 | 1 319 | 320 | 321 | res\drawable-mdpi 322 | 1 323 | 324 | 325 | 326 | 327 | res\drawable-hdpi 328 | 1 329 | 330 | 331 | res\drawable-hdpi 332 | 1 333 | 334 | 335 | 336 | 337 | res\drawable-xhdpi 338 | 1 339 | 340 | 341 | res\drawable-xhdpi 342 | 1 343 | 344 | 345 | 346 | 347 | res\drawable-xxhdpi 348 | 1 349 | 350 | 351 | res\drawable-xxhdpi 352 | 1 353 | 354 | 355 | 356 | 357 | res\drawable-xxxhdpi 358 | 1 359 | 360 | 361 | res\drawable-xxxhdpi 362 | 1 363 | 364 | 365 | 366 | 367 | res\drawable-small 368 | 1 369 | 370 | 371 | res\drawable-small 372 | 1 373 | 374 | 375 | 376 | 377 | res\drawable-normal 378 | 1 379 | 380 | 381 | res\drawable-normal 382 | 1 383 | 384 | 385 | 386 | 387 | res\drawable-large 388 | 1 389 | 390 | 391 | res\drawable-large 392 | 1 393 | 394 | 395 | 396 | 397 | res\drawable-xlarge 398 | 1 399 | 400 | 401 | res\drawable-xlarge 402 | 1 403 | 404 | 405 | 406 | 407 | res\values 408 | 1 409 | 410 | 411 | res\values 412 | 1 413 | 414 | 415 | 416 | 417 | 1 418 | 419 | 420 | Contents\MacOS 421 | 1 422 | 423 | 424 | 0 425 | 426 | 427 | 428 | 429 | Contents\MacOS 430 | 1 431 | .framework 432 | 433 | 434 | Contents\MacOS 435 | 1 436 | .framework 437 | 438 | 439 | 0 440 | 441 | 442 | 443 | 444 | 1 445 | .dylib 446 | 447 | 448 | 1 449 | .dylib 450 | 451 | 452 | 1 453 | .dylib 454 | 455 | 456 | Contents\MacOS 457 | 1 458 | .dylib 459 | 460 | 461 | Contents\MacOS 462 | 1 463 | .dylib 464 | 465 | 466 | 0 467 | .dll;.bpl 468 | 469 | 470 | 471 | 472 | 1 473 | .dylib 474 | 475 | 476 | 1 477 | .dylib 478 | 479 | 480 | 1 481 | .dylib 482 | 483 | 484 | Contents\MacOS 485 | 1 486 | .dylib 487 | 488 | 489 | Contents\MacOS 490 | 1 491 | .dylib 492 | 493 | 494 | 0 495 | .bpl 496 | 497 | 498 | 499 | 500 | 0 501 | 502 | 503 | 0 504 | 505 | 506 | 0 507 | 508 | 509 | 0 510 | 511 | 512 | 0 513 | 514 | 515 | Contents\Resources\StartUp\ 516 | 0 517 | 518 | 519 | Contents\Resources\StartUp\ 520 | 0 521 | 522 | 523 | 0 524 | 525 | 526 | 527 | 528 | 1 529 | 530 | 531 | 1 532 | 533 | 534 | 1 535 | 536 | 537 | 538 | 539 | 1 540 | 541 | 542 | 1 543 | 544 | 545 | 1 546 | 547 | 548 | 549 | 550 | 1 551 | 552 | 553 | 1 554 | 555 | 556 | 1 557 | 558 | 559 | 560 | 561 | 1 562 | 563 | 564 | 1 565 | 566 | 567 | 1 568 | 569 | 570 | 571 | 572 | 1 573 | 574 | 575 | 1 576 | 577 | 578 | 1 579 | 580 | 581 | 582 | 583 | 1 584 | 585 | 586 | 1 587 | 588 | 589 | 1 590 | 591 | 592 | 593 | 594 | 1 595 | 596 | 597 | 1 598 | 599 | 600 | 1 601 | 602 | 603 | 604 | 605 | 1 606 | 607 | 608 | 1 609 | 610 | 611 | 1 612 | 613 | 614 | 615 | 616 | 1 617 | 618 | 619 | 1 620 | 621 | 622 | 1 623 | 624 | 625 | 626 | 627 | 1 628 | 629 | 630 | 1 631 | 632 | 633 | 1 634 | 635 | 636 | 637 | 638 | 1 639 | 640 | 641 | 1 642 | 643 | 644 | 1 645 | 646 | 647 | 648 | 649 | 1 650 | 651 | 652 | 1 653 | 654 | 655 | 1 656 | 657 | 658 | 659 | 660 | 1 661 | 662 | 663 | 1 664 | 665 | 666 | 1 667 | 668 | 669 | 670 | 671 | 1 672 | 673 | 674 | 1 675 | 676 | 677 | 1 678 | 679 | 680 | 681 | 682 | 1 683 | 684 | 685 | 1 686 | 687 | 688 | 1 689 | 690 | 691 | 692 | 693 | 1 694 | 695 | 696 | 1 697 | 698 | 699 | 1 700 | 701 | 702 | 703 | 704 | 1 705 | 706 | 707 | 1 708 | 709 | 710 | 1 711 | 712 | 713 | 714 | 715 | 1 716 | 717 | 718 | 1 719 | 720 | 721 | 1 722 | 723 | 724 | 725 | 726 | 1 727 | 728 | 729 | 1 730 | 731 | 732 | 1 733 | 734 | 735 | 736 | 737 | 1 738 | 739 | 740 | 1 741 | 742 | 743 | 1 744 | 745 | 746 | 747 | 748 | 1 749 | 750 | 751 | 1 752 | 753 | 754 | 1 755 | 756 | 757 | 758 | 759 | 1 760 | 761 | 762 | 1 763 | 764 | 765 | 1 766 | 767 | 768 | 769 | 770 | 1 771 | 772 | 773 | 1 774 | 775 | 776 | 1 777 | 778 | 779 | 780 | 781 | 1 782 | 783 | 784 | 1 785 | 786 | 787 | 1 788 | 789 | 790 | 791 | 792 | 1 793 | 794 | 795 | 1 796 | 797 | 798 | 1 799 | 800 | 801 | 802 | 803 | 1 804 | 805 | 806 | 1 807 | 808 | 809 | 1 810 | 811 | 812 | 813 | 814 | 1 815 | 816 | 817 | 1 818 | 819 | 820 | 1 821 | 822 | 823 | 824 | 825 | 1 826 | 827 | 828 | 1 829 | 830 | 831 | 1 832 | 833 | 834 | 835 | 836 | 1 837 | 838 | 839 | 1 840 | 841 | 842 | 843 | 844 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 845 | 1 846 | 847 | 848 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 849 | 1 850 | 851 | 852 | 853 | 854 | 1 855 | 856 | 857 | 1 858 | 859 | 860 | 861 | 862 | ..\ 863 | 1 864 | 865 | 866 | ..\ 867 | 1 868 | 869 | 870 | 871 | 872 | 1 873 | 874 | 875 | 1 876 | 877 | 878 | 1 879 | 880 | 881 | 882 | 883 | 1 884 | 885 | 886 | 1 887 | 888 | 889 | 1 890 | 891 | 892 | 893 | 894 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 895 | 1 896 | 897 | 898 | 899 | 900 | ..\ 901 | 1 902 | 903 | 904 | ..\ 905 | 1 906 | 907 | 908 | 909 | 910 | Contents 911 | 1 912 | 913 | 914 | Contents 915 | 1 916 | 917 | 918 | 919 | 920 | Contents\Resources 921 | 1 922 | 923 | 924 | Contents\Resources 925 | 1 926 | 927 | 928 | 929 | 930 | library\lib\armeabi-v7a 931 | 1 932 | 933 | 934 | library\lib\arm64-v8a 935 | 1 936 | 937 | 938 | 1 939 | 940 | 941 | 1 942 | 943 | 944 | 1 945 | 946 | 947 | 1 948 | 949 | 950 | Contents\MacOS 951 | 1 952 | 953 | 954 | Contents\MacOS 955 | 1 956 | 957 | 958 | 0 959 | 960 | 961 | 962 | 963 | library\lib\armeabi-v7a 964 | 1 965 | 966 | 967 | 968 | 969 | 1 970 | 971 | 972 | 1 973 | 974 | 975 | 976 | 977 | Assets 978 | 1 979 | 980 | 981 | Assets 982 | 1 983 | 984 | 985 | 986 | 987 | Assets 988 | 1 989 | 990 | 991 | Assets 992 | 1 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | True 1008 | 1009 | 1010 | 12 1011 | 1012 | 1013 | 1014 | 1015 |
1016 | -------------------------------------------------------------------------------- /Example/MiniTable_Example.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digao-dalpiaz/DzMiniTable/5ac9c4c0f65a3d342598f80d39afcb088509b7b5/Example/MiniTable_Example.res -------------------------------------------------------------------------------- /Example/UFrmEdit.dfm: -------------------------------------------------------------------------------- 1 | object FrmEdit: TFrmEdit 2 | Left = 0 3 | Top = 0 4 | BorderStyle = bsDialog 5 | Caption = 'Add Customer' 6 | ClientHeight = 205 7 | ClientWidth = 441 8 | Color = clBtnFace 9 | Font.Charset = DEFAULT_CHARSET 10 | Font.Color = clWindowText 11 | Font.Height = -11 12 | Font.Name = 'Tahoma' 13 | Font.Style = [] 14 | OldCreateOrder = False 15 | Position = poScreenCenter 16 | OnShow = FormShow 17 | PixelsPerInch = 96 18 | TextHeight = 13 19 | object Label1: TLabel 20 | Left = 16 21 | Top = 16 22 | Width = 27 23 | Height = 13 24 | Caption = 'Name' 25 | end 26 | object Label2: TLabel 27 | Left = 16 28 | Top = 64 29 | Width = 29 30 | Height = 13 31 | Caption = 'Group' 32 | end 33 | object Label3: TLabel 34 | Left = 16 35 | Top = 112 36 | Width = 37 37 | Height = 13 38 | Caption = 'Amount' 39 | end 40 | object Bevel1: TBevel 41 | Left = 16 42 | Top = 160 43 | Width = 409 44 | Height = 9 45 | Shape = bsTopLine 46 | end 47 | object EdName: TEdit 48 | Left = 16 49 | Top = 32 50 | Width = 177 51 | Height = 21 52 | TabOrder = 0 53 | end 54 | object EdGroup: TEdit 55 | Left = 16 56 | Top = 80 57 | Width = 177 58 | Height = 21 59 | TabOrder = 1 60 | end 61 | object EdAmount: TEdit 62 | Left = 16 63 | Top = 128 64 | Width = 121 65 | Height = 21 66 | TabOrder = 2 67 | end 68 | object BtnOK: TButton 69 | Left = 144 70 | Top = 168 71 | Width = 75 72 | Height = 25 73 | Caption = 'OK' 74 | Default = True 75 | TabOrder = 3 76 | OnClick = BtnOKClick 77 | end 78 | object BtnCancel: TButton 79 | Left = 224 80 | Top = 168 81 | Width = 75 82 | Height = 25 83 | Cancel = True 84 | Caption = 'Cancel' 85 | ModalResult = 2 86 | TabOrder = 4 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /Example/UFrmEdit.pas: -------------------------------------------------------------------------------- 1 | unit UFrmEdit; 2 | 3 | interface 4 | 5 | uses Vcl.Forms, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Controls, System.Classes; 6 | 7 | type 8 | TFrmEdit = class(TForm) 9 | Label1: TLabel; 10 | EdName: TEdit; 11 | Label2: TLabel; 12 | EdGroup: TEdit; 13 | Label3: TLabel; 14 | EdAmount: TEdit; 15 | BtnOK: TButton; 16 | BtnCancel: TButton; 17 | Bevel1: TBevel; 18 | procedure BtnOKClick(Sender: TObject); 19 | procedure FormShow(Sender: TObject); 20 | private 21 | Edit: Boolean; 22 | end; 23 | 24 | var 25 | FrmEdit: TFrmEdit; 26 | 27 | function DoEdit(Edit: Boolean): Boolean; 28 | 29 | implementation 30 | 31 | {$R *.dfm} 32 | 33 | uses UFrmExample; 34 | 35 | function DoEdit(Edit: Boolean): Boolean; 36 | begin 37 | FrmEdit := TFrmEdit.Create(Application); 38 | FrmEdit.Edit := Edit; 39 | Result := FrmEdit.ShowModal = mrOk; 40 | FrmEdit.Free; 41 | end; 42 | 43 | procedure TFrmEdit.FormShow(Sender: TObject); 44 | begin 45 | if Edit then 46 | begin 47 | Caption := 'Edit Customer'; 48 | 49 | EdName.Text := FrmExample.MT.F['NAME']; 50 | EdGroup.Text := FrmExample.MT.F['GROUP']; 51 | EdAmount.Text := FrmExample.MT.F['AMOUNT']; 52 | end; 53 | end; 54 | 55 | procedure TFrmEdit.BtnOKClick(Sender: TObject); 56 | begin 57 | if not Edit then 58 | FrmExample.MT.New; 59 | 60 | FrmExample.MT.F['NAME'] := EdName.Text; 61 | FrmExample.MT.F['GROUP'] := EdGroup.Text; 62 | FrmExample.MT.F['AMOUNT'] := EdAmount.Text; 63 | 64 | FrmExample.MT.Post; 65 | 66 | if Edit then 67 | FrmExample.L.Items[FrmExample.L.ItemIndex] := EdName.Text 68 | else 69 | begin 70 | FrmExample.L.ItemIndex := FrmExample.L.Items.Add(EdName.Text); 71 | FrmExample.UpdButtons; 72 | end; 73 | 74 | ModalResult := mrOk; 75 | end; 76 | 77 | end. 78 | -------------------------------------------------------------------------------- /Example/UFrmExample.dfm: -------------------------------------------------------------------------------- 1 | object FrmExample: TFrmExample 2 | Left = 0 3 | Top = 0 4 | BorderIcons = [biSystemMenu, biMinimize] 5 | BorderStyle = bsSingle 6 | Caption = 'MiniTable Example' 7 | ClientHeight = 297 8 | ClientWidth = 385 9 | Color = clBtnFace 10 | Font.Charset = DEFAULT_CHARSET 11 | Font.Color = clWindowText 12 | Font.Height = -11 13 | Font.Name = 'Tahoma' 14 | Font.Style = [] 15 | OldCreateOrder = False 16 | Position = poScreenCenter 17 | OnCreate = FormCreate 18 | OnDestroy = FormDestroy 19 | PixelsPerInch = 96 20 | TextHeight = 13 21 | object LbList: TLabel 22 | Left = 8 23 | Top = 8 24 | Width = 65 25 | Height = 13 26 | Caption = 'Customer List' 27 | end 28 | object L: TListBox 29 | Left = 8 30 | Top = 24 31 | Width = 273 32 | Height = 265 33 | ItemHeight = 13 34 | TabOrder = 0 35 | OnClick = LClick 36 | end 37 | object BtnAdd: TButton 38 | Left = 288 39 | Top = 24 40 | Width = 89 41 | Height = 33 42 | Caption = 'Add' 43 | TabOrder = 1 44 | OnClick = BtnEditClick 45 | end 46 | object BtnEdit: TButton 47 | Left = 288 48 | Top = 64 49 | Width = 89 50 | Height = 33 51 | Caption = 'Edit' 52 | TabOrder = 2 53 | OnClick = BtnEditClick 54 | end 55 | object BtnDel: TButton 56 | Left = 288 57 | Top = 104 58 | Width = 89 59 | Height = 33 60 | Caption = 'Delete' 61 | TabOrder = 3 62 | OnClick = BtnDelClick 63 | end 64 | object BtnMoveUp: TButton 65 | Left = 288 66 | Top = 152 67 | Width = 89 68 | Height = 33 69 | Caption = 'Move Up' 70 | TabOrder = 4 71 | OnClick = BtnMoveUpClick 72 | end 73 | object BtnMoveDown: TButton 74 | Left = 288 75 | Top = 192 76 | Width = 89 77 | Height = 33 78 | Caption = 'Move Down' 79 | TabOrder = 5 80 | OnClick = BtnMoveDownClick 81 | end 82 | object BtnFind: TButton 83 | Left = 288 84 | Top = 240 85 | Width = 89 86 | Height = 33 87 | Caption = 'Find' 88 | TabOrder = 6 89 | OnClick = BtnFindClick 90 | end 91 | object MT: TDzMiniTable 92 | Left = 208 93 | Top = 56 94 | end 95 | end 96 | -------------------------------------------------------------------------------- /Example/UFrmExample.pas: -------------------------------------------------------------------------------- 1 | unit UFrmExample; 2 | 3 | interface 4 | 5 | uses Vcl.Forms, DzMiniTable, Vcl.StdCtrls, Vcl.Controls, System.Classes; 6 | 7 | type 8 | TFrmExample = class(TForm) 9 | MT: TDzMiniTable; 10 | L: TListBox; 11 | LbList: TLabel; 12 | BtnAdd: TButton; 13 | BtnEdit: TButton; 14 | BtnDel: TButton; 15 | BtnMoveUp: TButton; 16 | BtnMoveDown: TButton; 17 | BtnFind: TButton; 18 | procedure FormCreate(Sender: TObject); 19 | procedure BtnDelClick(Sender: TObject); 20 | procedure LClick(Sender: TObject); 21 | procedure BtnEditClick(Sender: TObject); 22 | procedure FormDestroy(Sender: TObject); 23 | procedure BtnMoveUpClick(Sender: TObject); 24 | procedure BtnMoveDownClick(Sender: TObject); 25 | procedure BtnFindClick(Sender: TObject); 26 | private 27 | procedure LoadList; 28 | public 29 | procedure UpdButtons; 30 | end; 31 | 32 | var 33 | FrmExample: TFrmExample; 34 | 35 | implementation 36 | 37 | {$R *.dfm} 38 | 39 | uses UFrmEdit, System.SysUtils, Vcl.Dialogs, System.UITypes; 40 | 41 | procedure TFrmExample.FormCreate(Sender: TObject); 42 | begin 43 | ReportMemoryLeaksOnShutdown := True; 44 | 45 | MT.FileName := ExtractFilePath(Application.ExeName)+'DATA.TXT'; 46 | 47 | LoadList; 48 | UpdButtons; 49 | end; 50 | 51 | procedure TFrmExample.FormDestroy(Sender: TObject); 52 | begin 53 | MT.Save; 54 | end; 55 | 56 | procedure TFrmExample.LoadList; 57 | begin 58 | MT.Open; 59 | 60 | MT.SelReset; 61 | while MT.Next do 62 | begin 63 | L.Items.Add( MT.F['NAME'] ); 64 | end; 65 | end; 66 | 67 | procedure TFrmExample.LClick(Sender: TObject); 68 | begin 69 | MT.Select(L.ItemIndex); 70 | UpdButtons; 71 | end; 72 | 73 | procedure TFrmExample.UpdButtons; 74 | var Sel: Boolean; 75 | begin 76 | Sel := L.ItemIndex<>-1; 77 | 78 | BtnEdit.Enabled := Sel; 79 | BtnDel.Enabled := Sel; 80 | 81 | BtnMoveUp.Enabled := Sel and (L.ItemIndex>0); 82 | BtnMoveDown.Enabled := Sel and (L.ItemIndex 28 | Click here to view the entire changelog 29 | 30 | - 03/13/2021 (Version 1.7) 31 | 32 | - Removed CompInstall.exe from component sources due to AV false positive warning (now you can get it directly from CompInstall repository). 33 | 34 | - 02/01/2021 (Version 1.6) 35 | 36 | - Removed Delphi XE2 from the list of environments as it was never possible to compile in this version. 37 | 38 | - 12/18/2020 (Version 1.5) 39 | 40 | - Updated Component Installer app (Fixed call to rsvars.bat when Delphi is installed in a path containing spaces characters). 41 | 42 | - 10/31/2020 (Version 1.4) 43 | 44 | - Included Delphi 10.4 auto-install support. 45 | 46 | - 10/27/2020 (Version 1.3) 47 | 48 | - Fixed previous Delphi versions (at least on XE2, XE3, XE4 and XE5) package tag. It was causing package compilation error. 49 | 50 | - 10/26/2020 (Version 1.2) 51 | 52 | - Updated CompInstall to version 2.0 (now supports GitHub auto-update) 53 | 54 | - 10/09/2020 (Version 1.1) 55 | 56 | - New methods to search data 57 | 58 | - 05/03/2020 59 | 60 | - Updated CompInstall to version 1.2 61 | 62 | - 02/11/2019 63 | 64 | - Include auto install app 65 | 66 | - 02/08/2019 67 | 68 | - Component renamed. Please full uninstall previous version before install this version. :warning: 69 | 70 | - 02/07/2019 71 | 72 | - Add Win64 support (library folders changed!) :warning: 73 | 74 | 75 | 76 | ## Component Description 77 | 78 | When you are working on your software project, you always need to store some data into a INI file or some text file, as a configuration file or other information. 79 | 80 | So, the options you have is INI file, or plain text. And almost always you need a table with some fields. 81 | 82 | In a plain text, you can use one record per line, and separate fields using tab character, or pipe character, or another one. But you have some problems with this method: you need to take care about the separator char, not using it at fields value; and you have a biggest problem: in a future version, if you need to add a column, you lose the compatibility at this file when there are already data stored. 83 | 84 | If you are working with INI file, you can specify the field names, but even that, you have problems to store one record per section, and is difficult to reorder records, delete records and name the record. 85 | 86 | But don't worry, here is the solution. 87 | 88 | The MiniTable is a non-visual component where you can store records with fields and values, and you can name the field, so you don't need to worry at future versions. You can add new fields at any time, just reading and writing them. 89 | 90 | ## Installing 91 | 92 | ### Auto install 93 | 94 | 1. Download Component Installer from: https://github.com/digao-dalpiaz/CompInstall/releases/latest 95 | 2. Put **CompInstall.exe** into the component repository sources folder. 96 | 3. Close Delphi IDE and run **CompInstall.exe** app. 97 | 98 | ### Manual install 99 | 100 | 1. Open **DzMiniTable** package in Delphi. 101 | 2. Ensure **Win32** Platform and **Release** config are selected. 102 | 3. Then **Build** and **Install**. 103 | 4. If you want to use Win64 platform, select this platform and Build again. 104 | 5. Add sub-path Win32\Release to the Library paths at Tools\Options using 32-bit option, and if you have compiled to 64 bit platform, add sub-path Win64\Release using 64-bit option. 105 | 106 | Supports Delphi XE3..Delphi 11 107 | 108 | ## Published Properties 109 | 110 | `AutoSave: Boolean` = Enables auto save to specified FileName at any method that writes any change to the table 111 | 112 | `FileName: String` = Specifies the full file name to Open and Save the table 113 | 114 | `JumpOpen: Boolean` = When this property is enabled, if the file does not exist at Open method, the table will be loaded empty without raise any exception. 115 | 116 | ## Public Properties 117 | 118 | `Lines: TStringList` = Allows you to change the stored table manually. **You should never change this TStringList.** 119 | 120 | `MemString: String` = Allows you to load the table directly from a string, and store the table to a string. This is useful when you are storing the table in a database blob file. 121 | 122 | `SelIndex: Integer` = Returns the current selected index (read-only property) 123 | 124 | `Count: Integer` = Returns the record count of the table (read-only property) 125 | 126 | `F[FieldName: String]: Variant` = Read/write a field value at current selected record. The FieldName is case-insensitive. 127 | If you are reading field value and the field does not exist, the result is an empty string. 128 | 129 | ## Procedures/Functions 130 | 131 | ```delphi 132 | procedure SelReset; 133 | ``` 134 | Resets the selection of record to none. You can use this method to initialize an iteration of record, ensuring the selected record is reseted. 135 | 136 | ```delphi 137 | function InRecord: Boolean; 138 | ``` 139 | Returns true if there is a record selected 140 | 141 | ```delphi 142 | procedure Open; 143 | ``` 144 | Load the table from file specified at FileName property 145 | 146 | ```delphi 147 | procedure Save; 148 | ``` 149 | Save the table to file specified at FileName property 150 | 151 | ```delphi 152 | procedure EmptyTable; 153 | ``` 154 | Clear all data in the table 155 | 156 | ```delphi 157 | procedure EmptyRecord; 158 | ``` 159 | Clear all data in the current selected record 160 | 161 | ```delphi 162 | function IsEmpty: Boolean; 163 | ``` 164 | Returns true if the table is empty 165 | 166 | ```delphi 167 | procedure Select(Index: Integer); 168 | ``` 169 | Select the record by index position. When you select a record, all its fields stays stored at internal memory, so you can read and write the fields value using `F` property. 170 | 171 | ```delphi 172 | procedure First; 173 | ``` 174 | Select the first record in the table 175 | 176 | ```delphi 177 | procedure Last; 178 | ``` 179 | Select the last record in the table 180 | 181 | ```delphi 182 | function Next: Boolean; 183 | ``` 184 | Select the next record in the table, based in the current index position. This method is useful to iterate all record. See example below: 185 | 186 | ```delphi 187 | DzMiniTable.SelReset; 188 | while MiniTable.Next do 189 | begin 190 | ListBox.Add(DzMiniTable.F['Name']+' / '+MiniTable.F['Phone']); 191 | end; 192 | ``` 193 | 194 | ```delphi 195 | procedure New; 196 | ``` 197 | Create a new record at the end of the table position and select it, so you can immediately start write fields. 198 | 199 | ```delphi 200 | procedure Insert(Index: Integer); 201 | ``` 202 | Insert a new record at the index position and select it, so you can immediately start write fields. 203 | 204 | ```delphi 205 | procedure Post; 206 | ``` 207 | Writes all change in the current record to the table. You don't need to start editing of the record. See example below: 208 | 209 | ```delphi 210 | DzMiniTable.New; 211 | DzMiniTable.F['Name'] := 'John'; 212 | DzMiniTable.F['Phone'] := '1111-2222'; 213 | DzMiniTable.Post; 214 | ``` 215 | or: 216 | ```delphi 217 | DzMiniTable.Select(3); 218 | DzMiniTable.F['Phone'] := '1111-2222'; 219 | DzMiniTable.Post; 220 | ``` 221 | 222 | ```delphi 223 | procedure Delete; 224 | ``` 225 | Delete the current selected record 226 | 227 | ```delphi 228 | procedure MoveDown; 229 | ``` 230 | Move the current record to one index down 231 | 232 | ```delphi 233 | procedure MoveUp; 234 | ``` 235 | Move the current record to one index up 236 | 237 | ```delphi 238 | function FindIndex(const FieldName: string; const Value: Variant): Integer; 239 | ``` 240 | Find any field value on all records, returning record index position. 241 | 242 | ```delphi 243 | function Locate(const FieldName: string; const Value: Variant): Boolean; 244 | ``` 245 | Find any field value on all records, returning true if record found, and **positioning it as current record**. 246 | If no record is found, the current position will not be changed. 247 | 248 | ```delphi 249 | function ContainsValue(const FieldName: string; const Value: Variant): Boolean; 250 | ``` 251 | Find any field value on all records, returning true if record found. 252 | 253 | ```delphi 254 | function FieldExists(const FieldName: String): Boolean; 255 | ``` 256 | Returns true if the FieldName exists at current selected record. 257 | 258 | ```delphi 259 | function ReadDef(const FieldName: String; const Default: Variant): Variant; 260 | ``` 261 | This functions is the same as the F property, but here you can specify a default value when the Field does not exist in the record. 262 | 263 | --------------------------------------------------------------------------------