source: oup/releases/0.34b/Helper/ValueEdit.pas@ 1193

Last change on this file since 1193 was 205, checked in by alloc, 18 years ago
File size: 4.5 KB
Line 
1unit ValueEdit;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, CrossEdit, Math;
6
7type
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
29var
30 Form_ValueEdit: TForm_ValueEdit;
31
32
33implementation
34
35uses BinEdit, RawEdit, DatStructureLoader, Main;
36
37{$R *.dfm}
38
39var
40 caller_win_dat: TForm_BinEdit;
41 caller_win_raw: TForm_RawEdit;
42 _datatype: Word;
43 _offset: Integer;
44
45
46
47
48procedure TForm_ValueEdit.MakeVarInput(objectname: String; offset: Integer;
49 datatype: Word; current: String; caller: TObject);
50begin
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.MaxLength := 0;
70 edit_new.Max := 0;
71 edit_new.BorderStyle := bsSingle;
72 Self.Width := 300;
73 case datatype of
74 1..4:
75 begin
76 edit_new.EditType := etUnsignedInt;
77 edit_new.LimitCheck := True;
78 edit_new.Max := Int(Power(256, datatype)) - 1;
79 end;
80 5..8:
81 begin
82 edit_new.MaxLength := 2 * (datatype - 4);
83 edit_new.EditType := etHex;
84 end;
85 9:
86 begin
87 edit_new.EditType := etFloat;
88 edit_new.LimitCheck := False;
89 end;
90 10:
91 begin
92 edit_new.EditType := etBinary;
93 edit_new.LimitCheck := False;
94 edit_new.MaxLength := 8;
95 end;
96 13..16:
97 begin
98 Exit;
99 edit_new.EditType := etInteger;
100 edit_new.LimitCheck := True;
101 edit_new.Max := Int((Power(256, datatype - 13)) / 2) - 1;
102 edit_new.Min := 1 - Int((Power(256, datatype - 13)) / 2) - 1;
103 end;
104 10000..65535:
105 begin
106 edit_new.EditType := etString;
107 edit_new.LimitCheck := False;
108 edit_new.MaxLength := datatype - 10000;
109 Self.Width := 700;
110 end;
111 end;
112 edit_new.Text := current;
113 edit_new.SetFocus;
114 edit_new.SelectAll;
115end;
116
117
118
119
120procedure TForm_ValueEdit.btn_okClick(Sender: TObject);
121begin
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;
131end;
132
133
134
135
136procedure TForm_ValueEdit.FormCreate(Sender: TObject);
137begin
138 DecimalSeparator := '.';
139 edit_new := TCrossEdit.Create(Self);
140 with edit_new do
141 begin
142 Left := 88;
143 Top := 88;
144 Width := 203;
145 Height := 18;
146 Anchors := [akLeft, akTop, akRight];
147 AutoSize := False;
148 BorderStyle := bsNone;
149 Color := clWhite;
150 Font.Charset := DEFAULT_CHARSET;
151 Font.Color := clWindowText;
152 Font.Height := -11;
153 Font.Name := 'Tahoma';
154 Font.Style := [];
155 HideSelection := False;
156 ParentFont := False;
157 TabOrder := 5;
158 Text := '0000';
159 FocusAlignment := taLeftJustify;
160 NoFocusAlignment := taLeftJustify;
161 Precision := 15;
162 Decimals := 14;
163 FocusWidthInc := 0;
164 EditType := etHex;
165 NextDialogOnEnter := True;
166 DialogOnCursorKeys := True;
167 NextPriorStep := 1;
168 AutoFocus := False;
169 LimitCheck := True;
170 Max := 2147483647.000000000000000000;
171 FocusColor := clWhite;
172 NoFocusColor := clWhite;
173 ErrorColor := clRed;
174 StringCharSet := scFull;
175 end;
176 Self.InsertControl(edit_new);
177end;
178
179procedure TForm_ValueEdit.btn_cancelClick(Sender: TObject);
180begin
181 Form_Main.Enabled := True;
182 Self.Visible := False;
183end;
184
185end.
Note: See TracBrowser for help on using the repository browser.