Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > [ "Начинающим" ]
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 30.04.2018, 12:19
Bosa Bosa вне форума
Прохожий
 
Регистрация: 30.04.2018
Сообщения: 5
Версия Delphi: Delphi 7
Репутация: 10
По умолчанию Ошибка EAccess Violation при удалении элементов

Здравствуйте!
Никак не могу понять почему вываливается ошибка доступа к памяти. Пользователь динамически создаёт список запрещённых частот, при удалении уже созданной из списка появляется ошибка. Частоты хранятся в динамическом массиве freq_array.
Помогите пожалуйста!
Код:
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
unit Unit2;
 
interface
 
uses
  Unit1, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;
 
type
  TForm2 = class(TForm)
    Timer1: TTimer;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Edit1: TEdit;
    Label3: TLabel;
    GroupBox3: TGroupBox;
    Button3: TButton;
    Button1: TButton;
    Button4: TButton;
 
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Timer1Timer(Sender: TObject);
    procedure ShowList;
    procedure ListButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
 
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form2: TForm2;
  lab_empty: TLabel;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.ListButtonClick(Sender: TObject);
  var l_array, Index : integer;
 
begin
  Index:= StrToInt(TComponent(Sender).Name[Length(TComponent(Sender).Name)])-1;
  l_array:= Length(freq_array);
  {$HINTS OFF} Finalize(freq_array[Index]); {$HINTS ON}
  if (l_array = 1) then
  begin
    SetLength(freq_array, 0);
  end
  else
  begin
    freq_array[Index]:= freq_array[l_array-1];
    SetLength(freq_array, l_array-1);
  end;
  ShowList;
end;
 
 
procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
  var
  a: Extended;
  i, k: Integer;
  freq_povtor: Boolean;
  s, h: String;
 
