Answer the question
In order to leave comments, you need to log in
I can't fix the exception. Don't know what's the problem?
the point is. that I write the text in "Richedit" and calculate the probability of dropping out the character of each letter, a bit of shit code - I'm sorry.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
RichEdit1: TRichEdit;
Label2: TLabel;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure teory(str:string);
var
Form1: TForm1;
// labels:array of Tlabel;
length_text,meter: integer;
mas:array[0..31] of integer;
mas_simvol:array[0..31] of string;
next_mas_simvol:array of string;
next_mas:array of real;
meter2 : real;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var m: string;
j,i,s,meter1:integer;
big_text:array of string;
imov:real;
begin
mas_simvol[0]:='а';//заполняю массив вручную алфавита
mas_simvol[1]:='б';
mas_simvol[2]:='в';
mas_simvol[3]:='г';
mas_simvol[4]:='д';
mas_simvol[5]:='е';
mas_simvol[6]:='є';
mas_simvol[7]:='ж';
mas_simvol[8]:='з';
mas_simvol[9]:='и';
mas_simvol[10]:='і';
mas_simvol[11]:='ї';
mas_simvol[12]:='й';
mas_simvol[13]:='к';
mas_simvol[14]:='л';
mas_simvol[15]:='м';
mas_simvol[16]:='н';
mas_simvol[17]:='о';
mas_simvol[18]:='п';
mas_simvol[19]:='р';
mas_simvol[20]:='с';
mas_simvol[21]:='т';
mas_simvol[22]:='у';
mas_simvol[23]:='ф';
mas_simvol[24]:='х';
mas_simvol[25]:='ч';
mas_simvol[26]:='ц';
mas_simvol[27]:='ш';
mas_simvol[28]:='щ';
mas_simvol[29]:='ь';
mas_simvol[30]:='ю';
mas_simvol[31]:='я';
meter:=0;
label2.Caption:='';
for i := 0 to 31 do
begin
mas[i]:= 0;//заполняю массив что будет потом считать количество той или иной буквы в тексте
end;
m:=RichEdit1.Text;
length_text:=Length(RichEdit1.Text);
SetLength(big_text,length_text);//задаю массиву big_text его ширину
for i := 0 to length_text-1 do
begin
big_text[i]:= Copy(m,i+1,1);
teory(big_text[i]);
end;//счётчик массива mas - определяет количество той или иной буквы
for i := 0 to 31 do
begin
if mas[i]>0 then
begin
meter:= meter+1;//подсчитываю количество букв которые были в тексте отбрасывая ненужные
end;
end;
meter1:=0;
SetLength(next_mas,meter);
SetLength(next_mas_simvol,meter);
for i := 0 to 31 do
begin
if mas[i]>0 then
begin
imov:= mas[i]/length_text;
next_mas[meter1]:=imov;//заполняю вероятность попадания в массив
next_mas_simvol[meter1]:=mas_simvol[i];
meter1:=meter1+1;
end;
end;
for i := 0 to meter-1 do
begin
for j := 0 to meter-1 do
begin
if next_mas[j]>next_mas[j+1] then
begin
meter2:=next_mas[j+1];
next_mas[j+1]:=next_mas[j];
next_mas[j]:=meter2;
end;
end;
end;// выстраиваем по убыванию
for i := 1 to meter do
begin
label2.Caption:=label2.Caption+' '+next_mas_simvol[i]+': '+inttostr(Round(next_mas[i]*1000))+' ';
end;
end;
procedure teory(str:string);
begin
if str='а' then mas[0]:=mas[0]+1;
if str='б' then mas[1]:=mas[1]+1;
if str='в' then mas[2]:=mas[2]+1;
if str='г' then mas[3]:=mas[3]+1;
if str='д' then mas[4]:=mas[4]+1;
if str='е' then mas[5]:=mas[5]+1;
if str='є' then mas[6]:=mas[6]+1;
if str='ж' then mas[7]:=mas[7]+1;
if str='з' then mas[8]:=mas[8]+1;
if str='и' then mas[9]:=mas[9]+1;
if str='і' then mas[10]:=mas[10]+1;
if str='ї' then mas[11]:=mas[11]+1;
if str='й' then mas[12]:=mas[12]+1;
if str='к' then mas[13]:=mas[13]+1;
if str='л' then mas[14]:=mas[14]+1;
if str='м' then mas[15]:=mas[15]+1;
if str='н' then mas[16]:=mas[16]+1;
if str='о' then mas[17]:=mas[17]+1;
if str='п' then mas[18]:=mas[18]+1;
if str='р' then mas[19]:=mas[19]+1;
if str='с' then mas[20]:=mas[20]+1;
if str='т' then mas[21]:=mas[21]+1;
if str='у' then mas[22]:=mas[22]+1;
if str='ф' then mas[23]:=mas[23]+1;
if str='х' then mas[24]:=mas[24]+1;
if str='ч' then mas[25]:=mas[25]+1;
if str='ц' then mas[26]:=mas[26]+1;
if str='ш' then mas[27]:=mas[27]+1;
if str='щ' then mas[28]:=mas[28]+1;
if str='ь' then mas[29]:=mas[29]+1;
if str='ю' then mas[30]:=mas[30]+1;
if str='я' then mas[31]:=mas[31]+1;
if str='А' then mas[0]:=mas[0]+1;
if str='Б' then mas[1]:=mas[1]+1;
if str='В' then mas[2]:=mas[2]+1;
if str='Г' then mas[3]:=mas[3]+1;
if str='Д' then mas[4]:=mas[4]+1;
if str='Е' then mas[5]:=mas[5]+1;
if str='Є' then mas[6]:=mas[6]+1;
if str='Ж' then mas[7]:=mas[7]+1;
if str='З' then mas[8]:=mas[8]+1;
if str='И' then mas[9]:=mas[9]+1;
if str='І' then mas[10]:=mas[10]+1;
if str='Ї' then mas[11]:=mas[11]+1;
if str='Й' then mas[12]:=mas[12]+1;
if str='К' then mas[13]:=mas[13]+1;
if str='Л' then mas[14]:=mas[14]+1;
if str='М' then mas[15]:=mas[15]+1;
if str='Н' then mas[16]:=mas[16]+1;
if str='О' then mas[17]:=mas[17]+1;
if str='П' then mas[18]:=mas[18]+1;
if str='Р' then mas[19]:=mas[19]+1;
if str='С' then mas[20]:=mas[20]+1;
if str='Т' then mas[21]:=mas[21]+1;
if str='у' then mas[22]:=mas[22]+1;
if str='ф' then mas[23]:=mas[23]+1;
if str='Х' then mas[24]:=mas[24]+1;
if str='Ч' then mas[25]:=mas[25]+1;
if str='Ц' then mas[26]:=mas[26]+1;
if str='Ш' then mas[27]:=mas[27]+1;
if str='Щ' then mas[28]:=mas[28]+1;
if str='Ь' then mas[29]:=mas[29]+1;
if str='Ю' then mas[30]:=mas[30]+1;
if str='Я' then mas[31]:=mas[31]+1;
end;
end.
Answer the question
In order to leave comments, you need to log in
I’m not a hatched larva of a programmer at all
, but the first thing that catches your eye
big_text:array of string;
SetLength(big_text,length_text);//
error code: pp.vk.me/c626826/v626826590/d508/wK4twsJynso.jpg
I can’t (or just don’t know how) indicate where in the code the place of the error is sent to some system file ...
try finaly - didn’t break through. but I'll try
Turn on the compiler option:
Project - Options - Delphi Compiler - Compiling - Runtime Errors - Range checking = true
And then the debugger will definitely show you the line with the error:
if next_mas[j]>next_mas[j+1] then
You access an array element with index outside the array dimension. At the maximum value of j, the next_mas[j+1] element is already going nowhere.
Then edit your own algorithm.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question