forked from Sovos-Compliance/convey-public-libs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kbmMemTableDesForm.pas
1440 lines (1246 loc) · 39.3 KB
/
kbmMemTableDesForm.pas
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
unit kbmMemTableDesForm;
interface
{$include kbmMemTable.inc}
{$IFNDEF LINUX}
uses
{$IFDEF CLX}
QForms,
QImgList, QDialogs, QGrids, QDBGrids, QStdCtrls, QCheckLst,
QButtons, QControls, QComCtrls, QExtCtrls,
TypInfo, ImgList, Controls, Dialogs, DB, DBTables, Grids, DBGrids,
StdCtrls, CheckLst, Buttons, ComCtrls, ExtCtrls, Classes
{$ELSE}
Windows, Messages, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, StdCtrls,BDE,DBTables,typinfo,
Grids, DBGrids, CheckLst, ImgList, Buttons, DB, Classes
{$IFDEF LEVEL6}
,DesignEditors
,DesignIntf
{$ELSE}
,DsgnIntf
{$ENDIF}
{$ENDIF}
,SysUtils
,kbmMemTable
,kbmMemCSVStreamFormat
,kbmMemBinaryStreamFormat
;
type
TfrmKbmMemTableDesigner = class(TForm)
{$IFNDEF LINUX}
SES_Dummy: TSession;
tsBDEAlias: TTabSheet;
Label1: TLabel;
Label2: TLabel;
LTV_Alias: TListView;
LTV_Tables: TListView;
{$ENDIF}
StatusBar1: TStatusBar;
DLG_SelectFile: TOpenDialog;
DTS_DataDesign: TDataSource;
DLG_SaveFile: TSaveDialog;
IMG_LTV_Tables: TImageList;
IMG_LTV_Alias: TImageList;
IMG_LTV_Fields: TImageList;
PGC_Options: TPageControl;
TBS_ActualStructure: TTabSheet;
PAN_ActualStructure: TPanel;
LTV_Structure: TListView;
TBS_BorrowStructure: TTabSheet;
PAN_BorrowStructure: TPanel;
BTN_Refresh: TButton;
BTN_GetStructure: TButton;
pcBorrowFrom: TPageControl;
tsTDataset: TTabSheet;
LTV_Datasets: TListView;
TBS_Data: TTabSheet;
PAN_Data: TPanel;
LAB_Progress: TLabel;
RBT_FromFile: TRadioButton;
RBT_FromTable: TRadioButton;
PAN_FromFile: TPanel;
Label3: TLabel;
EDT_File: TEdit;
PAN_FromTable: TPanel;
LTV_FromTable: TListView;
BTN_Load: TButton;
BTN_SelectFileName: TButton;
BTN_Save: TButton;
PRO_Records: TProgressBar;
CHK_Binary: TCheckBox;
CHK_OnlyData: TCheckBox;
TBS_Sorting: TTabSheet;
PAN_Sort: TPanel;
Label4: TLabel;
Label5: TLabel;
BTN_SEL_All: TSpeedButton;
BTN_SEL_Selected: TSpeedButton;
BTN_UNS_Selected: TSpeedButton;
BTN_UNS_All: TSpeedButton;
BTN_ORD_First: TSpeedButton;
BTN_ORD_Plus: TSpeedButton;
BTN_ORD_Minus: TSpeedButton;
BTN_ORD_Last: TSpeedButton;
Label6: TLabel;
LTV_Existing: TListView;
LTV_Sort: TListView;
BTN_Sort: TButton;
LTB_SortOptions: TCheckListBox;
TBS_DataDesign: TTabSheet;
PAN_DataDesign: TPanel;
DBG_DataDesign: TDBGrid;
RBT_FromDataset: TRadioButton;
PAN_FromDataset: TPanel;
LTV_FromDataset: TListView;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
{$IFNDEF LINUX}
procedure LTV_AliasChange(Sender: TObject; Item: TListItem;Change: TItemChange);
procedure LTV_TablesChange(Sender: TObject; Item: TListItem;Change: TItemChange);
{$ENDIF}
procedure BTN_GetStructureClick(Sender: TObject);
procedure RBT_FromFileClick(Sender: TObject);
procedure RBT_FromTableClick(Sender: TObject);
procedure LTV_FromTableChange(Sender: TObject; Item: TListItem;Change: TItemChange);
procedure BTN_SelectFileNameClick(Sender: TObject);
procedure BTN_LoadClick(Sender: TObject);
procedure BTN_SaveClick(Sender: TObject);
procedure BTN_RefreshClick(Sender: TObject);
procedure LTV_ExistingChange(Sender: TObject; Item: TListItem;Change: TItemChange);
procedure LTV_SortChange(Sender: TObject; Item: TListItem;Change: TItemChange);
procedure BTN_SEL_AllClick(Sender: TObject);
procedure BTN_UNS_AllClick(Sender: TObject);
procedure BTN_SEL_SelectedClick(Sender: TObject);
procedure BTN_UNS_SelectedClick(Sender: TObject);
procedure BTN_ORD_LastClick(Sender: TObject);
procedure BTN_ORD_FirstClick(Sender: TObject);
procedure BTN_ORD_MinusClick(Sender: TObject);
procedure BTN_ORD_PlusClick(Sender: TObject);
procedure BTN_SortClick(Sender: TObject);
procedure LTV_DatasetsChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure RBT_FromDatasetClick(Sender: TObject);
procedure LTV_FromDatasetChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
private
{ Private declarations }
IsFilling: boolean;
{$IFNDEF LINUX}
procedure GetAliases;
procedure GetTables(DatabaseName: string);
procedure LoadStructure(TableName: string);
{$ENDIF}
procedure GetDatasets;
procedure GetActualStructure;
procedure CheckAvailData;
procedure TransAll(Source: TListView; Dest: TListView);
procedure CopyItem(SourceItem: TListITem; Dest: TListView);
procedure StoreSortSetup;
{ListItems Handling functions and procedures }
function SwapItems(ItemFrom:TListItem; ItemTo:TListItem):boolean;
function MoveItem(Item:TListItem; DestinationIndex:integer):TListItem;
procedure SelectFull(Item:TListItem);
function DeleteItem(Item:TListItem): TListItem;
function IsInFieldNames(FieldNames,FieldName:string):boolean;
procedure CreateFields;
public
{ Public declarations }
{$IFDEF LEVEL3}
Designer:TFormDesigner;
{$ELSE}
{$IFDEF LEVEL6}
Designer:IDesigner;
{$ELSE}
Designer:IFormDesigner;
{$ENDIF}
{$ENDIF}
MemTable: TkbmMemTable;
procedure CopyDataSet(Source: TDataSet; Dest: TDataSet;Visual: boolean);
end;
var
frmKbmMemTableDesigner:TfrmKbmMemTableDesigner;
const
KbmMemTableDesignerVersion='Designer - TkbmMemTable v.'+COMPONENT_VERSION;
implementation
{$IFNDEF LINUX}
{$R *.dfm}
{$ELSE}
{$R *.xfm}
{$ENDIF}
// To use code completion, please remark the line further down (uses DSDesign)
// during designtime. Remember to remove the remark before compiletime.
// Kim Bo Madsen/Optical Services - Scandinavia
{$IFNDEF LINUX}
uses DSDesign;
{$ENDIF}
function TfrmKbmMemTableDesigner.SwapItems(ItemFrom:TListItem; ItemTo:TListItem):boolean;
var
ListView:TListView;
i:integer;
ItemDummy:TStringList;
tmpCaption:string;
tmpState:integer;
tmpImageIndex:integer;
ControlCheck:boolean;
begin
Result:=false;
if (ItemFrom = nil) or (ItemTo = nil) then exit;
if TListView(ItemFrom.Owner.Owner) <> TListView(ItemTo.Owner.Owner) then exit;
ListView:=TListView(ItemFrom.Owner.Owner);
if ListView = nil then exit;
ControlCheck:=ListView.CheckBoxes;
ItemDummy:=TStringList.Create;
try
tmpCaption:=ItemFrom.Caption;
tmpImageIndex:=ItemFrom.ImageIndex;
if ControlCheck then
tmpState:=ord(ItemFrom.Checked)
else
{$IFNDEF LINUX}
tmpState:=ItemFrom.StateIndex;
{$ELSE}
tmpState:=0;
{$ENDIF}
for i:=0 to ItemFrom.SubItems.Count-1 do
ItemDummy.Add(ItemFrom.SubItems[i]);
ItemFrom.Caption:=ItemTo.Caption;
for i:=0 to ItemTo.SubItems.Count-1 do
ItemFrom.SubItems[i]:=ItemTo.SubItems[i];
ItemFrom.ImageIndex:=ItemTo.ImageIndex;
if ControlCheck then
ItemFrom.Checked:=ItemTo.Checked
{$IFNDEF LINUX}
else
ItemFrom.StateIndex:=ItemTo.StateIndex
{$ENDIF}
;
ItemTo.Caption:=tmpCaption;
for i:=0 to ItemDummy.Count-1 do
ItemTo.SubItems[i]:=ItemDummy[i];
ItemTo.ImageIndex:=tmpImageIndex;
if ControlCheck then
ItemTo.Checked:=boolean(tmpState)
{$IFNDEF LINUX}
else
ItemTo.StateIndex:=tmpState
{$ENDIF};
finally
ItemDummy.Free;
end;
Result:=true;
end;
function TfrmKbmMemTableDesigner.MoveItem(Item:TListItem; DestinationIndex:integer):TListItem;
var
ListView:TListView;
NewItem:TListItem;
i:integer;
begin
Result:=nil;
if Item=nil then exit;
ListView:=TListView(Item.Owner.Owner);
if ListView = nil then exit;
NewItem:=ListView.Items.Insert(DestinationIndex);
NewItem.Caption:=Item.Caption;
NewItem.ImageIndex:=Item.ImageIndex;
{$IFNDEF LINUX}
NewItem.StateIndex:=Item.StateIndex;
{$ENDIF}
NewItem.Checked:=Item.Checked;
for i:=0 to Item.SubItems.Count - 1 do
NewItem.SubItems.Add(Item.SubItems[i]);
Item.Delete;
Result:=NewItem;
end;
procedure TfrmKbmMemTableDesigner.SelectFull(Item:TListItem);
var
ListView:TListView;
begin
ListView:=TListView(Item.Owner.Owner);
if ListView<>nil then
begin
if ListView.Selected<>nil then
begin
ListView.Selected.Focused:=false;
ListView.Selected.Selected:=false;
end;
end;
if Item<>nil then
begin
Item.Selected:=true;
Item.Focused:=true;
Item.MakeVisible{$IFNDEF LINUX}(false){$ENDIF};
end;
end;
function TfrmKbmMemTableDesigner.DeleteItem(Item:TListItem):TListItem;
var
Index:integer;
ListView:TListView;
begin
ListView:=TListView(Item.Owner.Owner);
Index:=Item.Index;
Item.Delete;
Result:=nil;
if ListView=nil then exit;
if ListView.Items.Count=0 then exit;
if Index>ListView.Items.Count-1 then
SelectFull(ListView.Items[ListView.Items.Count-1])
else
SelectFull(ListView.Items[Index]);
Result:=ListView.Selected;
end;
function TfrmKbmMemTableDesigner.IsInFieldNames(FieldNames,FieldName:string):boolean;
var
p:integer;
s:string;
begin
Result:=false;
p:=1;
while p<=length(FieldNames) do
begin
s:=ExtractFieldName(FieldNames,p);
if s=FieldName then
begin
Result:=true;
break;
end;
end;
end;
procedure TfrmKbmMemTableDesigner.GetDatasets;
var
I: Integer;
procedure AddDatasetsFromForm(CurForm: TComponent);
var
I:integer;
Item:TListItem;
CurComp: TComponent;
begin
{$IFDEF LEVEL6}
{$IFNDEF LINUX}
if (CurForm is TCustomForm) then
begin
if TCustomForm(CurForm).Designer<>nil then
CurForm:=TCustomForm(CurForm).designer.GetRoot;
end;
{$ENDIF}
{$ENDIF}
for i:=CurForm.ComponentCount-1 downto 0 do
begin
CurComp:=CurForm.Components[I];
if (CurComp is TDataSet) and (CurComp<>MemTable) then
begin
Item:=LTV_Datasets.Items.Add;
Item.Caption:= Format('%s.%s', [CurForm.Name, CurComp.Name]);
Item.Data := CurComp;
Item:=LTV_FromDataset.Items.Add;
Item.Caption:= Format('%s.%s', [CurForm.Name, CurComp.Name]);
Item.Data := CurComp;
end;
end;
end;
begin
// Mark as we are Filling the ListView
IsFilling:=true;
try
// Build datasets Listview
LTV_Datasets.Items.Clear;
LTV_FromDataset.Items.Clear;
for I := Screen.CustomFormCount - 1 downto 0 do
AddDatasetsFromForm(Screen.CustomForms[I]);
{$IFNDEF LEVEL6}
for I := Screen.DataModuleCount - 1 downto 0 do
AddDatasetsFromForm(Screen.DataModules[I]);
{$ENDIF}
finally
//Un-Mark as we are Filling the ListView
IsFilling:=false;
end;
end;
{$IFNDEF LINUX}
procedure TfrmKbmMemTableDesigner.GetAliases;
var
TempCursor:hDbiCur;
DB_Description:DBDesc;
Item:TListItem;
begin
// Mark as we are Filling the ListView
IsFilling:=true;
try
// Clear Alias Listview
LTV_Alias.Items.Clear;
Check(DbiOpenDatabaseList(TempCursor));
while (DbiGetNextRecord(TempCursor, dbiNOLOCK, @DB_Description, nil) = DBIERR_NONE) do
begin
Item:=LTV_Alias.Items.Add;
Item.Caption:=DB_Description.szName;
Item.SubItems.Add(DB_Description.szPhyName);
end;
// Close the Cursor
Check(DbiCloseCursor(TempCursor));
finally
//Un-Mark as we are Filling the ListView
IsFilling:=false;
end;
{
// Selected first Item if Possible to fire the Onchange Event
if LTV_Alias.Items.Count>0 then
begin
LTV_Alias.Items[0].Selected:=true;
LTV_Alias.Items[0].Focused:=true;
end;
}
end;
{$ENDIF}
{$IFNDEF LINUX}
procedure TfrmKbmMemTableDesigner.GetTables(DatabaseName: string);
var
Tables:TStringList;
Item:TListItem;
TableNumber:integer;
begin
//Mark as we are Filling the ListView
IsFilling:=true;
try
//Clear Tables Listviews
LTV_Tables.Items.Clear;
LTV_FromTable.Items.Clear;
//Tables Holder for GetTableNames
Tables:=TStringList.Create;
try
//Get Table Names
SES_Dummy.GetTableNames(DatabaseName, '*.*',False, False, Tables);
//Fill de Listview with the Tables Returned
for TableNumber:=0 to Tables.Count-1 do
begin
Item:=LTV_Tables.Items.Add;
Item.Caption:=Tables[TableNumber];
Item:=LTV_FromTable.Items.Add;
Item.Caption:=Tables[TableNumber];
end;
finally
//Free the StringList
Tables.Free;
end;
finally
//Un-Mark as we are Filling the ListView
IsFilling:=False;
end;
//Selected first ITem if Possible to fire the Onchange Event
if LTV_Tables.Items.Count > 0 then
begin
LTV_Tables.Items[0].Selected:=true;
LTV_Tables.Items[0].Focused:=true;
LTV_FromTable.Items[0].Selected:=true;
LTV_FromTable.Items[0].Focused:=true;
end;
RBT_FromTable.Enabled:=LTV_FromTable.Items.Count>0;
end;
{$ENDIF}
procedure TfrmKbmMemTableDesigner.GetActualStructure;
var
i:integer;
Item:TListItem;
begin
//Mark As Filling
IsFilling:=true;
try
//Clear the Listviews
LTV_Structure.Items.Clear;
LTV_Existing.Items.Clear;
LTV_Sort.Items.Clear;
//Fill the FieldDefs
for i:=0 to MemTable.Fields.Count-1 do
begin
with LTV_Structure.Items.Add do
begin
Caption:=MemTable.Fields.Fields[i].FieldName;
SubItems.Add(GetEnumName(Typeinfo(TFieldType),Ord(MemTable.Fields.Fields[i].DataType)));
SubItems.Add(IntToStr(MemTable.Fields.Fields[i].Size));
end;
// Possible sort fields not yet used.
Item:=LTV_Existing.Items.Add;
Item.Caption:=MemTable.Fields.Fields[i].FieldName;
if IsInFieldNames(MemTable.SortFields,Item.Caption) then
begin
with LTV_Sort.Items.Add do
Caption:=Item.Caption;
DeleteItem(Item);
end;
end;
finally
//Un-Mark As Filling
IsFilling:=False;
end;
//Selected first Item if Possible to fire the Onchange Event
if LTV_Structure.Items.Count>0 then
begin
LTV_Structure.Items[0].Selected:=true;
LTV_Structure.Items[0].Focused:=true;
LTV_Existing.Items[0].Selected:=true;
LTV_Existing.Items[0].Focused:=true;
end;
//ActualStructure Panel
PAN_ActualStructure.Enabled:=LTV_Structure.Items.Count>0;
//Sort Panel
PAN_Sort.Enabled:=LTV_Existing.Items.Count>0;
BTN_Sort.Enabled:=false;
//Force the Buttons Syncronization
LTV_ExistingChange(Self,nil,ctState);
LTV_SortChange(Self,nil,ctState);
end;
procedure TfrmKbmMemTableDesigner.CheckAvailData;
begin
if MemTable.Fields.Count>0 then
MemTable.Active:=true;
//Sort Panel
PAN_Sort.Enabled:=LTV_Existing.Items.Count>0;
BTN_Sort.Enabled:=(LTV_Sort.Items.Count>0) and (MemTable.Active) and (MemTable.RecordCount>0);
LTB_SortOptions.Enabled:=LTV_Sort.Items.Count>0;
//Force the Buttons Synchronization
LTV_ExistingChange(Self,nil,ctState);
LTV_SortChange(Self,nil,ctState);
if (MemTable.Active) and (MemTable.RecordCount>0) then
begin
PAN_DataDesign.Enabled:=true;
DTS_DataDesign.DataSet:=MemTable;
DTS_DataDesign.Enabled:=true;
DTS_DataDesign.AutoEdit:=true;
BTN_Save.Enabled:=true;
end
else
begin
PAN_DataDesign.Enabled:=false;
DTS_DataDesign.DataSet:=nil;
DTS_DataDesign.Enabled:=false;
DTS_DataDesign.AutoEdit:=false;
BTN_Save.Enabled:=false;
end;
end;
{$IFDEF LINUX}
function CreateUniqueName(Dataset:TkbmCustomMemTable; FieldClass:TFIeldClass; FieldName:string; Field:TField):string;
var
i1,i2:integer;
s:string;
unique:boolean;
begin
for i1:=1 to MaxInt do
begin
s:=Format('%s%s%d',[FieldClass.ClassName,FieldName,i1]);
// Check if unique.
with Dataset.Owner do
begin
unique:=true;
for i2:=0 to ComponentCount-1 do
begin
if (Components[i2]<>Field) and (CompareText(Components[i2].Name,s)=0) then
begin
unique:=false;
break;
end;
end;
if unique then
begin
Result:=s;
exit;
end;
end;
end;
end;
{$ENDIF}
procedure TfrmKbmMemTableDesigner.CreateFields;
var
i:integer;
Field:TField;
begin
MemTable.DeleteTable;
with MemTable.FieldDefs do
begin
for i:=0 to Count-1 do
begin
Field:=Items[i].CreateField(MemTable.Owner,nil,Items[i].Name,false);
try
Field.Origin:='';
{$IFNDEF LINUX}
Field.Name := DSDesign.CreateUniqueName(MemTable, Items[i].Name, TFieldClass(Items[i].ClassType), nil);
{$ELSE}
Field.Name := CreateUniqueName(MemTable, TFieldClass(Items[i].ClassType), Items[i].Name, nil);
{$ENDIF}
except
Field.Free;
raise;
end;
end;
end;
end;
{$IFNDEF LINUX}
procedure TfrmKbmMemTableDesigner.LoadStructure(TableName:string);
var
Table:TTable;
begin
//First We Create a Table that Will hold the Table
Table:=TTable.Create(Self);
try
//Assign the Values to the Table
Table.DatabaseName:=LTV_Alias.Selected.Caption;
Table.TableName:=TableName;
//Call the Procedure that Fills the fieldDefs
with MemTable do
begin
MemTable.Active:=false;
CreateTableAs(Table,[mtcpoStructure]);
end;
CreateFields;
finally
//Free the Table
Table.Free;
end;
//Refresh the Actual Structure
GetActualStructure;
end;
{$ENDIF}
procedure TfrmKbmMemTableDesigner.TransAll(Source,Dest:TListView);
var
Item:TListItem;
i:integer;
begin
//Mark as filling
IsFilling:=true;
try
for i:= 0 to Source.Items.Count-1 do
begin
Item:=Dest.Items.Add;
Item.Caption := Source.Items[i].Caption;
end;
//Clear Existing
Source.Items.Clear;
finally
//UnMark filling
IsFilling:=false;
end;
if Dest.Items.Count > 0 then
begin
Dest.Items[0].Selected:=true;
Dest.Items[0].Focused:=true;
end;
//Force the Buttons Syncronization
LTV_ExistingChange(Self,nil,ctState);
LTV_SortChange(Self,nil,ctState);
end;
procedure TfrmKbmMemTableDesigner.CopyItem(SourceItem:TListITem; Dest:TListView);
var
Item:TListItem;
begin
Item:=Dest.Items.Add;
Item.Caption:=SourceItem.Caption;
DeleteItem(SourceItem);
Item.Selected:=true;
Item.MakeVisible{$IFNDEF LINUX}(false){$ENDIF};
//Force the Buttons Sincronization.
LTV_ExistingChange(Self,nil,ctState);
LTV_SortChange(Self,nil,ctState);
end;
procedure TfrmKbmMemTableDesigner.StoreSortSetup;
var
i:integer;
s,a:string;
CompareOptions:TkbmMemTableCompareOptions;
begin
// Store sort fields.
if LTV_Sort.Items.Count>0 then
begin
a:='';
for i:=0 to LTV_Sort.Items.Count-1 do
begin
s:=s+a+LTV_Sort.Items[i].Caption;
a:=';';
end;
MemTable.SortFields:=s;
end;
// Store sort options.
CompareOptions := [];
if LTB_SortOptions.Items.Count>0 then
begin
for i:=ord(Low(TkbmMemTableCompareOption)) to ord(High(TkbmMemTableCompareOption)) do
if LTB_SortOptions.Checked[i] then
CompareOptions := CompareOptions + [TkbmMemTableCompareOption(i)];
MemTable.SortOptions:=CompareOptions;
end;
Designer.Modified;
end;
procedure TfrmKbmMemTableDesigner.CopyDataSet(Source: TDataSet; Dest: TDataSet;Visual: boolean);
var
i:integer;
begin
if Visual then
begin
//Progress
LAB_Progress.Visible:=true;
PRO_Records.Position:=0;
PRO_Records.Max:=Source.RecordCount;
PRO_Records.Visible:=true;
Application.ProcessMessages;
end;
//First Record of Source
Source.First;
//Read all the Records
TkbmMemTable(Dest).IgnoreReadOnly:=true;
try
while not Source.EOF do
begin
try
Dest.Insert;
for i:=0 to Source.Fields.Count-1 do
begin
try
Dest.FieldByName(Source.Fields[i].FieldName).Value:=Source.Fields[i].Value;
except
on E: Exception do
begin
MessageDlg('An error ocurred while trying to append a tecord to the memory table: '+E.Message,mtError,[mbOk],0);
Dest.Cancel;
exit;
end;
end;
end;
Dest.Post;
except
on E: Exception do
begin
MessageDlg('An error ocurred while trying to append a tecord to the memory table: '+E.Message,mtError,[mbOk],0);
Dest.Cancel;
exit;
end;
end;
if Visual then PRO_Records.Position:=PRO_Records.Position + 1;
//Next Record
Source.Next;
end;
finally
TkbmMemTable(Dest).IgnoreReadOnly:=false;
end;
If Visual then
begin
//Progress
LAB_Progress.Visible:=false;
PRO_Records.Visible:=false;
end;
end;
procedure TfrmKbmMemTableDesigner.FormCreate(Sender: TObject);
begin
//Set the Active Page
PGC_Options.ActivePage := TBS_BorrowStructure;
end;
procedure TfrmKbmMemTableDesigner.FormShow(Sender: TObject);
var
i:integer;
begin
if MemTable <> nil then
begin
//PageControl
PGC_Options.Enabled:=true;
//Caption
Caption:=Format('%s [%s]',[KbmMemTableDesignerVersion,MemTable.Name]);
//TBS_BorrowStructure
//First We get the Aliases
{$IFNDEF LINUX}
SES_Dummy.Active := True;
GetAliases;
{Depending on the Amount of Items}
if LTV_Alias.Items.Count > 0 then
begin
//Panels
PAN_BorrowStructure.Enabled := True;
//ListViews
//Tables ListView Filled on the Onchange Event of the LTV_Alias Listview
//buttons Arranged by the Onchange Event Also
end
else
begin
//ListViews
LTV_Alias.Items.Clear;
LTV_Tables.Items.Clear;
//Panels
PAN_BorrowStructure.Enabled:=false;
//Buttons
BTN_GetStructure.Enabled:=false;
BTN_Refresh.Enabled:=false;
end;
{$ENDIF}
GetDatasets;
//TBS_ActualStructure
GetActualStructure;
//Panel Controled by the GetActualStructure Procedure
//TBS_Data
//Panels
PAN_FromTable.Enabled:=false;
//RadioButtons &checkBoxes
RBT_FromFile.Checked:=true;
CHK_Binary.Enabled:=true;
CHK_Binary.Checked:=true;
CHK_OnlyData.Enabled:=true;
CHK_OnlyData.Checked:=true;
//RBT_FromTable Set on the GetTables Procedure
//Edits
EDT_File.Text:=TKbmMemTable(MemTable).PersistentFile;
//Buttons
BTN_SelectFileName.Enabled:=true;
BTN_Load.Enabled:=FileExists(EDT_File.Text);
//ProgressBar
PRO_Records.Visible:=false;
LAB_Progress.Visible:=false;
//TBS_DataDesign
CheckAvailData;
//TBS_Sort
//Controled by the GetActualStructure
//SortOptions
LTB_SortOptions.Items.Clear;
for i:=ord(Low(TkbmMemTableCompareOption)) to ord(High(TkbmMemTableCompareOption)) do
LTB_SortOptions.Items.Add(GetEnumName(Typeinfo(TkbmMemTableCompareOption),i));
end
else
begin
//If the Owner is not correctly passed then Disable All
//Caption
Caption:=Format('%s (MemTable not found)',[KbmMemTableDesignerVersion]);
//PageControl
PGC_Options.Enabled:=false;
//TBS_BorrowStructure
//ListViews}
{$IFNDEF LINUX}
LTV_Alias.Items.Clear;
LTV_Tables.Items.Clear;
{$ENDIF}
//Panels
PAN_BorrowStructure.Enabled:=false;
//Buttons
BTN_GetStructure.Enabled:=false;
BTN_Refresh.Enabled:=false;
//TBS_ActualStructure
PAN_ActualStructure.Enabled:=false;
//TBS_Data
//Panels
PAN_Data.Enabled:=false;
//Edits
EDT_File.Text:='';
//CheckBoxes
CHK_Binary.Checked:=false;
CHK_Binary.Enabled:=false;
CHK_OnlyData.Checked:=false;
CHK_OnlyData.Enabled:=false;
//Listviews
LTV_FromTable.Items.Clear;
//Buttons
BTN_Load.Enabled:=false;
BTN_SelectFileName.Enabled:=false;
BTN_Save.Enabled:=false;
//ProgressBar
PRO_Records.Visible:=false;
LAB_Progress.Visible:=false;
//TBS_DataDesign
PAN_DataDesign.Enabled:=false;
DTS_DataDesign.DataSet:=nil;
DTS_DataDesign.Enabled:=false;
DTS_DataDesign.AutoEdit:=false;
//TBS_Sort
//Panels
PAN_Sort.Enabled:=false;
//Listviews
LTV_Existing.Items.Clear;
LTV_Sort.Items.Clear;
//Listboxes
LTB_SortOptions.Items.Clear;
LTB_SortOptions.Enabled:=false;
//Buttons
BTN_Sort.Enabled:=false;
BTN_SEL_All.Enabled:=false;
BTN_SEL_Selected.Enabled:=false;
BTN_UNS_Selected.Enabled:=false;
BTN_UNS_All.Enabled:=false;
BTN_ORD_First.Enabled:=false;
BTN_ORD_Last.Enabled:=false;
BTN_ORD_Plus.Enabled:=false;
BTN_ORD_Minus.Enabled:=false;
end;
end;
procedure TfrmKbmMemTableDesigner.FormClose(Sender: TObject;var Action: TCloseAction);
begin
try
//Close the Session
StoreSortSetup;