-
Notifications
You must be signed in to change notification settings - Fork 10
/
250_tipsandtricks5.txt
3802 lines (3177 loc) · 109 KB
/
250_tipsandtricks5.txt
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
//Example of Outline and Memocomponent load and save capabilities of the VCL
//Task: Outsource the business logic procedure ShowEntry in a include file
//Get the text struct and set a new outline!, locs=236
//Dedicated to tutorial 11: starter programming forms
//#head<.txt Max: MAXBOX10: 17/05/2016 21:18:55 C:\Program Files (x86)\maxbox3\Import\IPC\maxbox4\maxbox4\examples\250_tipsandtricks5.txt icks5.txt ks4.txt
Program Outline_Form_App_Tutorial_GUI_TESTER;
function LoadLibrary(lib: pchar): Longint;
external 'LoadLibraryA@kernel32.dll stdcall';
function FreeLibrary(h: THandle): Longint;
external 'FreeLibrary@kernel32.dll stdcall';
function GetProcAddress(h: Thandle; addr: pchar): longint;
external 'GetProcAddress@kernel32.dll stdcall';
Const LEFTBASE = 20;
TOPBASE = 30;
TEXTPATH = 'examples\outline3.txt';
AVIPATH = 'examples\cool.avi';
BITMAP = 'examples\citymax.bmp';
//Open Arrays
type
TAnArray = array[0..20] of longint;
TAnotherArray = array[2..16] of longint;
THello = function: boolean; //procedure type
var
myMemo: TMemo;
inFrm: TForm;
stat: TStatusbar;
mOutln: TOutline;
selectFile: string;
mbitmap: Tbitmap;
AnArray: TAnArray;
AnotherArray: TAnotherArray;
Procedure UpdateOutline(self: TObject); forward;
procedure TForm1_FormPaint(Sender: TObject); forward;
//*******************Event Handlers - Closure***********************************
Procedure GetMediaData(self: TObject);
begin
if PromptForFileName(selectFile, 'Text files (*.txt)|*.txt', '',
'Select your outline file',
ExePath, False) //False = not Save dialog !
then begin
ShowMessage('Selected file = '+selectFile);
Stat.simpletext:= selectFile;
myMemo.lines.LoadFromFile(selectFile);
writeln('length' +inttostr(length(mymemo.text)))
UpdateOutline(self)
//Split full file/path value into its constituent parts
end;
end;
Procedure BtnSaveClick(self: TObject);
begin
if selectFile <> '' then begin
mymemo.lines.SaveToFile(selectFile)
UpdateOutline(self)
Stat.simpletext:= selectFile+ ' has been saved and updated' ;
end;
end;
Procedure UpdateOutline(self: TObject);
begin
with mOutln do begin
//Update Tree!
LoadFromFile(selectFile);
FullExpand;
end
end;
Procedure showEntry(self: TObject);
var idx: integer;
begin
idx:= mOutln.selecteditem //itemindex
writeln(mOutln.items[idx].text+' is marked')
Stat.simpletext:= mOutln.items[idx].text+' is marked';
end;
procedure FormCloseClick(Sender: TObject; var Action: TCloseAction);
begin
//myImage.Free;
Writeln('Outline Form Closed at: '+ TimeToStr(Time));
//inFrm.Free;
Action:= caFree;
end;
procedure ButtonCloseClick(Sender: TObject);
begin
mbitmap.Free;
inFrm.Close;
end;
//const KEY_WRITE = $20006;
procedure TMyTestServiceApp_ServiceAfterInstall(Sender: TService);
var
Reg: TRegistry;
name: string;
regc: Tcustominifile;
begin
//reg := TRegistry.Create;
Reg := TRegistry.Create1(KEY_READ or KEY_WRITE);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\SYSTEM\CurrentControlSet\Services\' + Name, false) then
begin
Reg.WriteString('Description', 'This is a description for my fine Service Application.');
Reg.CloseKey;
end;
finally
Reg.Free;
end;
end;
//--------------------------------Form Build---------------------------------//
//****************************************************************************
Procedure SetForm;
var
mt: TMainMenu;
mi, mi1, mi2: TMenuItem;
mPanel: TPanel;
bmp: TBitmap;
Image1: TImage;
//gifimg: TGIFImage;
begin
inFrm:= TForm.Create(self);
stat:= TStatusbar.Create(inFrm);
mPanel:= TPanel.Create(inFrm);
myMemo:= TMemo.Create(inFrm);
mOutln:= TOutline.Create(inFrm);
with inFrm do begin
caption:='*****OutlineMedia3*****';
height:= 810;
width:= 1080;
Position:= poScreenCenter;
onClose:= @FormCloseClick; //uncomment for debug
onPaint:= @TForm1_FormPaint;
Show;
end;
with mPanel do begin
caption:= '***Outline***';
Parent:= inFrm;
SetBounds(LEFTBASE,TOPBASE+40,340,400)
color:= clsilver;
font.color:= clyellow;
font.size:= 30;
end;
with myMemo do begin
Parent:= inFrm;
SetBounds(LEFTBASE+570,TOPBASE+40,340,400)
font.size:= 14;
color:= clWebGold;
scrollbars:= ssVertical;
if Not fileexists(exepath+'examples\outline3.txt') then
renameFile(exepath+'examples\outline.txt','examples\outline3.txt');
lines.LoadFromFile(selectFile);
Stat.simpletext:= selectFile;
end;
with mOutln do begin
//AddChild
Parent:= inFrm;
LoadFromFile(selectFile);
FullExpand;
width:= 280; height:= 340;
top:= TOPBASE+60;
left:= LEFTBASE+30;
onclick:= @showEntry;
end;
with Stat do begin
Parent:= inFrm;
stat.SimplePanel:= true;
end;
//********************************Bit Buttons*********************************
with TBitBtn.Create(inFrm) do begin
Parent:= inFrm;
setBounds(LEFTBASE+760,TOPBASE+460,150,40);
caption:= 'Open Text';
font.size:= 12;
glyph.LoadFromResourceName(HINSTANCE,'OPENFOLDER');
//event handler
onclick:= @GetMediaData;
end;
with TBitBtn.Create(inFrm) do begin
Parent:= inFrm;
setBounds(LEFTBASE+600,TOPBASE+460,150,40);
caption:= 'Save Text';
font.size:= 12;
glyph.LoadFromResourceName(HINSTANCE,'CL_MPNEXT');
onclick:= @BtnSaveClick;
end;
with TBitBtn.Create(inFrm) do begin
Parent:= inFrm;
setBounds(LEFTBASE+440,TOPBASE+460,150,40);
caption:= 'Update';
font.size:= 12;
glyph.LoadFromResourceName(HINSTANCE,'CL_MPPLAY');
onclick:= @UpdateOutline;
end;
with TBitBtn.Create(inFrm) do begin
Parent:= inFrm;
setBounds(LEFTBASE+280,TOPBASE+460,150,40);
caption:= 'Close';
font.size:= 12;
glyph.LoadFromResourceName(HINSTANCE,'CL_MPSTOP');
onclick:= @ButtonCloseClick;
end;
//--------------------------Animation, Picture, Labels-------------------------
with TAnimate.Create(inFrm) do begin
Parent:= inFrm;
//Transparent := True;
SetBounds(LEFTBASE+385,TOPBASE+55,0,0) //315,-5
FileName:= ExePath + AVIPATH;
Active:= True;
//Hide;
end;
with TAnimate.Create(inFrm) do begin
Parent:= inFrm;
Transparent := True;
CommonAVI := aviFindFile;
SetBounds(LEFTBASE+385,TOPBASE+155,0,0) //315,-5
//loadfromresource
resname:= 'AVI_THROBBER';
//FileName:= ExePath + AVIPATH;
//(Image1.Picture.Graphic as TGIFImage).Animate:= True;
//filename:= 'C:\maXbox\maxbox3\maxbox3\maXbox3\examples\math.gif';
Active:= True;
//Hide;
end;
bmp:= TBitmap.Create;
try
bmp.LoadFromFile(Exepath+BITMAP);
inFrm.Canvas.Draw(370,70,Bmp);
finally
bmp.Free;
end;
with TLabel.Create(inFrm) do begin
Parent:= inFrm;
setbounds(LEFTBASE+10,TOPBASE-15,180,20);
font.size:= 30;
font.color:= clred;
//font.style:= [fsunderline]
caption:= ' Outline FormApp ';
end;
with TLabel.Create(inFrm) do begin
Parent:= inFrm;
setbounds(LEFTBASE+575,TOPBASE,180,20);
font.size:= 20;
font.color:= clred;
caption:= ' Outline Tree ';
end;
//********************************Menu Controls*******************************
mt:= TMainMenu.Create(infrm)
mi:= TMenuItem.Create(mt)
mi1:= TMenuItem.Create(mt)
mi2:= TMenuItem.Create(mt)
with mi do begin
Caption:= 'Play Outline';
Name:='ITEM';
mt.Items.Add(mi);
OnClick:= @GetMediaData;
end;
with mi1 do begin
Caption:= 'Show Outline';
Name:='ITEM2';
mt.Items.Add(mi1) ;
end;
with mi2 do begin
Caption:= 'Open Outline';
Name:='ITEM3';
mt.Items.Add(mi2);
end;
end;
//Components at Runtime of best tips&tricks ------------>
procedure Components_at_Runtime(x,y: shortint);
var newbutton: TButton;
TabbedNotebook1, Notebook1: TNotebook;
tabset1, tabcontrol1: TTabControl;
pageset: TPageControl;
ipos: shortint;
begin
NewButton.Parent:= TWinControl(TabbedNotebook1.Pages.Objects[1])
NewButton.Parent:= TWinControl(Notebook1.Pages.Objects[1])
NewButton.Parent:= TWinControl(TabSet1.Tabs.Objects[1])
iPos:= TabControl1.IndexOfTabAt(x,y);
TabSet1.Hint:= 'Objects[1])';
end;
//Save an Integer with a string in an Tstring list object
function saveIntegerasString: longint;
var listbox1: TListBox;
ints: shortint;
begin
ints:= 100;
//Listbox1.Items.AddObject('Text string', TObject(ints));
//Result:= LongInt(Listbox1.Items.Objects[0]);
end;
//multitask enabled delay
procedure Delay2(msecs: integer); //top ten 2
var
FirstTickCount: longint;
begin
FirstTickCount:= GetTickCount;
repeat
Application.ProcessMessages; {allowing access to other
controls, widgets, etc.}
until ((GetTickCount-FirstTickCount) >= Longint(msecs));
end;
function RandomWords(howmany: integer): string;
var t: shortint;
begin
for t:= 1 to howmany do
result:= result+#13#10 +chr(random(25)+65)+chr(random(25)+65)+chr(random(25)+65)
+chr(random(25)+65)+chr(random(25)+65)+chr(random(25)+65);
//Listbox1.Items.Add(newWord);
end;
//Create a Paradox table with an Auto Increment type field
//Use a TQuery and SQL CREATE TABLE statement. For example:
procedure TBenchDlg_CreateBtnClick(Sender: TObject);
var query1: TQuery;
begin
with Query1 do begin
DatabaseName:= 'C:\DATEN\CALWIN2\CWTests';
with SQL do begin
Clear;
Add('CREATE TABLE "pBench.db" (ID AUTOINC,');
Add('FIRSTNAME CHAR(50),');
Add('LASTNAME CHAR(50),');
Add('PHONE INTEGER,');
Add('PRIMARY KEY(ID))');
ExecSQL;
Clear;
Add('CREATE INDEX ByName ON "pBench.db" (LASTNAME)');
ExecSQL;
end;
end;
end;
//Fill created table at runtime
procedure TBenchDlg_FillBtnClick(Sender: TObject);
var k,err, maxarray: integer;
s: string;
edit1: Tedit;
t: TTable;
datasource1: TDataSource;
globarray: array[0..100] of integer;
begin
val(Edit1.Text, maxArray, err);
t:= TTable.create(self);
with t do begin
DatabaseName:= 'C:\DATEN\CALWIN2\CWTests'; {personal alias}
TableName:= 'pbench.db';
open;
for k:= 1 to maxarray do begin
S:= intToStr(k); //str(k,s);
append;
FieldByName('Firstname').AsString := 'CWObjekt '+s;
FieldByName('Lastname').AsString := 'CWObjektteile '+s;
FieldByName('Phone').AsString := s;
GlobArray[k]:= StrToInt(FieldByName('Phone').AsString);
post; {required!!!}
end;
close;
end;
t.active:= true;
DataSource1.DataSet:= t;
//Create Indexes at runtime
with t do begin
Active := False;
DatabaseName := 'DBDEMOS';
TableName := 'Temp';
TableType := ttParadox;
FieldDefs.Assign(t.FieldDefs);
T.IndexDefs.Update; { Do an update first }
IndexDefs.Assign(t.IndexDefs);
CreateTable;
end;
end;
procedure TBenchDlg_SortBtnClick(Sender: TObject);
var
j,k,tmp: integer;
maxarray: integer;
listbox1: TListBox;
globarray: array[0..100] of integer;
begin
for j:=1 to MaxArray-1 do begin
for k:=1 to MaxArray-j do
if GlobArray[k] < GlobArray[k+1] then begin
{ Swap GlobArray[k+] with GlobArray[k] ... }
tmp:= GlobArray[k];;
GlobArray[k]:= GlobArray[k+1];
GlobArray[k+1]:= tmp;
end;
end;
ListBox1.Clear;
for j:= 1 to MaxArray do
Listbox1.Items.Add(IntToStr(GlobArray[j]));
end;
//Delete created table at runtime
procedure TBenchDlg_DelBtnClick(Sender: TObject);
var k,err: integer;
maxarray: integer;
edit1: Tedit;
t: TTable;
datasource1: TDataSource;
begin
Val(Edit1.Text,maxArray,err);
t:= TTable.create(self);
with t do begin
DatabaseName:= 'C:\DATEN\CALWIN2\CWtests'; {personal alias}
TableName:= 'pbench.db';
open;
edit;
first;
next;
while not t.eof do begin
delete;
end;
close;
end;
t.active:= true;
DataSource1.DataSet:= t;
end;
//Cell DBGridPosition in Runtime
procedure TForm1_MyDBGridDrawDataCell(Sender: TObject; Const Rect: TRect;
Field: TField; State: TGridDrawState);
var
RowHeight: Integer;
dbgrid: TDBGrid;
Col, Row: Integer;
begin
if gdFocused in State then begin
RowHeight:= Rect.Bottom - Rect.Top;
Row:= (Rect.Top div RowHeight) - 1;
Col:= Field.Index;
end;
end;
Procedure TForm1_DBGrid1DrawDataCell(Sender: TObject; Const Rect: TRect;
Field: TField; State: TGridDrawState);
var mg: TDBGrid;
begin
//mg.canvas
If gdFocused in State then
with TDBGrid(sender).Canvas do begin //(Sender as TDBGrid)
Brush.Color:= clRed;
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, Field.AsString);
end;
end;
//Calculation with Date within Calculated Fields
procedure TForm1_Table1CalcFields(DataSet: TDataset);
var
t1, t2: tDateTime;
table1d1, table1d2, table1d3: TTable;
begin
table1d1.fields[3].asDateTime:= Date + 2; {or table1d1.value := date + 2;}
table1d2.fields[2].asDateTime:= Date - 2;
t1:= table1d1.fields[3].asDateTime;
t2:= table1d2.fields[3].asDateTime;
table1d3.fields[3].asInteger := trunc(double(t1) - double(t2));
end;
//Thousands Separator
function FormatNumber(l: longint): string;
var
len, count: integer;
s: string;
begin
s:= inttostr(l);
len:= length(s);
for count:= ((len - 1) div 3) downto 1 do begin
insert('''', s, len-(count*3)+ 1);
len:= len + 1;
end;
result:= s;
end;
function FormatNumberThousand(l: longint): string; //top ten 1
begin
result:= FormatFloat('#,##0', StrToFloat(IntToStr(l)));
end;
//Create Alias at Runtime
procedure AliasAtRuntime;
var database1: TDatabase;
table1: TTable;
begin
Database1.Params.Clear;
Database1.Params.Add('PATH=C:\DELPHI\DEMOS\DATA');
Table1.DatabaseName:= 'MyNewAlias';
Table1.TableName:= 'CUSTOMER';
Table1.Active:= True;
//DataSource1.DataSet:= Table1;
//DBGrid1.DataSource:= DataSource1;
end;
//Copy one TimeStamp from one File to Another
procedure CopyFileDate(Const Source, Dest: String); //Source and Dest are PathNames
var
SourceHand, DestHand: word;
begin
SourceHand:= FileOpen(Source, fmOutput); { open source file }
DestHand:= FileOpen(Dest, fmInput); { open dest file }
//FileSetDate(DestHand, FileGetDate(SourceHand)); { get/set date }
FileClose(SourceHand); { close source file }
FileClose(DestHand); { close dest file }
end;
//SetRange Beispiel
procedure SetARaNGE;
var table1: TTable;
begin
with Table1 do begin
SetRangeStart;
FieldByName('LastName').AsString:= 'S';
SetRangeEnd;
FieldByName('LastName').AsString:= 'Szzz';
ApplyRange;
end;
end;
// Search in Querys
function SeqSearch(AQuery: TQuery; AField, AValue: String): Boolean;
begin
with AQuery do begin
First;
while (not Eof) and (not (FieldByName(AField).AsString = AValue)) do
Next;
result:= not EOF;
end;
end;
procedure TForm1_Timer1Timer(Sender: TObject);
var myform: Tform;
begin
myform.ActiveControl.Left:= myform.ActiveControl.Left + 1;
end;
procedure TMyTable_ExportToASCII;
var
I: Integer;
Dlg: TSaveDialog;
ASCIIFile: TextFile;
Res: Boolean;
mytable: Ttable;
FASCIIFileName: shortstring;
begin
with mytable do begin
if Active then
if (FieldCount > 0) and (RecordCount > 0) then begin
Dlg:= TSaveDialog.Create(Application);
Dlg.FileName:= FASCIIFileName;
Dlg.Filter:= 'ASCII-Dateien (*.asc)|*.asc';
Dlg.Options:= Dlg.Options+[ofPathMustExist,
ofOverwritePrompt, ofHideReadOnly];
Dlg.Title:= 'Daten in ASCII-Datei exportieren';
try
Res:= Dlg.Execute;
if Res then
FASCIIFileName:= Dlg.FileName;
finally
Dlg.Free;
end;
if Res then begin
//AssignFile(ASCIIFile, FASCIIFileName);
//Rewrite(ASCIIFile);
First;
if fieldbyname('FASCIIFieldNames').asboolean then
begin
for I:= 0 to FieldCount-1 do begin
//Write(ASCIIFile, Fields[I].FieldName);
if I <> FieldCount-1 then
//Write(ASCIIFile, FASCIISeparator);
end;
//Write(ASCIIFile, #13#10);
end;
while not EOF do begin
for I:= 0 to FieldCount-1 do begin
//Write(ASCIIFile, Fields[I].Text);
if I <> FieldCount-1 then
//Write(ASCIIFile, FASCIISeparator);
end;
Next;
if not EOF then
//Write(ASCIIFile, #13#10);
end;
Closefile(ASCIIFile); //CloseFile ?
if IOResult <> 0 then
MessageDlg('Fehler beim Erstellen oder Schreiben '+
'in die ASCII-Datei', mtError, [mbOK], 0);
end; //if res
end
else
MessageDlg('Es sind keine Tabellendaten zu exportieren.',
mtInformation, [mbOK], 0)
else
MessageDlg('Datenbank-Tabelle muß geöffnet sein, damit Daten '+
'ins ASCII-Format exportiert werden können.', mtError,
[mbOK], 0);
end; //with
end;
function TBDEDirect_CheckDatabase: Boolean;
var
DS: TDataSource;
winword: variant;
begin
Result := False;
//DS:= GetDataSource;
if DS = nil then
begin
MessageDlg('Die Anbindung an ein Datenquell-Element fehlt. '+
'Stellen Sie die Eigenschaft DataSource entsprechend ein.',
mtError, [mbOK], 0);
Exit;
end;
if DS.DataSet = nil then
begin
MessageDlg('Zugriff auf Datenbank nicht möglich.', mtError,
[mbOK], 0);
Exit;
end;
if TDBDataSet(DS.DataSet).Database = nil then
begin
MessageDlg('Zugriff auf Datenbank nicht möglich.', mtError,
[mbOK], 0);
Exit;
end;
{if TDBDataSet(DS.DataSet).Database.Handle = nil then begin
MessageDlg('Datenbank-Handle nicht verfügbar.', mtError,
[mbOK], 0);
Exit;
end;}
//if DS.DataSet.Handle = nil then begin
MessageDlg('Cursor-Handle nicht verfügbar.', mtError, [mbOK], 0);
Exit;
//end;
Result := True;
WinWord := CreateOleObject('word.Basic');
end;
procedure TForm1_InsertBtnClick(Sender: TObject);
var
WinWord: Variant;
S: string;
L: Integer;
query1: TQuery;
begin
{ Aufbau der Verbindung zu dem Server in WinWord und Starten }
{ der Datenbankabfrage }
WinWord:= CreateOleObject('word.Basic');
with Query1 do begin
Close;
//Params[0].Text:= Edit1.Text;
Open;
try
First;
L:= 0;
while not EOF do begin
{ Speichern des Abfrageergebnisses in dem String S }
S:= S + Query1.fieldbyname('Company').AsString + ',' +
Query1.fieldbyname('OrderNo').AsString + ',' +
Query1.fieldbyname('SaleDate').AsString + #13;
Inc(L);
Next;
end;
{ OLE-Automation wird benutzt, um S in WinWord einzufügen}
WinWord.Insert(S);
WinWord.LineUp(L, 1);
//WinWord.TextToTable(ConvertFrm:= 2, NumColumns := 3);
finally
Close;
end;
end;
end;
procedure TMyQuery_CheckSQL;
var myquery: TQuery;
begin
with myquery do begin
if not Active then begin
if (DatabaseName = '') and (DataSource = NIL) then begin
MessageDlg('Kein Datenbankzugriff. Stellen Sie die '+
'Eigenschaft DatabaseName bzw. DataSource '+
'entsprechend ein.', mtError, [mbOK], 0);
Exit;
end;
if SQL.Count = 0 then begin
MessageDlg('Kein SQL-Text', mtError, [mbOK], 0);
Exit;
end;
try
//OpenCursor;
except
//CloseCursor;
MessageDlg('Fehler in dem SQL-Text oder Datenbank-Fehler',
mtError, [mbOK], 0);
Exit;
end;
MessageDlg('SQL-Text korrekt', mtInformation, [mbOK], 0);
//CloseCursor;
end
else
MessageDlg('SQL-Abfrage bereits aktiv', mtInformation, [mbOK], 0);
end;
end;
//BITMAP size drawing
procedure BitmapLoad;
begin
mBitmap:= TBitmap.Create;
mBitmap.LoadFromFile(Exepath+BITMAP);
end;
procedure TForm1_FormPaint(Sender: TObject);
var
x, y, w, h: LongInt;
//mbitmap: Tbitmap;
//myform: TForm;
begin
with mBitmap do begin
w:= Width;
h:= Height;
end;
y:= 0;
while y < inFrm.Height do begin
x:= 0;
while x < inFrm.Width do begin
inFrm.Canvas.Draw(x, y, mBitmap);
x:= x+w;
end;
y:= y+h;
end;
//writeln('on paint tester')
end;
//Add a component at runtime to Notebook/TabbedNotebook
procedure AddButton(tabNotebook: TNotebook);
var
tabpage : TTabControl;
button : TButton;
begin
with tabNotebook do
tabpage:= TTabControl(Pages.Objects[PageIndex]);
button:= TButton.Create(tabpage);
try
with button do begin
Parent:= tabpage;
Left:= Random(tabpage.ClientWidth - Width);
Top:= Random(tabpage.ClientHeight - Height);
end;
except
button.Free;
end;
end;
//Iterate and count the controls with logger
procedure TForm1_ControlLogger;
var
I,j: Integer;
logList: TStringList;
edit1: TEdit;
c: TComponent;
begin
logList:= TStringList.create;
for I:= 0 to inFrm.ComponentCount -1 do begin
if inFrm.Components[I] is TButton then
TButton(inFrm.Components[I]).Font.Name := 'Arial';
//Edit1.Text:= IntToStr(inFrm.ComponentCount) + ' components';
logList.Add(intToStr(i) + ' count');
logList.Add(inttoStr(inFrm.instancesize));
for j:= 0 to inFrm.Components[i].ComponentCount - 1 do begin
c:= inFrm.Components[i].Components[j];
if c is TComponent then
writeln(inttostr(j)+ ' '+c.name +' '+ c.classname);
loglist.Add(inFrm.components[i].name);
end;
end;
//loglist.SaveToFile(ExePath+'LOGLIST2_mX3.TXT');
loglist.Free;
end;
function Encrypt(Const S: String; Key: word): String;
var
I: byte;
begin
//Result[0]:= S[0];
//result:= '';
for I:= 1 to Length(S) do begin
Result[I]:= chr(ord(S[I]) XOR (Key shr 8));
Key:= (ord(Result[I]) + Key) * 233445//C1 + C2;
end;
end;
function Decrypt(Const S: String; Key: word): String;
var
I: byte;
begin
//Result[0] := S[0];
//result:= '';
for I:= 1 to Length(S) do begin
Result[I]:= chr(ord(S[I]) XOR (Key shr 8));
Key:= (ord(S[I]) + Key) * 233445 //C1 + C2;
end;
end;
procedure TTabTest_InitArray(Const vAnArray: array of longint);
{ das ist die Form um Parameter als offene Arrays zu deklarieren }
var
i:integer;
begin
{ innerhalb der Prozedur wird das Array als 0-basiert angenommen }
{koennte auch sein for i:=0 to, beginnt immer bei 0}
i:= 1;
for i:= Low(vAnArray) to High(vAnArray) do begin
writeln('low first '+inttostr(i))
vAnArray[i]:= i;
anArray[i]:= i;
//writeln(inttostr(vanarray[i]))
end;
//AnArray:= TAnArray(vAnarray)
end;
function TTabTest_CalcSum(vAnArray: array of longint): longint;
var
Sum: integer;
i: integer;
begin
Sum:= 1;
//with ListBox1.Items do begin
Writeln('Unterer Index: ' + IntToStr(Low(vAnArray)));
Writeln('Oberer Index: ' + IntToStr(High(vAnArray)));
//end;
for i:= Low(vAnArray) to High(vAnArray) do begin
Sum:= Sum + vAnArray[i];
writeln(inttostr(vanarray[i]))
end;
result:= Sum;
end;
//SQL Search Dialog with Substitutionsparameter
procedure TDemo2Form_SuchenClick(Sender: TObject);
var searchresult,
searchString: shortstring;
it: byte;
query1: TQuery;
//Const it: byte=0;
begin
it:= 0;
searchString:=' Suchen Sie was';
with Query1 do begin
disableControls;
try
active:= false;
Close;
SQL.Clear;
Query1.SQL.Add('Select * from pbench where FIRSTNAME=:Name');
if InputQuery('search','prompt',searchString) then begin
//Params[0].AsString:= searchString;
Open;
active:= true;
end;
finally
enableControls;
end;
end; //with
end;
//Iterate through tabbednotebook pages to see each object?
procedure TForm1_Button2Click(Sender: TObject);
var
cmpnts, pg: word;
MyPageObj: TObject;
OutlineIdx: longint;
TabbedNotebook1: TNotebook;
outline1: TOutline;
begin
for pg := 0 to TabbedNotebook1.pages.count - 1 do begin
MyPageObj := TabbedNotebook1.pages.objects[pg];
OutlineIdx := outline1.add(0, TabbedNotebook1.pages[pg]);
for cmpnts := 0 to inFrm.componentCount - 1 do
//if (self.components[cmpnts] as TControl).parent = MyPageObj) then
outline1.AddChild(outlineIdx, self.components[cmpnts].name +
' [' + self.components[cmpnts].ClassName + ']');
end;
with MyPageObj do
for cmpnts:= 0 to self.ControlCount - 1 do
outline1.AddChild(outlineIdx, self.Controls[cmpnts].name +
' [' + self.Controls[cmpnts].ClassName + ']');
end;
{ This code came from Lloyd's help file! }
//Iterate a Table and use outline control
procedure TfrmWizDlg_Button3Click(Sender: TObject);
var
t: TTable;
indx, FieldCounter: integer;
outline1: TOutline;
begin
t:= TTable.create(self);
with t do begin
DatabaseName:= 'CWBASEII'; {personal alias}
TableName:= 'useddims.db';
open;
first; {probably redundant}
while not eof do begin
indx := outline1.add(0, fields[0].AsString);
for FieldCounter:= 1 to fieldcount -1 do
outline1.addChild(indx, fields[FieldCounter].AsString);
next;
end; {end of the while statement}
close;
end; { End of the with statement. }
end; {end of the procedure}
procedure TForm1_CheckBox1Click(Sender: TObject);
var
NotepadHandle: hWnd;
begin
//if checkbox1.checked then {start/stop checkbox}
WinExec('c:\windows\notepad.exe c:\autoexec.bat', sw_ShowNormal)
//else begin
NotepadHandle:= FindWindow('Notepad', '');
writeln(inttostr(notepadhandle));
//SendMessage(NotepadHandle, wm_Close, 0, 0);
//end;
end;
procedure ListAllIntegers(Const vAnArray: array of Integer);
var
I: Integer;
begin
for I := Low(vAnArray) to High(vAnArray) do
WriteLn('Integer at '+ inttoStr(I)+ ' is '+ InttoStr(vAnArray[I]));
end;
function sayhello: boolean; //functiontype
BEGIN
result:= true;