Показать сообщение отдельно
  #3  
Старый 25.01.2010, 22:48
inferno mf inferno mf вне форума
Прохожий
 
Регистрация: 13.09.2009
Сообщения: 19
Репутация: 10
По умолчанию

Цитата:
Сообщение от Страдалецъ
Настораживает меня в вашем примере:
Код:
Ch:=StringGrid1.Cells[0,i][1];
T.mszn[ch]:=StrToFloat(StringGrid1.Cells[1,i]);
У вас точно можно Char как индекс массива передавать?

Ну по идее да, вот 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.




Ответить с цитированием