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