begin
  if not (Key in ['0'..'9', #8, #13, '.', ',']) then Key:=#0
  else
  if (Key = '.') then Key:=','
  else
  if (Key = #13) then
  begin
    h:= Edit1.Text;
    if (Length(h)>10) then
      begin
        Label1.Font.Size:=12;
        Label1.Font.Color:=clRed;
        Label1.Top:= 36;
        Label1.Height:= 24;
        Label1.Caption:= 'Некорректное значение!';
        Edit1.Clear;
        Timer1.Enabled:=True;
      end
    else
    begin
      s:= '';
      for i:=1 To Length(h) Do
      begin
        if (h[i]='.') then s:=s+','
        else s:=s+h[i];
      end;
      if TryStrToFloat(s,a) then
        begin
          if (a<149) Or (a>150) And (a<173) Or (a>174) then
            begin
              Label1.Font.Size:=12;
              Label1.Font.Color:=clRed;
              Label1.Top:= 36;
              Label1.Height:= 24;
              Label1.Caption:= 'Неправильный диапазон!';
              Edit1.Clear;
              Timer1.Enabled:=True;
            end
          else
            begin
              freq_povtor:=False;
              for k:=0 to length(freq_array)-1 do
              begin
                if (freq_array[k] = a) then freq_povtor:=True;
              end;
              if (freq_povtor=True) then
                begin
                  Label1.Font.Size:=12;
                  Label1.Font.Color:=clRed;
                  Label1.Top:= 36;
                  Label1.Height:= 24;
                  Label1.Caption:= 'Частота уже есть в списке!';
                  Edit1.Clear;
                  Timer1.Enabled:=True;
                end
              else
                begin
                  Label1.Font.Size:=12;
                  Label1.Font.Color:=clGreen;
                  Label1.Top:= 36;
                  Label1.Height:= 24;
                  Label1.Caption:= 'Ввод успешен!';
                  SetLength(freq_array,length(freq_array)+1);
                  freq_array[length(freq_array)-1]:= a;
                  ShowList;
                  Edit1.Clear;
                  Timer1.Enabled:=True;
                end
            end
        end
      else
      begin
        Label1.Font.Size:=12;
        Label1.Font.Color:=clRed;
        Label1.Top:= 36;
        Label1.Height:= 24;
        Label1.Caption:= 'Некорректное значение!';
        Edit1.Clear;
        Timer1.Enabled:=True;
      end;
    end;
  end;
end;
 
 
procedure TForm2.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled:=False;
  Label1.Font.Size:=10;
  Label1.Font.Color:=clBlack;
  Label1.Top:= 29;
  Label1.Height:= 36;
  Label1.Caption:= 'Введите частоту в МГц в диапазоне 149...150 МГц или 173...174 МГц и нажмите клавишу "Enter"';
end;
 
procedure TForm2.ShowList;
var
  m, t: integer;
  lab_empty, lab_freq, lab_ce, lab_msg: TLabel;
  edit_freq: TEdit;
  but_freq: TButton;
 
begin
  //Form1.Label3.Caption:= IntToStr(Length(list_array));
  for t:= Form2.ComponentCount-1 downto 0 do
  begin
    if (Form2.Components[t].GetParentComponent=GroupBox1) then
       Form2.Components[t].Free;
  end;
 
  if (Length(freq_array)=0) then
    begin
      lab_empty:= TLabel.Create(Form2);
      lab_empty.Parent:= Form2.GroupBox1;
      lab_empty.Top:= 72;
      lab_empty.Left:= 216;
      lab_empty.Width:= 85;
      lab_empty.Height:= 19;
      lab_empty.Font.Color:= clMaroon;
      lab_empty.Font.Size:= 12;
      lab_empty.Font.Name:= 'Calibri';
      lab_empty.Caption:= 'Список пуст';
      Form2.GroupBox1.Height:= 110;
    end
  else
  begin
    Form2.GroupBox1.Height:= 110 + 35*(length(freq_array)-1);
    for m:=0 to length(freq_array)-1 do
    begin
      lab_freq:= TLabel.Create(Form2);
      lab_freq.Parent:= Form2.GroupBox1;
      lab_freq.Top:= 73+m*35;
      lab_freq.Left:= 17;
      lab_freq.Width:= 36;
      lab_freq.Alignment:= taRightJustify;
      lab_freq.Font.Color:= clBlack;
      lab_freq.Caption:= 'f'+IntToStr(m+1)+' =';
      lab_freq.Name:='el_list1_'+ IntToStr(m+1);
 
      edit_freq:= TEdit.Create(Form2);
      edit_freq.Parent:= Form2.GroupBox1;
      edit_freq.Top:= 70+m*35;
      edit_freq.Left:= 59;
      edit_freq.Width:= 83;
      edit_freq.Font.Color:= clBlack;
      edit_freq.MaxLength:= 10;
      edit_freq.Text:= FloatToStr(freq_array[m]);
      edit_freq.Name:='el_list2_'+ IntToStr(m+1);
 
      lab_ce:= TLabel.Create(Form2);
      lab_ce.Parent:= Form2.GroupBox1;
      lab_ce.Top:= 73+m*35;
      lab_ce.Left:= 144;
      lab_ce.Font.Color:= clBlack;
      lab_ce.Caption:= 'МГц';
      lab_ce.Name:='el_list3_'+ IntToStr(m+1);
 
      but_freq:= TButton.Create(Form2);
      but_freq.Parent:= Form2.GroupBox1;
      but_freq.Top:= 70+m*35;
      but_freq.Left:= 190;
      but_freq.Width:= 135;
      but_freq.Font.Color:= clBlack;
      but_freq.Font.Size:= 8;
      but_freq.Font.Name:= 'MS Sans Serif';
      but_freq.Font.Style:= [fsBold];
      but_freq.Caption:= 'Удалить из списка';
      but_freq.Name:='el_list4_'+ IntToStr(m+1);
      but_freq.onClick:=ListButtonClick;
 
      lab_msg:= TLabel.Create(Form2);
      lab_msg.Parent:= Form2.GroupBox1;
      lab_msg.Top:= 75+m*35;
      lab_msg.Left:= 340;
      lab_msg.Alignment:= taLeftJustify;
      lab_msg.Font.Color:= clBlack;
      lab_msg.Font.Size:= 10;
      lab_msg.Font.Name:= 'Calibri';
      lab_msg.Name:='el_list5_'+ IntToStr(m+1);
      lab_msg.Caption:=IntToStr(m);
    end;
  end;
end;
 
 
procedure TForm2.FormCreate(Sender: TObject);
begin
  ShowList;
end;
 
end.
Ответить с цитированием
 


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 00:53.


 

Сайт

Форум

FAQ

Соглашения

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2025