1 | unit Helper_ValueEdit;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
7 | Dialogs, StdCtrls, CrossEdit, Math;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TForm_ValueEdit = class(TForm)
|
---|
11 | group: TGroupBox;
|
---|
12 | btn_ok: TButton;
|
---|
13 | btn_cancel: TButton;
|
---|
14 | lbl_current: TLabel;
|
---|
15 | edit_current: TEdit;
|
---|
16 | lbl_new: TLabel;
|
---|
17 | lbl_offset: TLabel;
|
---|
18 | lbl_datatype: TLabel;
|
---|
19 | edit_offset: TEdit;
|
---|
20 | edit_datatype: TEdit;
|
---|
21 | procedure btn_cancelClick(Sender: TObject);
|
---|
22 | procedure btn_okClick(Sender: TObject);
|
---|
23 | procedure MakeVarInput(objectname: String; offset: LongWord;
|
---|
24 | datatype: Word; current: String; caller: TObject);
|
---|
25 | procedure FormCreate(Sender: TObject);
|
---|
26 | private
|
---|
27 | public
|
---|
28 | edit_new: TCrossEdit;
|
---|
29 | end;
|
---|
30 |
|
---|
31 | var
|
---|
32 | Form_ValueEdit: TForm_ValueEdit;
|
---|
33 |
|
---|
34 |
|
---|
35 | implementation
|
---|
36 |
|
---|
37 | uses BinEdit, RawEdit, DataStructures, Main;
|
---|
38 |
|
---|
39 | {$R *.dfm}
|
---|
40 |
|
---|
41 | var
|
---|
42 | caller_win_dat: TForm_BinEdit;
|
---|
43 | caller_win_raw: TForm_RawEdit;
|
---|
44 | _datatype: Word;
|
---|
45 | _offset: LongWord;
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | procedure TForm_ValueEdit.MakeVarInput(objectname: String; offset: LongWord;
|
---|
51 | datatype: Word; current: String; caller: TObject);
|
---|
52 | begin
|
---|
53 | caller_win_dat := nil;
|
---|
54 | caller_win_raw := nil;
|
---|
55 | if Pos('rawedit', TComponent(caller).Name) > 0 then
|
---|
56 | caller_win_raw := TForm_RawEdit(caller)
|
---|
57 | else
|
---|
58 | caller_win_dat := TForm_BinEdit(caller);
|
---|
59 | Form_Main.Enabled := False;
|
---|
60 | Self.Visible := True;
|
---|
61 | group.Caption := 'Edit value';
|
---|
62 | _datatype := datatype;
|
---|
63 | _offset := offset;
|
---|
64 | if Length(objectname) > 0 then
|
---|
65 | group.Caption := group.Caption + ' for ' + objectname;
|
---|
66 | edit_offset.Text := '0x' + IntToHex(offset, 8);
|
---|
67 | edit_datatype.Text := GetDataType(datatype);
|
---|
68 | edit_current.Text := current;
|
---|
69 | edit_new.EditType := etString;
|
---|
70 | edit_new.Text := '';
|
---|
71 | edit_new.LimitCheck := False;
|
---|
72 | edit_new.MaxLength := 0;
|
---|
73 | edit_new.Max := 0;
|
---|
74 | edit_new.BorderStyle := bsSingle;
|
---|
75 | Self.Width := 300;
|
---|
76 | case datatype of
|
---|
77 | 1..4:
|
---|
78 | begin
|
---|
79 | edit_new.EditType := etUnsignedInt;
|
---|
80 | edit_new.LimitCheck := True;
|
---|
81 | edit_new.Max := Int(Power(256, datatype)) - 1;
|
---|
82 | end;
|
---|
83 | 5..8:
|
---|
84 | begin
|
---|
85 | edit_new.MaxLength := 2 * (datatype - 4);
|
---|
86 | edit_new.EditType := etHex;
|
---|
87 | end;
|
---|
88 | 9:
|
---|
89 | begin
|
---|
90 | edit_new.EditType := etFloat;
|
---|
91 | edit_new.LimitCheck := False;
|
---|
92 | end;
|
---|
93 | 10:
|
---|
94 | begin
|
---|
95 | edit_new.EditType := etBinary;
|
---|
96 | edit_new.LimitCheck := False;
|
---|
97 | edit_new.MaxLength := 8;
|
---|
98 | end;
|
---|
99 | 13..16:
|
---|
100 | begin
|
---|
101 | Exit;
|
---|
102 | edit_new.EditType := etInteger;
|
---|
103 | edit_new.LimitCheck := True;
|
---|
104 | edit_new.Max := Int((Power(256, datatype - 13)) / 2) - 1;
|
---|
105 | edit_new.Min := 1 - Int((Power(256, datatype - 13)) / 2) - 1;
|
---|
106 | end;
|
---|
107 | 10000..65535:
|
---|
108 | begin
|
---|
109 | edit_new.EditType := etString;
|
---|
110 | edit_new.LimitCheck := False;
|
---|
111 | edit_new.MaxLength := datatype - 10000;
|
---|
112 | Self.Width := 700;
|
---|
113 | end;
|
---|
114 | end;
|
---|
115 | edit_new.SetFocus;
|
---|
116 | edit_new.SelectAll;
|
---|
117 | end;
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 | procedure TForm_ValueEdit.btn_okClick(Sender: TObject);
|
---|
123 | begin
|
---|
124 | if not edit_new.NoValidValue then
|
---|
125 | begin
|
---|
126 | Form_Main.Enabled := True;
|
---|
127 | Self.Visible := False;
|
---|
128 | if caller_win_dat = nil then
|
---|
129 | caller_win_raw.SetNewValue(_datatype, _offset, edit_new.Text)
|
---|
130 | else
|
---|
131 | caller_win_dat.SetNewValue(_datatype, _offset, edit_new.Text);
|
---|
132 | end;
|
---|
133 | end;
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 | procedure TForm_ValueEdit.FormCreate(Sender: TObject);
|
---|
139 | begin
|
---|
140 | edit_new := TCrossEdit.Create(Self);
|
---|
141 | with edit_new do
|
---|
142 | begin
|
---|
143 | Left := 88;
|
---|
144 | Top := 88;
|
---|
145 | Width := 203;
|
---|
146 | Height := 18;
|
---|
147 | Anchors := [akLeft, akTop, akRight];
|
---|
148 | AutoSize := False;
|
---|
149 | BorderStyle := bsNone;
|
---|
150 | Color := clWhite;
|
---|
151 | Font.Charset := DEFAULT_CHARSET;
|
---|
152 | Font.Color := clWindowText;
|
---|
153 | Font.Height := -11;
|
---|
154 | Font.Name := 'Tahoma';
|
---|
155 | Font.Style := [];
|
---|
156 | HideSelection := False;
|
---|
157 | ParentFont := False;
|
---|
158 | TabOrder := 5;
|
---|
159 | Text := '0000';
|
---|
160 | FocusAlignment := taLeftJustify;
|
---|
161 | NoFocusAlignment := taLeftJustify;
|
---|
162 | Precision := 15;
|
---|
163 | Decimals := 4;
|
---|
164 | FocusWidthInc := 0;
|
---|
165 | EditType := etHex;
|
---|
166 | NextDialogOnEnter := True;
|
---|
167 | DialogOnCursorKeys := True;
|
---|
168 | NextPriorStep := 1;
|
---|
169 | AutoFocus := False;
|
---|
170 | LimitCheck := True;
|
---|
171 | Max := 2147483647.000000000000000000;
|
---|
172 | FocusColor := clWhite;
|
---|
173 | NoFocusColor := clWhite;
|
---|
174 | ErrorColor := clRed;
|
---|
175 | StringCharSet := scFull;
|
---|
176 | end;
|
---|
177 | Self.InsertControl(edit_new);
|
---|
178 | end;
|
---|
179 |
|
---|
180 | procedure TForm_ValueEdit.btn_cancelClick(Sender: TObject);
|
---|
181 | begin
|
---|
182 | Form_Main.Enabled := True;
|
---|
183 | Self.Visible := False;
|
---|
184 | end;
|
---|
185 |
|
---|
186 | end.
|
---|