-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path565_ConsoleCapture23mX42298.TXT
1596 lines (1345 loc) · 45.1 KB
/
565_ConsoleCapture23mX42298.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
{***************************************************************
* Project : Console Expressions and Strips Routines with REGEX
* App Name : 550_Expressions.TXT, 530_3DLab.TXT, #locs=840
* Purpose : Demonstrates Console out to box, STExpression adding func() at runtime!
* Date : #sign>4:59 Max: MAXBOX10: 23/05/2016 14:33:15 PM
****************************************************************}
//TODO: transfer the strip to a REGEX funcrvalue
//ref: maXbox3/source/REST/uPSI_StExpr.pas
// http://delphidabbler.com/tips/61
Program DOSConsoleCapture;
{Formats a StripTag Position of HTML in function or REGEX match selection}
function ReadUntil(const ReadFrom, len: Integer; const C: Char; s: string): Integer;
var
j: Integer;
begin
for j := ReadFrom to Len do
if (s[j] = C) then begin
Result := j;
Exit;
end;
Result := Len+1;
end;
function StripTags2(const S: string): string;
var
Len: Integer;
i, APos: Integer;
begin
Len := Length(S);
i := 0;
Result := '';
while (i <= Len) do begin
Inc(i);
APos := ReadUntil(i, len, '<', s);
Result := Result + Copy(S, i, APos-i);
i := ReadUntil(APos+1,len, '>',s);
end;
end;
FUNCTION Strip(const SubString: String; MainString: String): String;
{ =================================================================== }
VAR i,j: Integer;
BEGIN{Strip}
j := length(SubString);
If j <> 0 Then Begin
i := Pos(SubString,MainString);
While i <> 0 Do Begin
Delete(MainString, i, j);
i := Pos(SubString,MainString);
End;
End;
result:= MainString;
END{Strip};
FUNCTION StripAny(const SubString: String; MainString: String): String;
{ =================================================================== }
VAR i,j: Integer;
s: char;
BEGIN{Strip}
//j := Ord(SubString[0]);
j := length(SubString);
While j > 0 Do Begin
s := SubString[j];
i := Pos(s,MainString);
While i <> 0 Do Begin
Delete(MainString,i,1);
i := Pos(s,MainString);
End;
Dec(j);
End;
result:= MainString;
END{Strip};
procedure AppendValueToStrings(const SL: TStrings; StartingValue: Integer);
var i: Integer;
begin
Assert(Assigned(SL),'not assigned'); // Make sure valid TStrings has been passed in
for i := 0 to SL.Count - 1 do begin
SL[i] := IntToStr(StartingValue) + ' ' + SL[i];
Inc(StartingValue);
end;
end;
function GrabLine2(const s: string; ALine: Integer): string;
var sl: TStringList;
begin
sl:= TStringList.Create;
try
sl.LoadFromFile(s);
Result:= sl[ALine - 1]; // index off by one
finally
sl.Free;
end;
end;
function GetLinesCount(sFileName : String): Integer;
var oSL : TStringlist;
begin
oSL:= TStringlist.Create;
oSL.LoadFromFile(sFileName);
result:= oSL.Count;
oSL.Free;
end; //[/DELPHI]
procedure STEXpressionPattern;
begin
with TStExpression.create(self) do begin
AddConstant('MPI',3.14159);
srlist:= TStringlist.create;
GetIdentList(srlist);
for it:= 0 to srlist.count-1 do
writeln(srlist.strings[it]);
srlist.Free;
Expression:= '2^10 * ln(8 +MPI)';
writeln(floattoStr(AnalyzeExpression))
free;
end;
end;
procedure TForm1Findwindow;
var
wnd: HWND;
i: Integer;
s: string;
begin
wnd := FindWindow('notepad', '');
if wnd <> 0 then begin
wnd := FindWindowEx(wnd, 0, 'Edit', '');
// Write Text in Notepad.
// Text ins Notepad schreiben.
s := 'Hello';
for i := 1 to Length(s) do
//SendMessage(wnd, WM_CHAR, word(s[i]), 0);
// Simulate Return Key.
PostMessage(wnd, WM_KEYDOWN, VK_RETURN, 0);
// Simulate Space.
PostMessage(wnd, WM_KEYDOWN, VK_SPACE, 0);
end;
end;
// function to add in expression at runtime
Function superPI(Value1: TStFloat): TStFloat;
begin
result:= value1 * PI;
end;
procedure TForm1_Button1Click(Sender: TObject);
var
H: HWND;
ClientWidth: integer;
begin
ClientWidth:= 300;
H := FindWindow('ConsoleWindowClass', 'C:\Windows\system32\cmd.exe');
if H<>0 then begin
{WinApi.Windows.}SetParent(H, Memo2.Handle);
SetWindowPos(H, 0, 0, 0, ClientWidth, ClientWidth, SWP_ASYNCWINDOWPOS);
end;
end;
procedure BitmapToMetafile(const Bmp: {Graphics.}TBitmap;
const EMF: {Graphics.}TMetafile);
var
MetaCanvas: {Graphics.}TMetafileCanvas; // canvas for drawing on metafile
begin
EMF.Height := Bmp.Height;
EMF.Width := Bmp.Width;
MetaCanvas := {Graphics.}TMetafileCanvas.Create(EMF, 0);
try
MetaCanvas.Draw(0, 0, Bmp);
finally
MetaCanvas.Free;
end;
end;
procedure ExtractRGB(const Color: {Graphics.}TColor; out Red, Green, Blue: Byte);
var
RGB: {Windows.}TColorREf; // RGB equivalent of given Colour
begin
RGB := {Graphics.}ColorToRGB(Color); // ensures system Colours are converted
Red := {Windows.}synGetRValue(RGB);
Green := {Windows.}synGetGValue(RGB);
Blue := {Windows.}synGetBValue(RGB);
end;
function ColorToRGBTriple(const Color: {Graphics.}TColor): {Windows.}TRGBTriple;
begin
ExtractRGB(Color, Result.rgbtRed, Result.rgbtGreen, Result.rgbtBlue);
end;
type
TPNGSig = array[0..7] of Byte; // png signature byte array
var
// png signature
cValidSig: TPNGSig; //integer; //TPNGSig = ($89, $50, $4E, $47, $0D, $0A, $1A, $0A);
function GetPNGSize(const FileName: string): {Types.}TSize;
var
Sig: TPNGSig; // png signature read from file
FS: {Classes.}TFileStream; // stream onto png file
X: Integer; // loops through bytes of signature
begin
Result.cx := 0;
Result.cy := 0;
if (FileName = '') or not {SysUtils.}FileExists(FileName) then
Exit;
FS := {Classes.}TFileStream.Create(
FileName, {SysUtils.}fmOpenRead or {SysUtils.}fmShareDenyNone
);
try
// Check signature
//FillChar(Sig, SizeOf(Sig), #0);
//FS.Read(Sig[0], SizeOf(Sig));
for X := Low(Sig) to High(Sig) do
if Sig[X] <> cValidSig[X] then
Exit;
// Signature valid: get dimensions
//FS.Seek(18, {Classes.}soFromBeginning);
//Result.cx := ReadBigEndianWord(FS);
//FS.Seek(22, Classes.soFromBeginning);
//Result.cy := ReadBigEndianWord(FS);
finally
FS.Free;
end;
end;
(*function ReadBigEndianWord(Stm: Classes.TStream): Word;
type
// Record used to hack big endian word
TBigEndianWord = packed record
case Byte of
0: (Value: Word); // value as word
1: (Byte1, Byte2: Byte); // value as bytes
end;
var
BEW: TBigEndianWord; // record read from stream
begin
FillChar(BEW, SizeOf(BEW), 0);
Stm.Read(BEW.Byte2, SizeOf(Byte));
Stm.Read(BEW.Byte1, SizeOf(Byte));
Result := BEW.Value;
end;
*)
const
cEscChar = '\'; // the C escape character
function IsValidCEscapedStr(const S, ValidEscChars: string): Boolean;
var
Idx: Integer; // loops thru chars in string
EscCharPos: Integer; // position of esc char in ValidEscChars
begin
// Assume we fail
Result := False;
// Scan through all string
Idx := 1;
while Idx <= Length(S) do begin
if (S[Idx] = cEscChar) then begin
// We have an escape char
if Idx = Length(S) then
Exit; // error: esc symbol is at end of string
// skip over escape symbol and test escape char
Inc(Idx);
EscCharPos := {SysUtils.}AnsiPos(S[Idx], ValidEscChars);
if EscCharPos = 0 then
Exit; // error: esc char is not recognised
end;
Inc(Idx);
end;
// Everything is OK
Result := True;
end;
procedure SendKeysToWindowX(const HWnd: {Windows.}HWND; const Text: string);
var
Idx: Integer; // current position in input string
Ch: Char; // current character in input string
WParam: LongInt; // WParam to WM_KEYxxx and WM_CHAR messages
LParam: LongInt; // LParam to WM_KEYxxx and WM_CHAR messages
ScanCode: Byte; // scan code of virtual key code
OEMScan: Word; // OEM scan code equivalent of virtual key code
begin
for Idx := 1 to Length(Text) do begin
// Record current char and its ordinal value
Ch := Text[Idx];
WParam := Ord(Ch);
// Send WM_KEYDOWN message
ScanCode := {Windows.}MapVirtualKey(WParam, 0);
LParam := 1 or (ScanCode shl 16) or $40000001; // sets bits 1 & 30
{Windows.}SendMessage(HWnd, {Messages.}WM_KEYDOWN, WParam, LParam);
// Send WM_CHAR message
OEMScan := {Windows.}LoByte({Windows.}VkKeyScan(Ch));
ScanCode := {Windows.}MapVirtualKey(OEMScan, 0);
LParam := 1 + (ScanCode shl 16) or $00000001; // sets bit 1
{Windows.}SendMessage(HWnd, {Messages.}WM_CHAR, WParam, LParam);
// Send WM_KEYUP message
ScanCode := {Windows.}MapVirtualKey(WParam, 0);
LParam := 1 or (ScanCode shl 16) or $C0000001; // sets bits 1, 30 & 31
{Windows.}SendMessage(HWnd, {Messages.}WM_KEYUP, WParam, LParam);
end;
end;
function LastPos(const SubStr, Str: string): Integer;
var
Idx: Integer; // an index of SubStr in Str
begin
Result := 0;
Idx := {StrUtils.}PosEx(SubStr, Str,1);
if Idx = 0 then
Exit;
while Idx > 0 do
begin
Result := Idx;
Idx := {StrUtils.}PosEx(SubStr, Str, Idx + 1);
end;
end;
procedure RemoveDuplicateStrings(const Strings: TStrings);
var
TempStrings: {Classes.}TStringList;
Cnt: Integer;
begin
if Strings.Count <= 1 then
Exit;
TempStrings := {Classes.}TStringList.Create;
try
TempStrings.Sorted := True;
TempStrings.Duplicates := {Classes.}dupIgnore;
for Cnt := 0 to Strings.Count - 1 do
TempStrings.Add(Strings[Cnt]);
Strings.Assign(TempStrings);
finally
TempStrings.Free;
end;
end;
function DownloadURLToFile(const URL, FileName: string): Boolean;
begin
// URLDownloadFile returns true if URL exists even if file not created
// hence we also check file has been created.
Result := {Windows.}Succeeded(
{UrlMon.}URLDownloadToFile(nil, PChar(URL), PChar(FileName), 0, nil)
) and {SysUtils.}FileExists(FileName);
end;
procedure PlaySoundX(const AFilename: string);
begin
//{MMSystem.}SndPlaySound(
//PChar(AFilename), MMSystem.SND_ASYNC or MMSystem.SND_NODEFAULT
//);
end;
function GetIEVersionStr: string;
var
Reg: {Registry.}TRegistry; // registry access object
begin
Result := '';
Reg := {Registry.}TRegistry.Create;
try
Reg.RootKey := {Windows.}HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly('Software\Microsoft\Internet Explorer') then begin
if Reg.ValueExists('Version') then
Result := Reg.ReadString('Version');
end;
finally
Reg.Free;
end;
end;
function GetBiosVendor: string;
var
Reg: TRegistry;
begin
Result := '';
Reg := TRegistry.Create1(KEY_READ);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if not Reg.OpenKey('HARDWARE\DESCRIPTION\System\Bios\', False) then
Exit;
Result := Reg.ReadString('BIOSVendor');
Reg.CloseKey;
finally
Reg.Free;
end;
end;
function ExtractURIQueryString(const URI: string): string;
var
QueryStart: Integer;
QueryEnd: Integer;
begin
Result := '';
QueryStart := {SysUtils.}AnsiPos('?', URI);
if QueryStart = 0 then
Exit;
Inc(QueryStart);
QueryEnd := {SysUtils.}AnsiPos('#', URI);
if QueryEnd < QueryStart then
QueryEnd := Length(URI)
else
Dec(QueryEnd);
Result := Copy(URI, QueryStart, QueryEnd - QueryStart + 1);
end;
function TerminateProcessByIDX(ProcessID: Cardinal): Boolean;
var
HProcess : THandle;
begin
Result := False;
HProcess := {Windows.}OpenProcess(PROCESS_TERMINATE, False, ProcessID);
if HProcess > 0 then
try
Result := {SysUtils.}Win32Check(TerminateProcess(HProcess, 0));
finally
{Windows.}CloseHandle(HProcess);
end;
end;
function GetWindowProcessName(const Wnd: {Windows.}HWND): string;
begin
Result := GetProcessName(GetWindowProcessID(Wnd));
end;
function ResourceExists(const Module: HMODULE;
const ResName, ResType: PChar): Boolean;
begin
Result := {Windows.}FindResource(Module, ResName, ResType) <> 0;
end;
//const
//SM_MEDIACENTER = 87; // metrics flag not defined in Windows unit
function IsMediaCenterOS: Boolean;
begin
Result := {Windows.}GetSystemMetrics(SM_MEDIACENTER) <> 0;
end;
//const
//SM_TABLETPC = 86; // metrics flag not defined in Windows unit
function IsTabletOS: Boolean;
begin
Result := GetSystemMetrics(SM_TABLETPC) <> 0;
end;
function GetProcessorName: string;
var
Reg: TRegistry;
begin
Result := '';
Reg := TRegistry.Create1(KEY_READ);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if not Reg.OpenKey(
'HARDWARE\DESCRIPTION\System\CentralProcessor\0\', False
) then
Exit;
Result := Reg.ReadString('ProcessorNameString');
Reg.CloseKey;
finally
Reg.Free;
end;
end;
//const
// float format specifiers
var
cFmtSpec : array[0..1] of Char; // = ('f', 'n');
function FloatToFixed2(const Value: Extended; const DecimalPlaces: Byte;
const SeparateThousands: byte{Boolean}): string;
begin
Result := {SysUtils.}Format(
'%.*' + cFmtSpec[SeparateThousands], [DecimalPlaces, Value]
);
end;
function Int64ToFixed(const Value: Int64;
const SeparateThousands: Boolean): string;
begin
Result := FloatToFixed(Value, 0, SeparateThousands);
end;
function RemainingBatteryPercent: Integer;
var
Stat: {Windows.}TSystemPowerStatus;
begin
{Windows.}GetSystemPowerStatus(Stat);
Result := Stat.BatteryLifePercent;
if (Result < 0) or (Result > 100) then
Result := -1;
end;
function GetProcessorIdentifier: string;
var
Reg: TRegistry;
begin
Result := '';
Reg := TRegistry.Create1(KEY_READ);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if not Reg.OpenKey(
'HARDWARE\DESCRIPTION\System\CentralProcessor\0\', False
) then
Exit;
Result := Reg.ReadString('Identifier');
Reg.CloseKey;
finally
Reg.Free;
end;
end;
procedure ListDrives(const List: {Classes.}TStrings);
var
Drives: PChar; // buffer for list of drives
BufSize: Integer; // size of drive buffer
begin
// Get buffer size and allocate it
BufSize := GetLogicalDriveStrings(0, 'nil');
//GetMem(Drives, BufSize * SizeOf(Char));
try
// Get #0 delimited drives list and convert to string list
if {Windows.}GetLogicalDriveStrings(BufSize, Drives) = 0 then
{SysUtils.}RaiseLastOSError;
MultiSzToStrings(Drives, List); //}
finally
//FreeMem(Drives);
end;
end;
function MakeSafeHTMLText(TheText: string): string;
var
Idx: Integer; // loops thru characters of TheText
Ch: Char; // each charactor in TheText
begin
Result := '';
for Idx := 1 to Length(TheText) do
begin
Ch := TheText[Idx];
case Ch of
'<': Result := Result + '<';
'>': Result := Result + '>';
'&': Result := Result + '&';
'"': Result := Result + '"';
else
begin
if (Ch < #32) or (Ch >= #127) then
Result := Result + '&#' + IntToStr(Ord(Ch)) + ';'
else
Result := Result + Ch;
end;
end;
end;
end;
function IsASCIIDigit(const Ch: Char): Boolean;
begin
//Result := Ord(Ch) in [Ord('0')..Ord('9')];
Result:= (Ord(Ch) >= Ord('0')) And (ord(ch) <= Ord('9'));
end;
procedure GetChunk(Source: string; var Pos: Integer; out Dest: string);
var
IsNum: Boolean; // flags if string chunk is numeric
DP: Integer; // cursor into Source string
begin
if Pos > Length(Source) then
Dest := ''
else begin
IsNum := IsASCIIDigit(Source[Pos]);
DP := 0;
while (Pos + DP <= Length(Source))
and (IsASCIIDigit(Source[Pos + DP]) = IsNum) do
Inc(DP);
Dest := Copy(Source, Pos, DP);
Pos := Pos + DP;
end;
end;
const LOCALE_ITIME = 1;
function Is24HourTimeFormat: Boolean;
var
DefaultLCID: {Windows.}LCID; // thread's default locale
begin
DefaultLCID := {Windows.}GetThreadLocale;
Result := 0 <> {SysUtils.}StrToIntDef(
{SysUtils.}GetLocaleStr(DefaultLCID, {Windows.}LOCALE_ITIME, '0'),
0
);
end;
const
cPercent = '%';
function CountPercent(const S: UTF8String): Integer;
var
Idx: Integer; // loops thru all octets of S
begin
Result := 0;
for Idx := 1 to Length(S) do
if S[Idx] = cPercent then
Inc(Result);
end;
const
ccOneMB = 1024 * 1024; // a megabyte in bytes
Function BytesToMB(const Bytes: Int64): Extended;
begin
Result := Bytes / cOneMB;
end;
function BytesToMBStr(const Bytes: Int64; const DecimalPlaces: Byte;
const SeparateThousands: Boolean): string;
begin
Result := FloatToFixed(BytesToMB(Bytes), DecimalPlaces, SeparateThousands);
end;
function MemoCursorPos(const Memo: TCustomMemo): TPoint;
var
Row, Col: Integer; // row and column containing cursor
begin
Row := SendMessage(
Memo.Handle, EM_LINEFROMCHAR, Memo.SelStart, 0
);
Col := Memo.SelStart - SendMessage(
Memo.Handle, EM_LINEINDEX, Row, 0
);
Result.X := Col;
Result.Y := Row;
end;
Const FName = 'maxboxlog2.log'; //'firstdemo3.txt';
Testtext = 'this is CODEsign to mine!..?';
var FormLab3D: TFormLab3D;
myfunc: TStMethod1Param;
idt: TIdThread;
Begin //main
//OpenDoc(exepath+FName)
{Memo1.Lines.LoadFromFile(YourFileNameHere);
AppendValueToStrings(Memo1.Lines, 10);
Memo1.Lines.SaveToFile(YourFileNameHere);}
//maxform1.N3dlab1click(self);
writeln(Strip('<br/>','<p>This is text.<br/>This is line 2</p>'))
writeln(StripString('<p>This is text.<br/>This is line 2</p>','<br/>'))
writeln(StripAny('<br/>','<p>This is text.<br/>This is line 2</p>'))
writeln(Strip('!',testtext));
writeln(StripAny('!,.?',testtext));
sr:= StripTags2('<p>This is text.<br/> This is line 2</p>');
//ShowMessage(s); // will display 'This is text.This is line 2'
writeln(sr); // will display 'This is text.This is line 2'
writeln(StripTags('<p>This is text.<br/> This is line 2</p>'));
Writeln(ReplaceRegExpr ('([</pbr>])*',
'<p>This is text.<br/> This is line 2</p>','', True))
Writeln(ReplaceRegExpr ('<[^>]*>',
'<p>This is text.<br/> This is line 2</p>','', True))
//CL.AddDelphiFunction('Function AnalyzeExpr( const Expr : AnsiString) : Double');
writeln(floattostr(AnalyzeExpr('2^10 * ln(8)')))
//add a function at runtime!
with TStExpression.create(self) do begin
AddConstant('MPI',3.14159);
{srlist:= TStringlist.create;
GetIdentList(srlist);
for it:= 0 to srlist.count-1 do
writeln(srlist.strings[it]);
srlist.Free;}
myfunc:= @superPI;
AddMethod1Param('getsuperpi', myfunc);
Expression:= '2^10 * ln(8 +MPI)';
writeln(floattoStr(AnalyzeExpression))
Expression:= '2^10 * ln(8 +MPI)+ getsuperpi(42)';
writeln(floattoStr(AnalyzeExpression))
free;
end;
{ srlist:= TStringlist.create;
//ConsoleCapture('C:\', 'cmd.exe', '/c dir *.* /s',srlist);
ConsoleCapture('C:\', 'cmd.exe', '/c dir *.*',srlist);
writeln(srlist.text)
srlist.Free;
}
srlist:= TStringlist.create;
//ConsoleCapture('C:\', 'cmd.exe', '/c dir *.* /s',srlist);
//ConsoleCapture('C:\', 'cmd.exe', '/k java -version',srlist);
ConsoleCapture('C:\', 'cmd.exe', '/c ipconfig',srlist);
// ConsoleCapture('C:\', 'cmd.exe', '/c netstat',srlist);
// ConsoleCapture('C:\', 'cmd.exe', '/c ping 127.0.0.1',srlist);
// CaptureConsoleOutput('java -version',memo2);
writeln(srlist.text)
srlist.Free;
//http://delphi.wikia.com/wiki/Capture_Console_Output_Realtime_To_Memo
// CaptureConsoleOutput('/c java -version',memo2);
//Function GetDosOutput( CommandLine : string; Work : string) : string');
//writeln('GetDosOutput '+GetDosOutput('cmd.exe','/c java -version'));
//http://delphidabbler.com/tips/61
writeln('GetDosOutput1: '+GetDosOutput('help dir','c:\'));
writeln('')
writeln('GetDosOutput2: '+GetDosOutput('java -version','c:\'));
//srlist:= TStringlist.create;
//ConsoleCapture('C:\', 'cmd.exe', '/c dir *.* /s',srlist);
//ConsoleCapture('C:\', 'cmd.exe', '/k java -version',srlist);
//ConsoleCapture('C:\', 'cmd.exe', '/c java -version',sr);
//writeln(sr)
//srlist.Free;
//ExecuteShell('cmd','/c rundll32.exe url.dll,TelnetProtocolHandler 172.134.77.119')
// ExecuteShell('cmd','/c rundll32.exe url.dll,MailToProtocolHandler [email protected]')
//ExecuteShell('cmd','/c rundll32.exe url.dll,NewsProtocolHandler borland.public.delphi.objectpascal')
//rundll32.exe url.dll,NewsProtocolHandler borland.public.delphi.objectpascal
SendCopyMessage('this is from outer box','TMaxForm1');
//SendCopyMessage('this is from outer box','MainForm');
writeln('comSpec '+getenvironmentvariable('ComSpec'))
// function ExecuteProcess(FileName: string;Visibility:Integer; BitMask:Integer; Synch:Boolean):Longword;
//bitmask ---> 2 means on second CPU, sync or async possible!
{ if ExecuteProcess('notepad.exe', SW_SHOW, 1, true) = 0 then
writeln('Multiprocessing Runs on CPU 1');
if ExecuteMultiProcessor('notepad.exe', SW_SHOW, 2, true) = 0 then
writeln('Multiprocessing Runs on CPU 2');
}
writeln('NUMBER_OF_PROCESSORS: '
+getEnvironmentVariable('NUMBER_OF_PROCESSORS'))
writeln(DecimalSeparator);
writeln(getDecimalSeparator);
//SysErrorMessage(GetLastError());
// ShowMessage(SysErrorMessage(GetLastError))
//RaiseException(erCustomError,'Your message goes here');
// The following line will not be executed because of the exception!
//MsgBox('You will not see this.', 'mbInformation', MB_OK);
{ with Application do begin
NormalizeTopMosts;
MessageBox('This should be on top.', 'Look', MB_OK); // [smbOK]
RestoreTopMosts;
end;
}
TForm1_Button1Click(self)
sr:= '';
writeln(botostr(CreateDOSProcessRedirected('cmd /c dir *.*','',sr)))
writeln('this dos '+sr)
//GetExceptionMessage
//BitmapToMetafile
ColorToRGBTriple(1234567)
//ExecuteCommandDOS 1
//CaptureConsoleOutput 2
//GetDosOutput 3
//SendKeysToWindow 4
//IsRunningOnBattery 5
// DOSCommand 6
//DOSCommandRedirect 7
//DownloadURLToFile 8
//DecimalToFraction 9
//IsRunningOnBattery
//ishexstr
//IsCharInSet
{if DownloadURLToFile('http://www.softwareschule.ch/maxboxnews.htm',
exepath+'localwebstore.txt') then
opendoc(exepath+'localwebstore.txt');
}
writeln(GetBiosVendor)
//hashofstring
//IntToNumberText2
//IsLibraryInstalled
//PostKeyEx32
//TerminateProcessByID
writeln(itoa(RemainingBatteryPercent))
writeln(GetProcessorName)
writeln(GetProcessorIdentifier)
// openweb('http://snippets.delphidabbler.com/#')
//GetRegistryString
//RefreshEnvironment
//function IsKeyPressed2(const VirtKeyCode: Integer): Boolean;
//IsKeyPressed2(const VirtKeyCode: Integer): Boolean;
//SizeOfFile64
//IShellLink
//TIdThread
//openweb
//openbrowser
//openurl
writeln(botostr(IsASCIIDigit('6')))
ShowShellPropertiesDlg(exepath+'maxbox4.exe')
End. // ConsoleCapt Code Snippets REGEX StripUtils
Ref:
function AllDigitsDifferent(N: Int64): Boolean;
var
UsedDigits: array[0..9] of Boolean; // records which digits have been used
I: 0..9; // loops through elements of UsedDigits
M: 0..9; // modulus after dividing by 10
begin
N := Abs(N);
Result := False;
for I := 0 to 9 do
UsedDigits[I] := False;
while N > 0 do
begin
M := N mod 10;
if UsedDigits[M] then
Exit;
UsedDigits[M] := True;
N := N div 10;
end;
Result := True; // if we get here all digits are unique
end;
procedure DecimalToFraction(Decimal: Extended; out FractionNumerator: Extended;
out FractionDenominator: Extended; const AccuracyFactor: Extended);
var
DecimalSign: Extended;
Z: Extended;
PreviousDenominator: Extended;
ScratchValue: Extended;
{$IFDEF FPC}
const
{$ELSE}
resourcestring
{$ENDIF}
sTooSmall = 'Decimal too small to convert to fraction';
sTooLarge = 'Decimal too large to convert to fraction';
const
LargestDecimal: Extended = 1.0E+19;
SmallestDecimal: Extended = 1.0E-19;
begin
if Decimal < 0.0 then
DecimalSign := -1.0
else
DecimalSign := 1.0;
Decimal := Abs(Decimal);
if Math.SameValue(Decimal, Int(Decimal)) then
begin
FractionNumerator := Decimal * DecimalSign;
FractionDenominator := 1.0;
Exit;
end;
if (Decimal < SmallestDecimal) then // X = 0 already taken care of
raise SysUtils.EConvertError.Create(sTooSmall);
if (Decimal > LargestDecimal) then
raise SysUtils.EConvertError.Create(sTooLarge);
Z := Decimal;
PreviousDenominator := 0.0;
FractionDenominator := 1.0;
repeat
Z := 1.0 / (Z - Int(Z));
ScratchValue := FractionDenominator;
FractionDenominator := FractionDenominator * Int(Z) + PreviousDenominator;
PreviousDenominator := ScratchValue;
FractionNumerator := Int(Decimal * FractionDenominator + 0.5) // Rounding
until
(
Abs(
Decimal - (FractionNumerator / FractionDenominator)
) < AccuracyFactor
)
or (Z = Int(Z));
FractionNumerator := DecimalSign * FractionNumerator;
end;
function ColorToHTML(const Color: Graphics.TColor): string;
var
ColorRGB: Integer;
begin
ColorRGB := Graphics.ColorToRGB(Color);
Result := SysUtils.Format(
'#%0.2X%0.2X%0.2X',
[Windows.GetRValue(ColorRGB),
Windows.GetGValue(ColorRGB),
Windows.GetBValue(ColorRGB)]
);
end;
function DOSCommand(const CommandLine: string; const CmdShow: Integer;
const WaitUntilComplete: Boolean; const WorkingDir: string = ''): Boolean;
var
ComSpec: array[0..Pred(Windows.MAX_PATH)] of Char;
FullCommandLine: string;
PWorkingDir: PChar;
SI: Windows.TStartupInfo;
PI: Windows.TProcessInformation;
begin
FillChar(SI, SizeOf(SI), #0);
SI.cb := SizeOf(SI);
SI.dwFlags := Windows.STARTF_USESHOWWINDOW; // needed to use wShowWindow
SI.wShowWindow := CmdShow;
Windows.GetEnvironmentVariable('COMSPEC', ComSpec, SizeOf(ComSpec));
FullCommandLine := ComSpec + ' /C ' + CommandLine;
if WorkingDir <> '' then
PWorkingDir := PChar(WorkingDir)
else
PWorkingDir := nil;
Result := Windows.CreateProcess(
nil,
PChar(FullCommandLine),
nil,
nil,
False,
Windows.NORMAL_PRIORITY_CLASS,
nil,
PWorkingDir,
SI,
PI
);
if Result then
begin
if WaitUntilComplete then
Windows.WaitforSingleObject(PI.hProcess, Windows.INFINITE);
Windows.CloseHandle(PI.hProcess);
Windows.CloseHandle(PI.hThread );
end;
end;
function DOSCommandRedirect(const CommandLine: string;
const OutStream: Classes.TStream): Boolean; overload;
var
SA: Windows.TSecurityAttributes;
SI: Windows.TStartupInfo;
PI: Windows.TProcessInformation;
ComSpec: array[0..Pred(Windows.MAX_PATH)] of Char;
FullCommandLine: string;
StdOutPipeRead, StdOutPipeWrite: THandle;
WasOK: Boolean;
Buffer: array[0..8*1024-1] of Char;
BytesRead: Cardinal;
begin
Windows.GetEnvironmentVariable('COMSPEC', ComSpec, SizeOf(ComSpec));
FullCommandLine := ComSpec + ' /C ' + CommandLine;
with SA do
begin
nLength := SizeOf(SA);
bInheritHandle := True;
lpSecurityDescriptor := nil;
end;
Windows.CreatePipe(StdOutPipeRead, StdOutPipeWrite, @SA, 0);
try
with SI do
begin
FillChar(SI, SizeOf(SI), 0);
cb := SizeOf(SI);