![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
![]() Помогите разобраться с ошибкой. Писал программу для вычисления арифметического выражения...
При попытке высчитать выражение появляется такая ошибка - access violation at address 004514D8 in module 'Project1.exe' . Read of adress 000000 Вот основной модуль Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,Unit2, StdCtrls, Grids; type TForm1 = class(TForm) StringGrid1: TStringGrid; Edit1: TEdit; Edit2: TEdit; Button1: TButton; Button2: TButton; Edit3: TEdit; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; n:byte; T:Tpz; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin StringGrid1.Cells[0,0]:='Операнд'; StringGrid1.Cells[1,0]:='Значение'; Edit1.Clear; Edit2.Clear; end; procedure TForm1.Button1Click(Sender: TObject); var i:byte; Ch:char; strp:string; m:extended; begin t:=tpz.create; with t do begin n:=strtoint(edit3.text); strp:=Edit1.Text; for i:=1 to n do begin Ch:=StringGrid1.Cells[0,i][1]; T.mszn[ch]:=StrToFloat(StringGrid1.Cells[1,i]); end; m:=T.AV(strp); Edit2.Text:=FloatToStr(m); end; end; procedure TForm1.Button2Click(Sender: TObject); var ch:char; i:integer; begin N:=strtoint(Edit3.text); stringgrid1.rowcount:=N+1; ch:='a'; for i:=1 to n do begin stringgrid1.cells[1,i]:=inttostr(random(10)+1); stringgrid1.cells[0,i]:=ch; inc(ch); end; end; end. |
#2
|
||||
|
||||
![]() Настораживает меня в вашем примере:
Код:
Ch:=StringGrid1.Cells[0,i][1]; T.mszn[ch]:=StrToFloat(StringGrid1.Cells[1,i]); Жизнь такова какова она есть и больше никакова. Помогаю за спасибо. |
#3
|
|||
|
|||
![]() Цитата:
Ну по идее да, вот 2-ой модуль. Код:
unit Unit2; interface Uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,math, StdCtrls; Type Tinf=char; Tsel=^Psel; Psel=Record inf:Tinf; A:Tsel; end; TLists=class(Tobject) sp1,spk,sp:Tsel; constructor create; Procedure Adds(Inf:Tinf); Procedure Reads (Var Inf:Tinf); end; Tmas=array ['a'..'ÿ'] of extended; Tpz=class mszn:Tmas; stec:Tlists; Function AV(strp:string):extended; end; implementation var i:byte; constructor Tlists.Create; begin inherited Create; sp1:=nil; end; Procedure Tlists.Adds; begin New(sp); sp^.inf:=Inf; sp^.A:=sp1; sp1:=sp; end; Procedure TLists.Reads; Begin Inf:=sp1^.Inf; sp:=sp1; sp1:=sp1^.A; Dispose(sp); end; Function Tpz.AV; Var ch,ch1,ch2,chr : char; op1,op2 : extended; begin stec:=Tlists.create; chr:=Succ('z'); for i:=1 to Length(strp) do begin ch:=strp[i]; if not (ch in ['*','/','+','-','^']) then stec.Adds(ch) else begin stec.Reads(ch2); stec.Reads(ch1); op1:=mszn[ch1]; op2:=mszn[ch2]; case ch of '+':Result:=op1+op2; '-':Result:=op1-op2; '*':Result:=op1*op2; '/':Result:=op1/op2; '^':Result:=power(op1,op2); end; mszn[chr]:=Result; stec.Adds(chr); Inc(chr); end; end; stec.Free; end; end. |