Optimize some boolean conditions.
[marekmrva_bc.git] / FloatEditClass.pas
blob44f525600c6c7c82d722a67a63eceaf64c8f805d
1 unit FloatEditClass;
3 interface
5 uses
6 FunctionsClass, ResourcesClass,
7 Classes, Controls, Forms, Graphics, StdCtrls;
9 type
11 { TFloatEdit }
13 TFLoatEdit = class(TForm)
14 private
15 pChange, pCancel: TButton;
16 pCheckBox: TCheckBox;
17 pFloatEdit, pHexEdit: TEdit;
18 pFloatLabel, pHexLabel: TLabel;
19 pFP: Pointer;
20 pSize: Integer;
21 pUserChange: Boolean;
22 procedure pFloatChange(Sender: TObject); virtual;
23 procedure pHexChange(Sender: TObject); virtual;
24 procedure pOnShow(Sender: TObject); virtual;
25 public
26 constructor Create(AOwner: TComponent); override;
27 function ShowBox(Input: Pointer; Size: Integer): Boolean; overload; virtual;
28 function ShowBox(Input: Pointer; Size: Integer; var Check: Boolean): Boolean; overload; virtual;
29 end;
31 implementation
33 // ************************************************************************** //
34 // * TFLoatEdit implementation * //
35 // ************************************************************************** //
37 procedure TFLoatEdit.pFloatChange(Sender: TObject);
38 begin
39 if not pUserChange then Exit;
40 pUserChange := False;
41 CustomStrToFloat(pFloatEdit.Text, pFP, pSize);
42 pHexEdit.Text := CustomDataToHex(pFP, pSize);
43 pUserChange := True;
44 end;
46 procedure TFLoatEdit.pHexChange(Sender: TObject);
47 begin
48 if not pUserChange then Exit;
49 pUserChange := False;
50 CustomHexToData(pHexEdit.Text, pFP, pSize);
51 pFloatEdit.Text := CustomFloatToStr(pFP, pSize);
52 pUserChange := True;
53 end;
55 procedure TFLoatEdit.pOnShow(Sender: TObject);
56 begin
57 pFloatEdit.Text := CustomFloatToStr(pFP, pSize);
58 pFloatEdit.SetFocus;
59 end;
61 constructor TFLoatEdit.Create(AOwner: TComponent);
62 begin
63 inherited CreateNew(AOwner, 0);
64 Position := poDesktopCenter;
65 ClientWidth := 231;
66 ClientHeight := 105;
67 BorderStyle := bsDialog;
68 OnShow := pOnShow;
69 pChange := TButton.Create(Self);
70 with pChange do
71 begin
72 Parent := Self;
73 Caption := FL_EDIT_OK;
74 Left := 77;
75 Top := 81;
76 Width := 72;
77 Height := 20;
78 ModalResult := mrOk;
79 Default := True;
80 end;
81 pCancel := TButton.Create(Self);
82 with pCancel do
83 begin
84 Parent := Self;
85 Caption := FL_EDIT_CANCEL;
86 Left := 153;
87 Top := 81;
88 Width := 72;
89 Height := 20;
90 ModalResult := mrCancel;
91 Cancel := True;
92 end;
93 pCheckBox := TCheckBox.Create(Self);
94 with pCheckBox do
95 begin
96 Parent := Self;
97 Caption := FL_EDIT_MODIFY_TAG;
98 Left := 9;
99 Top := 57;
100 Width := 200;
101 Height := 19;
102 end;
103 pFloatEdit := TEdit.Create(Self);
104 with pFloatEdit do
105 begin
106 Parent := Self;
107 Left := 41;
108 Top := 7;
109 Width := 186;
110 Height := 20;
111 OnChange := pFloatChange;
112 end;
113 pHexEdit := TEdit.Create(Self);
114 with pHexEdit do
115 begin
116 Parent := Self;
117 Left := 41;
118 Top := 31;
119 Width := 186;
120 Height := 20;
121 OnChange := pHexChange;
122 end;
123 pFloatLabel := TLabel.Create(Self);
124 with pFloatLabel do
125 begin
126 Parent := Self;
127 Caption := FL_EDIT_FLOAT;
128 Left := 9;
129 Top := 10;
130 Width := 309;
131 Height := 21;
132 end;
133 pHexLabel := TLabel.Create(Self);
134 with pHexLabel do
135 begin
136 Parent := Self;
137 Caption := FL_EDIT_HEX;
138 Left := 9;
139 Top := 34;
140 Width := 309;
141 Height := 21;
142 end;
143 pUserChange := True;
144 end;
146 function TFLoatEdit.ShowBox(Input: Pointer; Size: Integer): Boolean;
148 lcheck: Boolean;
149 begin
150 lcheck := False;
151 Result := ShowBox(Input, Size, lcheck);
152 end;
154 function TFLoatEdit.ShowBox(Input: Pointer; Size: Integer; var Check: Boolean
155 ): Boolean;
156 begin
157 Result := False;
158 if Check then
159 begin
160 pCheckBox.Checked := True;
161 pCheckBox.Visible := True;
163 else
164 pCheckBox.Visible := False;
165 pFP := Input;
166 if (Size in [4, 8, 10]) then
167 begin
168 pSize := Size;
169 if (ShowModal = mrOk) then Result := True;
170 Check := pCheckBox.Checked;
171 end;
172 end;
174 end.