-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunContainerBlock.pas
1005 lines (834 loc) · 23.9 KB
/
unContainerBlock.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 unContainerBlock;
interface
uses
Vcl.ExtCtrls,Vcl.Controls,System.Classes,Winapi.Windows,Winapi.Messages,Vcl.Graphics,
Vcl.ComCtrls,Vcl.StdCtrls,unBlock;
Type
TDspContainerBlock=class(TDspBlock)
FEndBlock:TDspBlock;
private
FEndBlockName:String;
procedure SetEndBlockName(const Value: string);
function GetEndBlockName: string;
procedure SetEndBlock(const Value: TDspBlock);
protected
procedure AssignTo(Dest:TPersistent);override;
function createNewBlock: TDspBlock;override;
procedure Reattach(Sender: TDspBlock);override;
procedure SetParent(AParent: TWinControl); override;
procedure CreateLBE;virtual;
procedure setNewlyCreated(v:boolean);override;
procedure checkloopblock;override;
function getLinkTo: TDspBlock;override;
function getblocksize: integer;override;
public
EndBlockText:String;
procedure SetBounds( pLeft , pTop , pWidth , pHeight:integer );Override;
constructor Create(AOwner: TComponent); override;
destructor destroy;override;
function getLastDspBlock(caller:TDspBlock):TDspBlock;override;
function getContainersize:integer;
published
property EndBlock:TDspBlock read FEndBlock write SetEndBlock;
property EndBlockName:string read GetEndBlockName write SetEndBlockName;
end;
TDspContainerBlockEnd=class(TDspBlock)
FContainerBlock:TDspContainerBlock;
private
FContainerBlockName: String;
procedure SetContainerBlock(const Value: TDspContainerBlock);
procedure SetContainerBlockName(const Value: String);
function GetContainerBlockName: String;
protected
procedure Reattach(Sender: TDspBlock);override;
public
constructor Create(AOwner: TComponent); override;
procedure SetBounds( pLeft , pTop , pWidth , pHeight:integer );Override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
published
property ContainerBlock:TDspContainerBlock read FContainerBlock write SetContainerBlock;
property ContainerBlockName:String read GetContainerBlockName write SetContainerBlockName;
end;
TDspLoopBlock=Class(TDspContainerBlock)
protected
function createNewBlock: TDspBlock;override;
function getParam2: Integer;override;
End;
TDspControlBlock=Class(TDspContainerBlock)
private
FisSimple:Boolean;
sv:TColor;
FisMale: boolean;
procedure CBClick(Sender: TObject);
procedure SetCommaText;
procedure SetisMale(const Value: boolean);
procedure SetComboWidth;
procedure SetisSimple(const Value: Boolean);
protected
procedure setfParam1(const Value: Integer);Override;
function getParam1Text: String;override;
function createNewBlock: TDspBlock;override;
procedure RecalcWidth;override;
procedure CreateCtrl1;override;
procedure CreateCtrl2;override;
function getParam1Control(x, y: integer): integer;override;
function getParam2Control(x, y: integer): integer;override;
procedure edit2Change(Sender: TObject);override;
procedure edit1Change(Sender: TObject);override;
procedure loaded;override;
procedure SetParent(AParent: TWinControl); override;
function GetParam1Rect: TRect;override;
function getParam1: Integer;override;
public
constructor Create(AOwner: TComponent);override;
published
property IsSimple:Boolean read FisSimple write SetisSimple;
property isMale:boolean read FisMale write SetisMale;
end;
TDspControlBlockELSE=class;
TDspControlElseBlock=Class(TDspControlBlock)
fElseBlock:TDspBlock;
Elsebut:Tcheckbox;
private
FElseBlockName : string;
procedure elseclick(Sender: Tobject);
function GetElseBlockName: string;
procedure SetElseBlockName(const Value: string);
function getElsebutchecked: boolean;
procedure setElsebutchecked(const Value: boolean);
procedure SetElseBlock(const Value: TDspBlock);
protected
procedure CreateLBE;override;
procedure SetParent(AParent: TWinControl); override;
function getLastDspBlock(caller:TDspBlock):TDspBlock;override;
procedure Reattach(Sender: TDspBlock);override;
procedure checkloopblock;override;
procedure AssignTo(Dest:TPersistent);override;
procedure loaded;override;
public
function elsevisible:boolean;
function createNewBlock: TDspBlock;override;
constructor Create(AOwner: TComponent);override;
destructor destroy;override;
procedure Paint; override;
procedure SetNewWidth(nw: Integer);override;
procedure SetBounds( pLeft , pTop , pWidth , pHeight:integer );Override;
function GetArduinoCommand(idnt:integer=1):String;Override;
published
property ElseBlock:TDspBlock read FElseBlock write SetElseBlock;
property ElseBlockName:string read GetElseBlockName write SetElseBlockName;
property Elsebutchecked:boolean read getElsebutchecked write setElsebutchecked;
End;
TDspControlBlockELSE=class(TDspBlock)
FContainerBlock:TDspContainerBlock;
private
FContainerBlockName: String;
procedure SetContainerBlock(const Value: TDspContainerBlock);
procedure SetContainerBlockName(const Value: String);
function GetContainerBlockName: String;
protected
procedure Reattach(Sender: TDspBlock);override;
public
constructor Create(AOwner: TComponent); override;
procedure SetBounds( pLeft , pTop , pWidth , pHeight:integer );Override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
published
property ContainerBlock:TDspContainerBlock read FContainerBlock write SetContainerBlock;
property ContainerBlockName:String read GetContainerBlockName write SetContainerBlockName;
end;
implementation
uses sysutils,forms,dialogs,math,DspCombo;
procedure ComboBox_AutoWidth(const theComboBox: TCombobox);
const
HORIZONTAL_PADDING = 4;
var
itemsFullWidth: integer;
idx: integer;
itemWidth: integer;
begin
if theComboBox.parent=nil then exit;
if theComboBox.parent.parent=nil then exit;
itemsFullWidth := 0;
// get the max needed with of the items in dropdown state
for idx := 0 to -1 + theComboBox.Items.Count do
begin
itemWidth := theComboBox.Canvas.TextWidth(theComboBox.Items[idx]);
Inc(itemWidth, 2 * HORIZONTAL_PADDING);
if (itemWidth > itemsFullWidth) then Begin
itemsFullWidth := itemWidth;
Inc(itemsFullWidth,length(theComboBox.Items[idx]));
End;
end;
// set the width of drop down if needed
if (itemsFullWidth > theComboBox.Width) then
begin
//check if there would be a scroll bar
if theComboBox.DropDownCount < theComboBox.Items.Count then
itemsFullWidth := itemsFullWidth + GetSystemMetrics(SM_CXVSCROLL);
SendMessage(theComboBox.Handle, CB_SETDROPPEDWIDTH, itemsFullWidth, 0);
end;
end;
{ TDspContainerBlock }
procedure TDspContainerBlock.AssignTo(Dest: TPersistent);
var blck:TDspContainerBlock;
Begin
inherited Assignto(Dest);
if Dest is TDspContainerBlock then
Begin
blck:=TDspContainerBlock(Dest);
blck.EndBlockText:=EndBlockText;
End;
end;
procedure TDspContainerBlock.checkloopblock;
begin
inherited;
if assigned(FEndblock) then
Fendblock.Top:=FEndBlock.Top;
end;
constructor TDspContainerBlock.Create(AOwner: TComponent);
begin
inherited;
nospadDn:=40;
EndBlockText:='ÔÝëïò';
fParam1:=5;
end;
procedure TDspContainerBlock.CreateLBE;
begin
if csloading in Componentstate then exit; //do not create on loading
FEndBlock:=TDspContainerBlockEnd.CreateFloat(Owner);
FEndblock.Parent:=parent;
FEndblock.CommndID:=99;//container end for all
FEndblock.CommandText:=EndBlockText;
FEndblock.Color:=Color;
FEndblock.CommandColor:=CommandColor;
TDspContainerBlockEnd(FEndblock).ContainerBlock:=Self;
FEndblock.Left:=Left;
FEndblock.Top:=top+height+10;
FEndblock.prototype:=false;
end;
function TDspContainerBlock.createNewBlock: TDspBlock;
begin
result:= TDspContainerBlock.CreateFloat(Owner);
end;
destructor TDspContainerBlock.destroy;
begin
if assigned(FEndBlock) then
Begin
try
Freeandnil(fendblock);
except
FEndBlock:=nil;
end;
End;
inherited;
end;
function TDspContainerBlock.getblocksize: integer;
begin
result:=getContainersize;
end;
function TDspContainerBlock.getLastDspBlock(caller:TDspBlock): TDspBlock;
begin
result:= inherited getLastDspBlock(Caller);
if caller<>FEndBlock then
if assigned(FEndBlock) and (FEndBlock.linkto<>nil) then
Result:=FEndBlock.linkto.getLastDspBlock(caller)
else
result:=FEndBlock;
end;
function TDspContainerBlock.getLinkTo: TDspBlock;
begin
if assigned(FEndBlock) then
result:=FEndBlock
else result:=nil;
end;
function TDspContainerBlock.getContainersize: integer;
var res:integer;
begin
if assigned(FirstBlock) then
getDspBlockListSize(FirstBlock,res)
else res:=0;
result:=res+1;//plus self
end;
function TDspContainerBlock.GetEndBlockName: string;
begin
if assigned(EndBlock) then
result:=EndBlock.name
else
result:='';
end;
procedure TDspContainerBlock.Reattach(Sender: TDspBlock);
begin
inherited;
if assigned(FendBlock) then
FEndBlock.Top:=FEndBlock.Top;
// repaint;
end;
procedure TDspContainerBlock.SetBounds(pLeft, pTop, pWidth, pHeight: integer);
begin
inherited;
if assigned(FEndBlock) then
Begin
if Left<>FEndBlock.Left then
FEndBlock.Left:=Left;
FEndBlock.Top:=FEndBlock.Top;
End;
end;
procedure TDspContainerBlock.SetEndBlock(const Value: TDspBlock);
begin
FEndBlock := Value;
end;
procedure TDspContainerBlock.SetEndBlockName(const Value: string);
var f:TDspBlock;
begin
FEndBlockName := Value;
if assigned(owner) and not assigned(EndBlock) then
Begin
f:=TDspBlock(owner.FindComponent(FEndBlockName));
if assigned(f) then
EndBlock:=f;
End;
end;
procedure TDspContainerBlock.setNewlyCreated(v: boolean);
begin
inherited;
if not v then
CreateLBE;
RecalcWidth;
end;
procedure TDspContainerBlock.SetParent(AParent: TWinControl);
begin
inherited;
if assigned(FEndBlock) then
FEndBlock.Parent:=AParent;
end;
{ TDspLoopBlock }
function TDspLoopBlock.createNewBlock: TDspBlock;
begin
result:= TDspLoopBlock.CreateFloat(Owner);
end;
function TDspLoopBlock.getParam2: Integer;
begin
result:=getContainersize;
end;
{ TDspContainerBlockEnd }
constructor TDspContainerBlockEnd.Create(AOwner: TComponent);
begin
inherited;
fNewlycreated:=false;
topNose:=false;
end;
function TDspContainerBlockEnd.GetContainerBlockName: String;
begin
if assigned(ContainerBlock) then
result:=ContainerBlock.name
else
result:='';
end;
procedure TDspContainerBlockEnd.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
//
end;
procedure TDspContainerBlockEnd.Reattach(Sender: TDspBlock);
begin
inherited;
Left:=FContainerBlock.Left;
if assigned(FContainerBlock) then
FContainerBlock.Reattach(Sender);
repaint;
end;
procedure TDspContainerBlockEnd.SetBounds(pLeft, pTop, pWidth, pHeight: integer);
Var bk:TDspBlock;
t:integer;
begin
inherited;
if assigned(FContainerBlock) then
Begin
if Left<>FContainerBlock.Left then
Left:=FContainerBlock.Left;
bk:=FContainerBlock.getLastDspBlock(Self);
if not assigned(bk) or (bk=self) then exit;
t:=bk.Top+bk.Height+10;
if top<>t then
top:=t;
End;
end;
procedure TDspContainerBlockEnd.SetContainerBlock(const Value: TDspContainerBlock);
begin
if assigned(FContainerBlock) then
FContainerBlock.free;
FContainerBlock := Value;
end;
procedure TDspContainerBlockEnd.SetContainerBlockName(const Value: String);
var f:TDspContainerBlock;
begin
FContainerBlockName := Value;
if assigned(owner) and not assigned(ContainerBlock) then
Begin
f:=TDspContainerBlock(owner.FindComponent(FContainerBlockName));
if assigned(f) then
ContainerBlock:=f;
End;
end;
{ TDspControlBlock }
constructor TDspControlBlock.Create(AOwner: TComponent);
Begin
inherited;
Param1:=0;
param2:=5;
totalparams:=1;
FIsSimple:=true;
FisMale:=false;
End;
procedure TDspControlBlock.CreateCtrl1;
Begin
// ctrl1:=TComboHack.Create(self);
// ctrl1.parent:=self;
// TCombobox(ctrl1).OnClick:=cbclick;
// TCombobox(ctrl1).Font.Size:=8;
// TCombobox(ctrl1).Font.Style:=[fsBold];
//// TComboHack(ctrl1).BevelWidth:=1;
// TComboBox(ctrl1).BevelInner:=bvnone;
// TComboBox(ctrl1).BevelOuter:=bvspace;
// TComboBox(ctrl1).BevelEdges:=[];
// TComboBox(ctrl1).Style:=csDropDown;
// TComboBox(ctrl1).Ctl3D:=true;
// TCombobox(ctrl1).Height:=16;
ctrl1:=TDspCombo.Create(self);
ctrl1.parent:=self;
TDspCombo(ctrl1).OnClick:=cbclick;
TDspCombo(ctrl1).Font.Assign(Font);
// TDspCombo(ctrl1).Font.Size:=8;
TDspCombo(ctrl1).Font.Style:=[fsBold];
TDspCombo(ctrl1).Height:=16;
TDspCombo(ctrl1).AutoSize:=true;
ctrl1.Width:=45;
End;
procedure TDspControlBlock.CreateCtrl2;
Begin
inherited;
End;
procedure TDspControlBlock.CBClick(Sender: TObject);
Begin
// param1:=Integer(Tcheckbox(sender).checked);
param1:=TDspCombo(sender).ItemIndex;
//SetComboWidth;
End;
procedure TDspControlBlock.edit1Change(Sender: TObject);
begin
inherited;
end;
procedure TDspControlBlock.edit2Change(Sender: TObject);
begin
inherited;
end;
function TDspControlBlock.createNewBlock: TDspBlock;
begin
result:= TDspControlBlock.CreateFloat(Owner);
// isSimple:=True;
// IsMale:=False;
sv:=-1;
end;
procedure TDspControlBlock.RecalcWidth;
begin
inherited;
end;
procedure TDspControlBlock.SetComboWidth;
var i,w:integer;
const
HORIZONTAL_PADDING = 4;
begin
exit;
if TCombobox(ctrl1).Text='' then exit;
w:=45;
w:=max(w,TCombobox(ctrl1).Canvas.TextWidth(TCombobox(ctrl1).Text));
Inc(w, 2 * HORIZONTAL_PADDING);
Inc(w,length(TCombobox(ctrl1).Text)*2);
inc(w,2);
// for i := 0 to TCombobox(ctrl1).items.count-1 do
// w:=max(w,TCombobox(ctrl1).Canvas.TextWidth(TCombobox(ctrl1).Items[i]));
TCombobox(ctrl1).Width:=w;
ComboBox_AutoWidth(TCombobox(ctrl1));
end;
function TDspControlBlock.getParam1Text:String;
Begin
Result:=TDspCombo(ctrl1).text;
End;
procedure TDspControlBlock.SetCommaText;
var s:String;
Begin
s:=param1prompt;
if s='' then
s:='ü÷é';
//if not Assigned(Parent) then exit;
if FisSimple then
Begin
TDspCombo(ctrl1).Items.CommaText:=',"'+s+'"';
// ArduCheck:='==,!=';
End
else
Begin
if IsMale then //todo:Add not equal
TDspCombo(ctrl1).Items.CommaText:='"ìåãáëýôåñï áðü","ìéêñüôåñï áðü","ßóï ìå","ìåãáëýôåñï Þ ßóï áðü","ìéêñüôåñï Þ ßóï áðü"'
else
TDspCombo(ctrl1).Items.CommaText:='"ìåãáëýôåñç áðü","ìéêñüôåñç áðü","ßóç ìå","ìåãáëýôåñç Þ ßóç áðü","ìéêñüôåñç Þ ßóç áðü"';
// ArduCheck:='<=,>=,==,<,>';
End;
ArduCheck:='==,!=,>,<,==,>=,<='; //all commands together
//SetComboWidth;
// ComboBox_AutoWidth(TCombobox(ctrl1));
if (TDspCombo(ctrl1).Text='') or (TDspCombo(ctrl1).Text='0') then
Begin
TDspCombo(ctrl1).Itemindex:=0;
Myhint:=myhint;
param1:=0;
End;
End;
procedure TDspControlBlock.setfParam1(const Value: Integer);
begin
inherited;
if TDspCombo(Ctrl1).ItemCount=0 then
SetCommaText;
if TdspCombo(Ctrl1).ItemCount>Value then
TdspCombo(Ctrl1).Itemindex:=Value;
end;
procedure TDspControlBlock.SetisMale(const Value: boolean);
begin
FisMale := Value;
SetCommaText;
end;
procedure TDspControlBlock.SetisSimple(const Value: Boolean);
begin
FisSimple := Value;
if Assigned(Parent) then
Begin
SetCommaText;
TDspCombo(Ctrl1).Itemindex:=TDspCombo(Ctrl1).Itemindex;//Re Set text
Param1:=TDspCombo(Ctrl1).Itemindex;
End;
end;
procedure TDspControlBlock.SetParent(AParent: TWinControl);
begin
inherited;
if Assigned(AParent) then
SetCommatext;
end;
function TDspControlBlock.getParam1: Integer;
begin
if not IsSimple then
Result:=inherited getParam1+2//2 commands of simple is 0 and 1 itemindex of combobox
else
Result:=inherited getParam1;
end;
Type TDspComboHack=Class(TDspCombo);
function TDspControlBlock.getParam1Control(x,y:integer):integer;
var s:string;
res:integer;
Begin
// if param1=1 then
// s:=param1prompt else s:='';
if sv=-1 then
sv:=TDspComboHack(ctrl1).canvas.Font.Color;
res:=x;
if not prototype then
Begin
if param1=1 then
Begin
TDspComboHack(ctrl1).canvas.Font.Color:=clRed;
End
else if sv<>-1 then
TDspComboHack(ctrl1).canvas.Font.Color:=sv;
ctrl1.left:=x; //combobox position
ctrl1.top:=y;
if not ctrl1.Visible then SetCommaText;
ctrl1.visible:=true;
res:=res+ctrl1.width;
End
else ctrl1.Visible:=false;
// sv:=canvas.Font.Color;
// canvas.Font.Color:=clRed;
// canvas.TextOut(res,y ,s);
// canvas.Font.Color:=sv;
//res:=res+canvas.TextWidth(s);
result:=res;
End;
function TDspControlBlock.GetParam1Rect: TRect;
begin
Result.Empty;
end;
function TDspControlBlock.getParam2Control(x,y:integer):integer;
Begin
result := inherited getParam2Control(x,y);
End;
procedure TDspControlBlock.loaded;
begin
inherited;
if assigned(ctrl1) and assigned(parent) then
//TCheckBox(ctrl1).Checked:=param1=1;
Begin
SetCommaText;
if not IsSimple then
fparam1:=fparam1-2;
TDspCombo(ctrl1).ItemIndex:=fparam1;
End;
end;
{ TDspControlElseBlock }
procedure TDspControlElseBlock.AssignTo(Dest: TPersistent);
var blck:TDspControlElseBlock;
begin
inherited;
if Dest is TDspControlElseBlock then
Begin
blck:=TDspControlElseBlock(Dest);
blck.Elsebut.font.Assign(font);
blck.Elsebut.Visible:=true;
blck.IsSimple:=isSimple;
End;
end;
procedure TDspControlElseBlock.checkloopblock;
begin
inherited;
if assigned(FElseblock) and FElseblock.visible then
FElseblock.Top:=FElseBlock.Top;
end;
constructor TDspControlElseBlock.Create(AOwner: TComponent);
begin
inherited;
Elsebut:=Tcheckbox.create(self);
Elsebut.parent:=self;
Tcheckbox(Elsebut).Caption:='';
Elsebut.Width:=25;
TCheckBox(Elsebut).Checked:=false;
Tcheckbox(Elsebut).OnClick:=elseclick;
elsebut.Top:=12;
Elsebut.ShowHint:=true;
Elsebut.Hint:='Åíåñãïðïßçóç "Áëëéþò"';
elsebut.Visible:=false;
end;
procedure TDspControlElseBlock.elseclick(Sender:Tobject);
Begin
if csLoading in componentstate then exit;
if not assigned(ElseBlock) then exit;
if not elsebut.Checked and assigned(fElseblock.LinkTo) then
Begin
if MessageDlg('ÕðÜñ÷ïõí åíôïëÝò óôï block "áëëéþò" ðïõ èá äéáãñáöïýí.'#10#13' Åßóáé óßãïõñïò;',mtWarning , mbOKCancel, 0)=mrOk then
Begin
fElseblock.LinkTo.Free;
fElseblock.LinkTo:=nil;
End
else
elsebut.Checked:=true;
End;
fElseBlock.Visible:=elsebut.Checked;
invalidate;
fEndblock.top:=fEndblock.top;
End;
function TDspControlElseBlock.elsevisible: boolean;
begin
result:=elsebut.checked;
end;
function TDspControlElseBlock.GetArduinoCommand(idnt: integer): String;
var ts:Tstringlist;
begin
if fArduinoCommand='' then fArduinoCommand:=ArduCmd;
if pos('%p1',fArduinoCommand)>0 then
Begin
ts:=Tstringlist.create;
ts.CommaText:=ArduCheck;
fArduinoCommand:=stringReplace(fArduinoCommand,'%p1',ts[param1],[rfReplaceAll]);
ts.Free;
End;
Result:=inherited GetArduinoCommand(idnt);
end;
function TDspControlElseBlock.GetElseBlockName: string;
begin
if assigned(ElseBlock) then
result:=ElseBlock.name
else
result:='';
end;
procedure TDspControlElseBlock.CreateLBE;
begin
inherited;
if csloading in Componentstate then exit; //do not create on loading
fElseBlock:=TDspControlBlockElse.CreateFloat(Owner);
fElseBlock.topNose:=false;
fElseBlock.Parent:=parent;
fElseBlock.CommndID:=100;//Control Else for all
fElseBlock.CommandText:='Áëëéþò';
fElseBlock.ArduCmd:='else {';
fElseBlock.Color:=Color;
fElseBlock.CommandColor:=CommandColor;
TDspControlBlockElse(fElseBlock).ContainerBlock:=Self;
fElseBlock.Left:=Left;
fElseBlock.Top:=top+height+10;
fElseBlock.prototype:=false;
fElseblock.Visible:=false;
end;
function TDspControlElseBlock.createNewBlock: TDspBlock;
begin
result:= TDspControlElseBlock.CreateFloat(Owner);
end;
destructor TDspControlElseBlock.destroy;
begin
if assigned(FElseBlock) then
Begin
try
Freeandnil(FElseBlock);
except
FElseBlock:=nil;
end;
End;
inherited;
end;
function TDspControlElseBlock.getElsebutchecked: boolean;
begin
result:=elsebut.Checked;
end;
function TDspControlElseBlock.getLastDspBlock(caller: TDspBlock): TDspBlock;
begin
if caller=FElseblock then
result:= inherited getLastDspBlock(FEndblock)
else
if (caller=FEndblock) and elsevisible then
Begin
if assigned(fElseBlock) and (fElseBlock.linkto<>nil) then
Result:=fElseBlock.linkto.getLastDspBlock(caller)
else
result:=fElseBlock;
End
else
result:= inherited getLastDspBlock(Caller);
end;
procedure TDspControlElseBlock.loaded;
begin
inherited;
Elsebut.Visible:=true;
end;
procedure TDspControlElseBlock.Paint;
begin
inherited;
end;
procedure TDspControlElseBlock.Reattach(Sender: TDspBlock);
begin
inherited;
if assigned(FElseBlock) then
FElseBlock.Top:=FElseBlock.Top;
end;
procedure TDspControlElseBlock.SetBounds(pLeft, pTop, pWidth, pHeight: integer);
begin
inherited;
if assigned(FElseBlock) then
Begin
if Left<>FElseBlock.Left then
FElseBlock.Left:=Left;
FElseBlock.Top:=FElseBlock.Top;
End;
end;
procedure TDspControlElseBlock.SetElseBlock(const Value: TDspBlock);
begin
FElseBlock := Value;
if assigned(FElseBlock) then
FElseBlock.visible:=elsevisible;
end;
procedure TDspControlElseBlock.SetElseBlockName(const Value: string);
var f:TDspBlock;
begin
FElseBlockName := Value;
if assigned(owner) and not assigned(ElseBlock) then
Begin
f:=TDspBlock(owner.FindComponent(FElseBlockName));
if assigned(f) then
ElseBlock:=f;
End;
end;
procedure TDspControlElseBlock.setElsebutchecked(const Value: boolean);
begin
elsebut.Checked:=value;
end;
procedure TDspControlElseBlock.SetNewWidth(nw: Integer);
begin
if elsebut.Visible then
begin
Elsebut.Left:=nw+3;
inherited SetNewWidth(elsebut.left+elsebut.Width+8);
end
else
inherited SetNewWidth(nw);
end;
procedure TDspControlElseBlock.SetParent(AParent: TWinControl);
begin
inherited;
if assigned(fElseBlock) then
fElseBlock.Parent:=AParent;
end;
{ TDspControlBlockELSE }
constructor TDspControlBlockELSE.Create(AOwner: TComponent);
begin
inherited;
fNewlycreated:=false;
topNose:=false;
nospadDn:=40;
end;
function TDspControlBlockELSE.GetContainerBlockName: String;
begin
if assigned(ContainerBlock) then
result:=ContainerBlock.name
else
result:='';
end;
procedure TDspControlBlockELSE.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//
end;
procedure TDspControlBlockELSE.Reattach(Sender: TDspBlock);
begin
inherited;
Left:=FContainerBlock.Left;
if assigned(FContainerBlock) then
FContainerBlock.Reattach(Sender);
repaint;
end;
procedure TDspControlBlockELSE.SetBounds(pLeft, pTop, pWidth, pHeight: integer);
Var bk:TDspBlock;
t:integer;
begin
inherited;
if assigned(FContainerBlock) then
Begin
if Left<>FContainerBlock.Left then
Left:=FContainerBlock.Left;
bk:=FContainerBlock.getLastDspBlock(Self);
if not assigned(bk) or (bk=self) then exit;
t:=bk.Top+bk.Height+10;
if top<>t then
top:=t;
End;
end;
procedure TDspControlBlockELSE.SetContainerBlock(
const Value: TDspContainerBlock);
begin
FContainerBlock:=value;
end;
procedure TDspControlBlockELSE.SetContainerBlockName(const Value: String);
var f:TDspContainerBlock;
begin
FContainerBlockName := Value;
if assigned(owner) and not assigned(ContainerBlock) then
Begin
f:=TDspContainerBlock(owner.FindComponent(FContainerBlockName));
if assigned(f) then
ContainerBlock:=f;
End;
end;
initialization
System.Classes.RegisterClass(TDspControlBlockELSE);
System.Classes.RegisterClass(TDspControlElseBlock);
System.Classes.RegisterClass(TDspControlBlock);
System.Classes.RegisterClass(TDspLoopBlock);