-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTOOLDB.BAK
886 lines (849 loc) · 22.9 KB
/
TOOLDB.BAK
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
{ Cette unit‚ offre divers services particulier pour les bases de donn‚es
comme par exemple permet la conversion en langage SQL de donn‚es binaires.
}
Unit ToolDB;
{$I DEF.INC}
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
INTERFACE
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
Uses ResTex;
Function DBChoice(X1,Y1,X2,Y2:Byte;Const Title,TableName:String;Column:Byte):String;
Procedure DBLInit(Var Q:DBListBox;X1,Y1,X2,Y2:Byte;Const Title,TableName:String;Column:Byte);
Procedure DBLOpen(Var Q:DBListBox;X1,Y1,X2,Y2:Byte;Const Title,PathDB,TableName:String;Column:Byte);
Procedure DBLDn(Var Q:DBListBox);
Procedure DBLEnd(Var Q:DBListBox);
Procedure DBLHome(Var Q:DBListBox);
Procedure DBLPgUp(Var Q:DBListBox);
Procedure DBLPgDn(Var Q:DBListBox);
Procedure DBLPutLine(Var Q:DBListBox);
Function DBLReadLine(Var Q:DBListBox;P:Word):String;
Procedure DBLSearchName(Var Q:DBListBox;Const Name:String);
Procedure DBLSelectBar(Var Q:DBListBox);
Function DBLRun(Var Q:DBListBox):Word;
Procedure DBLShowList(Var Q:DBListBox);
Procedure DBLUnSelectBar(Var Q:DBListBox);
Procedure DBLUp(Var Q:DBListBox);
Procedure DBLDone(Var Q:DBListBox);
Procedure DBSQLToDataBase(Const SourceName,TargetName:String);
Procedure DBToExcel(Const SourceName,TargetName:String);
Procedure DBToLotus(Const SourceName,TargetName:String);
Procedure DBToSQL(Const SourceName,TargetName:String);
Procedure DBToMGC(Const SourceName,TargetName:String);
Procedure DBConversionToSQL(Var Q:DataSet;Const TargetName:String);
Procedure DBConversionToExcel21(Var Q:DataSet;Const TargetName:String);
Procedure DBConversionToLotus(Var Q:DataSet;Const TargetName:String);
Procedure DBConversionToMGC(Var Q:DataSet;Const TargetName:String);
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
IMPLEMENTATION
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
Uses
Isatex,Systex,Systems,Dials,Dialex,ResServD,ResSaveD,Mouse,Math,Calcex;
Procedure OnStatusCompiler(Var Q;Var Context;Line:LongInt);Far;
Var
W:Window Absolute Context;
Begin
WEPutTxtXY(W,33,5,CStr(Line));
End;
Procedure PutFrameDialog(Var W:Window;Const SourceName,TargetName,Title,Status:String);Begin
WEInitO(W,60,10);
WEPushWn(W);
WEPutWnKrDials(W,Title);
WEBar(W);
WELn(W);
WEPutTxtLn(W,'tat = '+Status);
WEPutTxtLn(W,'Source principal = '+Path2NoDir(SourceName));
WEPutTxtLn(W,'Source courante = '+Path2NoDir(SourceName));
WEPutTxtLn(W,'Nom du programme de sortie = '+Path2NoDir(TargetName));
WEPutTxtLn(W,'Nombre de ligne(s) compil‚ =');
End;
Procedure DBSQLToDataBase(Const SourceName,TargetName:String);
Var
Handle:Hdl;
DS:DataSet;
W:Window;
List:ArrayList;
Begin
FillClr(List,SizeOf(List));
Handle:=FileOpen(SourceName,fmRead);
If(Handle=errHdl)Then ErrNoMsgOk(errFileNotFound)
Else
Begin
DBInit(DS,TargetName);
PutFrameDialog(W,SourceName,TargetName,'Compilation','Compilation');
DS.OnStatusCompiler:=OnStatusCompiler;
DS.OnStatusCompilerContext:=@W;
If Not DBCreateWithSQL(DS,List,Handle)Then ErrNoMsgOk(SQLError);
WEPutTxtXY(W,33,1,StrUSpc('Terminer.',32));
While WEOk(W)do;
WEDone(W);
DBDone(DS);
FileClose(Handle);
End;
End;
Procedure DBToSQL(Const SourceName,TargetName:String);
Var
Q:DataSet;
Begin
DBInit(Q,SourceName);
DBConversionToSQL(Q,TargetName);
DBDone(Q);
End;
Procedure DBToLotus(Const SourceName,TargetName:String);
Var
Q:DataSet;
Begin
DBInit(Q,SourceName);
DBConversionToLotus(Q,TargetName);
DBDone(Q);
End;
Procedure DBToExcel(Const SourceName,TargetName:String);
Var
Q:DataSet;
Begin
DBInit(Q,SourceName);
DBConversionToExcel21(Q,TargetName);
DBDone(Q);
End;
Procedure DBToMGC(Const SourceName,TargetName:String);
Var
Q:DataSet;
Begin
DBInit(Q,SourceName);
DBConversionToMGC(Q,TargetName);
DBDone(Q);
End;
Procedure DBConversionToSQL(Var Q:DataSet;Const TargetName:String);
Var
Handle:Hdl;
I,J:Integer; { Compteur de boucle }
Num:Boolean; { Nombre? }
BB:^Byte;
BC:^Char Absolute BB;
BI:^Integer Absolute BB;
BL:^LongInt Absolute BB;
BO:^Boolean Absolute BB;
BS:^String Absolute BB;
BW:^Word Absolute BB;
W:Window;
Line:LongInt;
S:String;
Data:Array[0..4095]of Byte;
Begin
Line:=0;
PutFrameDialog(W,Q.FileName,TargetName,'D‚compilation','D‚compilation');
Handle:=FileCreateAndBackup(TargetName);
If(Handle<>errHdl)Then Begin
PutFileTxtLn(Handle,'CREATE TABLE '+Q.RealName+' (');
For I:=0to Q.FieldRec.Num-1do Begin
PutFileTxt(Handle,' '+StrUSpc(StrPas(Q.FieldRec.Buffer^[I].Title),20)+' ');
Case(Q.FieldRec.Buffer^[I].TypeDef)of
tdBlob:PutFileTxt(Handle,'BLOB');
tdBoolean:PutFileTxt(Handle,'BOOLEAN');
tdByte:PutFileTxt(Handle,'BYTE');
tdChar:Begin
PutFileTxt(Handle,'CHAR');
If Q.FieldRec.Buffer^[I].Len<>0Then PutFileTxt(Handle,'('+WordToStr(Q.FieldRec.Buffer^[I].Len-1)+')');
End;
tdDirectChar:Begin
PutFileTxt(Handle,'CHAR');
If Q.FieldRec.Buffer^[I].Len<>0Then PutFileTxt(Handle,'('+WordToStr(Q.FieldRec.Buffer^[I].Len)+')');
End;
tdDate:PutFileTxt(Handle,'DATE');
tdDecimal:PutFileTxt(Handle,'DECIMAL');
tdDouble:PutFileTxt(Handle,'DOUBLE');
tdFloat:PutFileTxt(Handle,'FLOAT');
tdInteger:PutFileTxt(Handle,'INTEGER');
tdSmallInt:PutFileTxt(Handle,'SMALLINT');
tdVarChar:PutFileTxt(Handle,'VARCHAR');
tdWord:PutFileTxt(Handle,'WORD');
tdNumeric:Begin
PutFileTxt(Handle,'NUMERIC');
If Q.FieldRec.Buffer^[I].Len<>0Then Begin
PutFileTxt(Handle,'('+WordToStr(Q.FieldRec.Buffer^[I].Len-1));
If Q.FieldRec.Buffer^[I].Decimal<>0Then Begin
PutFileTxt(Handle,','+WordToStr(Q.FieldRec.Buffer^[I].Decimal));
End;
PutFileTxt(Handle,')');
End;
End;
End;
If(Q.FieldRec.Buffer^[I].PrimaryKey)Then PutFileTxt(Handle,' PRIMARY KEY');
If(Q.FieldRec.Buffer^[I].NotNull)Then PutFileTxt(Handle,' NOT NULL');
If I<Q.FieldRec.Num-1Then PutFileTxtLn(Handle,',')
Else PutFileLn(Handle);
End;
PutFileTxtLn(Handle,');');
PutFileLn(Handle);
If(dsIndex)in(Q.Attribut)Then Begin
PutFileTxtLn(Handle,'CREATE INDEX;');
PutFileLn(Handle);
End;
DBFirst(Q);
Repeat
DBReadRec(Q,Data);
PutFileTxt(Handle,'INSERT INTO '+Q.RealName+' VALUES (');
For I:=0to Q.FieldRec.Num-1do Begin
BB:=@Data;
DBGotoColumnAbs(Q,I,Pointer(BB));
Case(Q.FieldRec.Buffer^[I].TypeDef)of
tdBoolean:If BO^Then PutFileTxt(Handle,'True ')
Else PutFileTxt(Handle,'False');
tdByte:PutFileTxt(Handle,'0x'+HexByte2Str(BB^));
tdChar:Begin
If Q.FieldRec.Buffer^[I].Len=0Then PutFileTxt(Handle,''''+BC^+'''')
Else
Begin
S:='';
For J:=1to Length(BS^)do Begin
Case BS^[J]of
#0..' ':IncStr(S,' ');
'''':AddStr(S,'''''');
Else IncStr(S,BS^[J]);
End;
End;
PutFileTxt(Handle,''''+S+'''');
End;
End;
tdInteger:PutFileTxt(Handle,IntToStr(BL^));
tdSmallInt:PutFileTxt(Handle,IntToStr(BI^));
tdVarChar:PutFileTxt(Handle,''''+BS^+'''');
tdDirectChar:Begin
S:=LoadStr(BS^,Q.FieldRec.Buffer^[I].Len);
ChgChr(S,#0,' ');
PutFileTxt(Handle,''''+S+'''');
End;
tdNumeric:Begin
S:=LoadStr(BS^,Q.FieldRec.Buffer^[I].Len);
ChgChr(S,#0,' ');
Num:=False;
For J:=1to Length(S)do If S[J]in['0'..'9']Then Begin
Num:=True;
Break;
End;
If Not(Num)Then S[1]:='0';
PutFileTxt(Handle,S);
End;
tdWord:PutFileTxt(Handle,'0x'+HexWord2Str(BW^));
End;
If I<Q.FieldRec.Num-1Then PutFileTxt(Handle,',');
End;
PutFileTxtLn(Handle,');');
Inc(Line);
WEPutTxtXY(W,33,5,CStr(Line));
If Q.CurrPos<0Then Break;
Until DBEOF(Q);
FileClose(Handle);
End;
WEPutTxtXY(W,33,1,StrUSpc('Terminer.',32));
While WEOk(W)do;
WEDone(W);
Q.OnStatusCompiler:=NIL;
Q.OnStatusCompilerContext:=NIL;
End;
Procedure DBConversionToExcel21(Var Q:DataSet;Const TargetName:String);
Var
Handle:Hdl;
I,J:Word;
W:Window;
BB:^Byte;
BC:^Char Absolute BB;
BI:^Integer Absolute BB;
BL:^LongInt Absolute BB;
BO:^Boolean Absolute BB;
BS:^String Absolute BB;
BW:^Word Absolute BB;
Buffer:Array[0..511]of Byte;
SignExcel:BOFExcel Absolute Buffer;
Label4Excel:LabelExcel Absolute Buffer;
Number4Excel:NumberExcel Absolute Buffer;
Integer4Excel:IntegerExcel Absolute Buffer;
EOF4Excel:EOFExcel Absolute Buffer;
S:String;
Data:Array[0..4095]of Byte;
Begin
PutFrameDialog(W,Q.FileName,TargetName,'Exportation en Excel 2.1','Conversion');
Handle:=FileCreateAndBackup(TargetName);
If(Handle<>errHdl)Then Begin
{ Microsoft Excel 2.1 }
FillClr(SignExcel,SizeOf(SignExcel));
{ SignExcel.Length:=6;
SignExcel.TypeCode:=$0009;}
SignExcel.Length:=6;
SignExcel.TypeCode:=$0209;
_SetRec(Handle,SizeOf(SignExcel),SignExcel);
{D‚finition de la premiŠre ligne}
For I:=0to Q.FieldRec.Num-1do Begin
S:=StrPas(Q.FieldRec.Buffer^[I].Title);
Case(Q.FieldRec.Buffer^[I].TypeDef)of
tdChar:If Q.FieldRec.Buffer^[I].Len=0Then
AddStr(S,',C,1')
Else
AddStr(S,',C,'+IntToStr(Q.FieldRec.Buffer^[I].Len));
End;
FillClr(Label4Excel,SizeOf(Label4Excel));
Label4Excel.Column:=I;
Label4Excel.Row:=0;
Label4Excel.TypeCode:=xltLabel;
Label4Excel.Length:=SizeOf(Label4Excel)-4-SizeOf(String)+Length(S)+2;
Label4Excel.Value:=''''+S;
_SetRec(Handle,Label4Excel.Length+4,Label4Excel);
End;
{criture du corps}
DBFirst(Q);
I:=0;J:=1;
Repeat
DBReadRec(Q,Data);
For I:=0to Q.FieldRec.Num-1do Begin
FillClr(Label4Excel,SizeOf(Label4Excel));
Label4Excel.Column:=I;
Label4Excel.Row:=J;
BB:=@Data;
DBGotoColumnAbs(Q,I,Pointer(BB));
Case(Q.FieldRec.Buffer^[I].TypeDef)of
tdVarChar:Begin
Label4Excel.TypeCode:=xltLabel;
Label4Excel.Length:=SizeOf(Label4Excel)-4-SizeOf(String)+Length(BS^)+2;
Label4Excel.Value:=''''+BS^;
_SetRec(Handle,Label4Excel.Length+4,Label4Excel);
End;
tdDirectChar:Begin
S:=LoadStr(BS^,Q.FieldRec.Buffer^[I].Len);
ChgChr(S,#0,' ');
Label4Excel.TypeCode:=xltLabel;
Label4Excel.Length:=SizeOf(Label4Excel)-4-SizeOf(String)+Length(BS^)+2;
Label4Excel.Value:=''''+S;
_SetRec(Handle,Label4Excel.Length+4,Label4Excel);
End;
tdInteger:Begin
Number4Excel.TypeCode:=xltNumber;
Number4Excel.Length:=SizeOf(Label4Excel)-4;
RealToDouble(BL^,Number4Excel.Value);
_SetRec(Handle,Number4Excel.Length+4,Number4Excel);
End;
tdWord:Begin
Integer4Excel.TypeCode:=xltInteger;
Integer4Excel.Length:=SizeOf(Integer4Excel)-4;
Integer4Excel.Value:=BW^;
_SetRec(Handle,Integer4Excel.Length+4,Integer4Excel);
End;
End;
End;
Inc(J);
WEPutTxtXY(W,33,5,CStr(J));
Until DBEOF(Q);
EOF4Excel.TypeCode:=xltEOF;
EOF4Excel.Length:=SizeOf(EOF4Excel);
_SetRec(Handle,SizeOf(EOF4Excel),EOF4Excel);
FileClose(Handle);
End;
WEPutTxtXY(W,33,1,StrUSpc('Terminer.',32));
While WEOk(W)do;
WEDone(W);
End;
Procedure DBConversionToLotus(Var Q:DataSet;Const TargetName:String);
Var
Handle:Hdl;
LLabel:LabelLotus123;
LHeader:HeaderLotus123 Absolute LLabel;
LEnd:EndLotus123 Absolute LHeader;
LDouble:DoubleLotus123 Absolute LHeader;
BB:^Byte;
BC:^Char Absolute BB;
BI:^Integer Absolute BB;
BL:^LongInt Absolute BB;
BO:^Boolean Absolute BB;
BS:^String Absolute BB;
BW:^Word Absolute BB;
W:Window;
I,J:Word;
S:String;
Data:Array[0..4095]of Byte;
Begin
PutFrameDialog(W,Q.FileName,TargetName,'Exportation en Lotus 1-2-3','Conversion');
Handle:=FileCreateAndBackup(TargetName);
If(Handle<>errHdl)Then Begin
{criture de l'entˆte}
LHeader.TypeCode:=0;
LHeader.Length:=2;
LHeader.Value:=1030;
_SetRec(Handle,SizeOf(LHeader),LHeader);
{D‚finition de la premiŠre ligne}
For I:=0to Q.FieldRec.Num-1do Begin
S:=StrPas(Q.FieldRec.Buffer^[I].Title);
Case(Q.FieldRec.Buffer^[I].TypeDef)of
tdChar:If Q.FieldRec.Buffer^[I].Len=0Then
AddStr(S,',C,1')
Else
AddStr(S,',C,'+IntToStr(Q.FieldRec.Buffer^[I].Len));
End;
FillClr(LLabel,SizeOf(LLabel));
LLabel.Column:=I;
LLabel.TypeCode:=$0F;
LLabel.Length:=Length(S)+7;
LLabel.Format:=$FF;
LLabel.Text[0]:='''';
StrPascalCopy(LLabel.Text[1],239,S);
_SetRec(Handle,Length(S)+11,LLabel);
End;
{criture du corps}
DBFirst(Q);
I:=0;J:=1;
Repeat
DBReadRec(Q,Data);
For I:=0to Q.FieldRec.Num-1do Begin
FillClr(LLabel,SizeOf(LLabel));
LLabel.Column:=I;
LLabel.Row:=J;
BB:=@Data;
DBGotoColumnAbs(Q,I,Pointer(BB));
Case(Q.FieldRec.Buffer^[I].TypeDef)of
tdVarChar:Begin
LLabel.TypeCode:=$0F;
LLabel.Length:=Length(BS^)+7;
LLabel.Format:=$FF;
LLabel.Text[0]:='''';
StrPascalCopy(LLabel.Text[1],239,BS^);
_SetRec(Handle,Length(BS^)+11,LLabel);
End;
tdChar:Begin
If Q.FieldRec.Buffer^[I].Len=0Then S:=BC^
Else
Begin
S:='';
For J:=1to Length(BS^)do Begin
Case BS^[J]of
#0..' ':IncStr(S,' ');
'''':AddStr(S,'''''');
Else IncStr(S,BS^[J]);
End;
End;
End;
LLabel.TypeCode:=$0F;
LLabel.Length:=Length(S)+7;
LLabel.Format:=$FF;
LLabel.Text[0]:='''';
StrPascalCopy(LLabel.Text[1],239,S);
_SetRec(Handle,Length(S)+11,LLabel);
End;
tdDirectChar:Begin
S:=LoadStr(BS^,Q.FieldRec.Buffer^[I].Len);
ChgChr(S,#0,' ');
LLabel.TypeCode:=$0F;
LLabel.Length:=Length(S)+7;
LLabel.Format:=$FF;
LLabel.Text[0]:='''';
StrPascalCopy(LLabel.Text[1],239,S);
_SetRec(Handle,Length(S)+11,LLabel);
End;
tdInteger:Begin
LDouble.TypeCode:=$E;
LDouble.Length:=13;
LDouble.Format:=2 or 128;
RealToDouble(BL^,LDouble.Value);
_SetRec(Handle,17,LDouble);
End;
tdSmallInt:Begin
LDouble.TypeCode:=$E;
LDouble.Length:=13;
LDouble.Format:=2 or 128;
RealToDouble(BI^,LDouble.Value);
_SetRec(Handle,17,LDouble);
End;
tdWord:Begin
LDouble.TypeCode:=$E;
LDouble.Length:=13;
LDouble.Format:=2 or 128;
RealToDouble(BW^,LDouble.Value);
_SetRec(Handle,17,LDouble);
End;
tdByte:Begin
LDouble.TypeCode:=$E;
LDouble.Length:=13;
LDouble.Format:=2 or 128;
RealToDouble(BB^,LDouble.Value);
_SetRec(Handle,17,LDouble);
End;
End;
End;
Inc(J);
WEPutTxtXY(W,33,5,CStr(J));
Until DBEOF(Q);
{criture de la fin}
LEnd.TypeCode:=1;
LEnd.Length:=0;
_SetRec(Handle,SizeOf(LEnd),LEnd);
FileClose(Handle);
End;
WEPutTxtXY(W,33,1,StrUSpc('Terminer.',32));
While WEOk(W)do;
WEDone(W);
Q.OnStatusCompiler:=NIL;
Q.OnStatusCompilerContext:=NIL;
End;
Procedure DBConversionToMGC(Var Q:DataSet;Const TargetName:String);
Var
Handle:Hdl;
Cellule:DataMGCIdRec;
Value:CelluleValue;
BB:^Byte;
BC:^Char Absolute BB;
BI:^Integer Absolute BB;
BL:^LongInt Absolute BB;
BO:^Boolean Absolute BB;
BS:^String Absolute BB;
BW:^Word Absolute BB;
W:Window;
I,J:Word;
S:String;
Data:Array[0..4095]of Byte;
Begin
PutFrameDialog(W,Q.FileName,TargetName,'Exportation en MGC','Conversion');
Handle:=NewNBak(TargetName);
If(Handle<>errHdl)Then Begin
{criture de l'entˆte}
PutFileTxt(Handle,'MGC'#26);
{D‚finition de la premiŠre ligne}
For I:=0to Q.FieldRec.Num-1do Begin
S:=StrPas(Q.FieldRec.Buffer^[I].Title);
Case(Q.FieldRec.Buffer^[I].TypeDef)of
tdChar:If Q.FieldRec.Buffer^[I].Len=0Then
AddStr(S,',C,1')
Else
AddStr(S,',C,'+IntToStr(Q.FieldRec.Buffer^[I].Len));
End;
FillClr(Cellule,SizeOf(Cellule));
Cellule.Col:=I;
Cellule.H.Format:=cfText;
Cellule.H.Attribut:=$70;
Cellule.Size:=Length(S)+1;
_SetRec(Handle,SizeOf(Cellule),Cellule);
_SetRec(Handle,Cellule.Size,S);
End;
{criture du corps}
DBFirst(Q);
I:=0;J:=1;
Repeat
DBReadRec(Q,Data);
For I:=0to Q.FieldRec.Num-1do Begin
FillClr(Cellule,SizeOf(Cellule));
FillClr(Value,SizeOf(Value));
Cellule.H.Attribut:=$F0;
Cellule.Col:=I;
Cellule.Row:=J;
BB:=@Data;
DBGotoColumnAbs(Q,I,Pointer(BB));
Case(Q.FieldRec.Buffer^[I].TypeDef)of
tdVarChar:Begin
Cellule.H.Format:=cfText;
Cellule.Size:=Length(BS^)+1;
S:=BS^;
End;
tdChar:Begin
If Q.FieldRec.Buffer^[I].Len=0Then S:=BC^
Else
Begin
S:='';
For J:=1to Length(BS^)do Begin
Case BS^[J]of
#0..' ':IncStr(S,' ');
'''':AddStr(S,'''''');
Else IncStr(S,BS^[J]);
End;
End;
End;
Cellule.H.Format:=cfText;
Cellule.Size:=Length(S)+1;
End;
tdDirectChar:Begin
S:=LoadStr(BS^,Q.FieldRec.Buffer^[I].Len);
ChgChr(S,#0,' ');
Cellule.H.Format:=cfText;
Cellule.Size:=Length(S)+1;
End;
tdInteger:Begin
Cellule.H.Format:=cfValue;
Cellule.Size:=SizeOf(Value.Value);
Value.Value:=BL^;
End;
tdSmallInt:Begin
Cellule.H.Format:=cfValue;
Cellule.Size:=SizeOf(Value.Value);
Value.Value:=BI^;
End;
tdWord:Begin
Cellule.H.Format:=cfValue;
Cellule.Size:=SizeOf(Value.Value);
Value.Value:=BW^;
End;
tdByte:Begin
Cellule.H.Format:=cfValue;
Cellule.Size:=SizeOf(Value.Value);
Value.Value:=BB^;
End;
End;
_SetRec(Handle,SizeOf(Cellule),Cellule);
Case(Cellule.H.Format)of
cfText:_SetRec(Handle,Cellule.Size,S);
cfValue:_SetRec(Handle,Cellule.Size,Value);
End;
End;
Inc(J);
WEPutTxtXY(W,33,5,CStr(J));
Until DBEOF(Q);
{criture de la fin}
FileClose(Handle);
End;
WEPutTxtXY(W,33,1,StrUSpc('Terminer.',32));
While WEOk(W)do;
WEDone(W);
Q.OnStatusCompiler:=NIL;
Q.OnStatusCompilerContext:=NIL;
End;
Function DBLReadLine(Var Q:DBListBox;P:Word):String;
Var
PBuffer:Pointer;
PString:^String Absolute PBuffer;
Buffer:Array[0..1023]of Byte;
Begin
{ DBMoveTo(ChantalServer,P);
DBReadRec(ChantalServer,Buffer);
PBuffer:=@Buffer;
DBGotoColumnAbs(ChantalServer,Q.ColumnNum,PBuffer);
DBLReadLine:=PString^;}
DBMoveTo(Q.DB,P);
DBReadRec(Q.DB,Buffer);
PBuffer:=@Buffer;
DBGotoColumnAbs(Q.DB,Q.ColumnNum,PBuffer);
DBLReadLine:=PString^;
End;
Procedure DBLSelectBar(Var Q:DBListBox);Begin
WESetKrSel(Q.W);
WEBarSelHor(Q.W,0,Q.Y,wnMax);
End;
Procedure DBLUnSelectBar(Var Q:DBListBox);Begin
If(IsBanderolle)Then Begin
WEBarSpcHorBanderolle(Q.W,Q.Y,Q.P);
WEPutTxtXYT(Q.W,0,Q.Y,DBLReadLine(Q,Q.P));
End
Else
Begin
WESetKrBorder(Q.W);
WEBarSelHor(Q.W,0,Q.Y,wnMax);
End;
End;
Procedure DBLPutLine(Var Q:DBListBox);Begin
If(IsBanderolle)Then Begin
WEBarSpcHorBanderolle(Q.W,Q.Y,Q.P);
WEPutTxtXYT(Q.W,0,Q.Y,DBLReadLine(Q,Q.P));
End
Else
WEPutTxtXY(Q.W,0,Q.Y,DBLReadLine(Q,Q.P));
End;
Procedure DBLHome(Var Q:DBListBox);
Var
I:Byte;
Begin
WESetPosHome(Q.W);
Q.P:=0;
Q.Y:=0;
For I:=0to(Q.W.MaxY)do Begin
If(IsBanderolle)Then Begin
WEBarSpcHorBanderolle(Q.W,I,I);
WEPutTxtTLn(Q.W,DBLReadLine(Q,I));
End
Else
WEPutTxtLn(Q.W,DBLReadLine(Q,I));
End;
DBLSelectBar(Q);
End;
Procedure DBLShowList(Var Q:DBListBox);
Var
I:Byte;
PT:Word;
Begin
WEClrWnBorder(Q.W,0,0,wnMax,wnMax);
WESetPosHome(Q.W);
PT:=Q.P-Q.Y;
For I:=0to(Q.W.MaxY)do Begin
If(IsBanderolle)Then Begin
WEBarSpcHorBanderolle(Q.W,I,PT);
WEPutTxtTLn(Q.W,DBLReadLine(Q,PT));
End
Else
WEPutTxtLn(Q.W,DBLReadLine(Q,PT));
Inc(PT);
End;
DBLSelectBar(Q);
End;
Procedure DBLSearchName(Var Q:DBListBox;Const Name:String);Begin
If DBLocateAbs(ChantalServer,2,Name,[soNotStrict])Then Begin
Q.P:=ChantalServer.CurrLine;
If(Q.P<Q.Y)Then Q.Y:=Q.P;
DBLShowList(Q);
End;
End;
Procedure DBLUp(Var Q:DBListBox);Begin
If Q.P>0Then Begin
Q.BufChr:='';
DBLUnSelectBar(Q);
Dec(Q.P);
If Q.Y>0Then Dec(Q.Y)
Else
Begin
WEScrollUp(Q.W,0,0,wnMax,wnMax);
DBLPutLine(Q);
End;
DBLSelectBar(Q);
End;
End;
Procedure DBLDn(Var Q:DBListBox);Begin
If(Q.P<Q.MP)Then Begin
Q.BufChr:='';
DBLUnSelectBar(Q);
Inc(Q.P);
If(Q.Y<Q.W.MaxY)Then Inc(Q.Y)
Else
Begin
WEScrollDn(Q.W,0,0,wnMax,wnMax);
DBLPutLine(Q);
End;
DBLSelectBar(Q);
End;
End;
Procedure DBLEnd(Var Q:DBListBox);Begin
If(Q.P<=Q.MP)Then Begin
Q.BufChr:='';
Q.P:=Q.MP;
Q.Y:=Q.W.MaxY;
If(Q.P<=Q.W.MaxY)Then Q.Y:=Q.P;
DBLShowList(Q);
End;
End;
Procedure DBLPgDn(Var Q:DBListBox);Begin
If(Q.P+(Q.W.MaxY shl 1)<Q.MP)Then Begin
Q.BufChr:='';
Inc(Q.P,Q.W.MaxY);
DBLShowList(Q);
End
Else
DBLEnd(Q);
End;
Procedure DBLPgUp(Var Q:DBListBox);Begin
If(Q.P<Q.W.MaxY)Then DBLHome(Q)
Else
Begin
Dec(Q.P,Q.W.MaxY);
If(Q.P<Q.Y)Then Q.Y:=Q.P;
DBLShowList(Q);
End;
End;
Procedure DBLInit(Var Q:DBListBox;X1,Y1,X2,Y2:Byte;Const Title,TableName:String;Column:Byte);Begin
FillClr(Q,SizeOf(Q));
WEInit(Q.W,X1,Y1,X2,Y2);
WEPushWn(Q.W);
WEPutWn(Q.W,Title,CurrKrs.Dialog.Env.List);
WEPutBarMsRight(Q.W);
DBOpenServerName(ChantalServer,TableName);
Q.MP:=DBNumRec(ChantalServer)-2;
Q.ColumnNum:=Column;
Q.DB:=ChantalServer;
End;
Procedure DBLOpen(Var Q:DBListBox;X1,Y1,X2,Y2:Byte;Const Title,PathDB,TableName:String;Column:Byte);Begin
FillClr(Q,SizeOf(Q));
WEInit(Q.W,X1,Y1,X2,Y2);
WEPushWn(Q.W);
WEPutWn(Q.W,Title,CurrKrs.Dialog.Env.List);
WEPutBarMsRight(Q.W);
DBInit(Q.DB,PathDB);
If TableName<>''Then DBOpenServerName(Q.DB,TableName);
Q.MP:=DBNumRec(Q.DB)-3;
Q.ColumnNum:=Column;
End;
Procedure DBLDone(Var Q:DBListBox);Begin
WEDone(Q.W);
End;
Function DBLRun(Var Q:DBListBox):Word;
Var
K:Word;
OldP:LongInt;
Begin
Repeat
OldP:=Q.P;
K:=WEReadk(Q.W);
Case(K)of
kbHome:DBLHome(Q);
kbRBarMsUp,kbRBarMsDn:Begin
__HideMousePtr;
Case(K)of
kbRBarMsUp:DBLUp(Q);
Else DBLDn(Q);
End;
DelayMousePress(100);
__ShowMousePtr;
End;
kbUp:DBLUp(Q);
kbDn:DBLDn(Q);
kbPgUp:DBLPgUp(Q);
kbPgDn:DBLPgDn(Q);
kbEnd:DBLEnd(Q);
Else If(Char(K)>#31)and(Hi(K)<$80)Then Begin
IncStr(Q.BufChr,ChrUp(Char(K)));
DBLSearchName(Q,Q.BufChr);
End
Else
Break;
End;
If(OldP<>Q.P)Then Begin
If(@Q.ShowCurrLine<>NIL)Then Q.ShowCurrLine(Q,Q.Context^);
Old:=Q.P;
End;
Until False;
DBLRun:=K;
End;
Function DBChoice(X1,Y1,X2,Y2:Byte;Const Title,TableName:String;Column:Byte):String;
Var
R:DBListBox;
K:Word;
Begin
DBChoice:='';
DBLInit(R,X1,Y1,X2,Y2,Title,TableName,Column);
DBLHome(R);
Repeat
K:=WEReadk(R.W);
Case(K)of
kbInWn:Begin
DBChoice:=DBLReadLine(R,R.P-R.Y+LastMouseY-WEGetRY1(R.W));
WaitMouseBut0;
Break;
End;
kbEnter:Begin
DBChoice:=DBLReadLine(R,R.P);
Break;
End;
kbHome:DBLHome(R);
kbRBarMsUp,kbRBarMsDn:Begin
__HideMousePtr;
Case(K)of
kbRBarMsUp:DBLUp(R);
Else DBLDn(R);
End;
DelayMousePress(100);
__ShowMousePtr;
End;
kbUp:DBLUp(R);
kbDn:DBLDn(R);
kbPgUp:DBLPgUp(R);
kbPgDn:DBLPgDn(R);
kbEnd:DBLEnd(R);
Else If(Char(K)>#31)and(Hi(K)<$80)Then Begin
IncStr(R.BufChr,ChrUp(Char(K)));
DBLSearchName(R,R.BufChr);
End
Else
Break;
End;
Until False;
DBLDone(R);
End;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
END.