Einzelnen Beitrag anzeigen

Mr.XYZ
(Gast)

n/a Beiträge
 
#30

Re: Warum funktioniert ein Code einmal und dann wieder nicht

  Alt 6. Nov 2009, 12:17
okay hier ist der Quellcode kannst ihn ja gleich korrigieren wen du willst.[ist aber noch nicht vertig)
Delphi-Quellcode:
unit Unit2;

interface

uses
  mmsystem, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Buttons;

type

  Tnumer = record
           zahl : string;
           end;
  Toperation = record
               operant : string;
               end;
  Trechnung = record
              numer : array[0..100] of Tnumer;
              operation : array[0..100] of Toperation;
              end;

  TForm2 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    Button1: TButton;
    Label2: TLabel;
    Bevel1: TBevel;
    Edit2: TEdit;
    Label3: TLabel;
    procedure Edit2Change(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Button1Click(Sender: TObject);
    procedure Edit2Enter(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  chint : string;
  vertig : string;
  taste : string;
  pres_un : integer;
  sactiv : string;
  klammer1 : Char;
  i : integer;
  y : integer;
  ch: integer;
  x : integer;

  baum : array[0..100] of integer;
  activ : integer;
  first : boolean;
  input : string;
  save : string;
  vare : Array [0..100] of string;

  Form2: TForm2;


implementation


{$R *.dfm}
procedure TForm2.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
 if (key = VK_DELETE) then
 begin
 Edit1.Text:='clear';
 end;
 if (key = VK_SHIFT) or(key = VK_CONTROL) or (key = VK_DELETE) or (pos('key','q,w,e,r,t,z,u,i,o,p,ü,a,s,d,f,g,h,j,k,l,ö,ä,y,x,c,v,b,n,m')>0) or (key = VK_TAB) or (key = VK_CLEAR) or (key = VK_MENU) then
 begin
 pres_un:=pres_un+1;
 Edit1.Text:=save;
 end else
 begin
 if (first = false) then
  begin
   save:= Edit1.Text;
    first:=true;
   ch:= length(save);

   if (save[ch] = chr(40) ) then
   begin
    baum[y]:=x;
    ch:= length(baum);
    Label2.Caption:= IntToStr(baum[0]);
    first:=true;
    vare[activ]:=vare[activ]+'V'+IntToStr(baum[y]);
    activ:=1;
    for i:= 1 to ch do
      begin
       Label2.Caption:= Label2.Caption+IntToStr(baum[i]);
      end;
   end;
  input:=edit1.Text;
  ch:=length(input);
  klammer1:= chr(41);
  Label2.Caption:=klammer1+' = '+input[ch];
  if ( input[ch] = klammer1 ) then
  begin
   baum[y]:=0;
   baum[0]:=0;
   y:=0;
   baum[y]:=0;
   first:= false;
   application.MessageBox('Felerhafte eingabe!!','Error!!',MB_OK);
   Edit1.text:='';
  end;
  ch:=length(input);
  taste:=IntToStr(key);
  if (taste<>'56') and (taste<>'57') then begin
    first:=true;
    chint:=input[ch];
    if (chint = '+') or (input[ch] = '-') or (input[ch] = '*') then
    begin
    application.MessageBox('Felerhafte eingabe!!','Error!!',MB_OK);
    Edit1.text:='';
    end;
    if(chint = 'k') then
    begin
    Edit1.Text:='';
    first:= false;
    end;
    ch:=length(input);
    input:=edit1.Text;
    vare[activ]:=vare[activ]+input[ch];
    end;

  end else
   begin
   input:=edit1.Text;
   ch:= length(input);

   if (input[ch] = chr(40) ) then
   begin
   //Label2.Caption:='+'+input[ch];
   x:=x+1;
   y:=y+1;
   baum[y]:=x;
   ch:= length(baum);
   vare[activ]:=vare[activ]+'V'+IntToStr(baum[y]);
   activ:= x;
   Label2.Caption:= IntToStr(baum[0]);
    for i:=1 to ch do
     begin
      Label2.Caption:= Label2.Caption+IntToStr(baum[i]);
     end;
   end;
   ch:= length(input);
   if(input[ch] = chr(41) ) then
   begin
   y:= y-1;
   activ:= baum[y];
   if ( y<=0) then
   begin
   application.MessageBox('Felerhafte eingabe!!','Error!!',MB_OK);
   y:= y+1;
    ch:= length(input);
    ch:= ch-1;
    Edit1.text:=copy(input,1,ch);
   end else
   begin
   baum[y]:=0;
   ch:= length(baum);
   Label2.Caption:= IntToStr(baum[0]);
     for i:=1 to ch do
      begin
       Label2.Caption:= Label2.Caption+IntToStr(baum[i]);
      end;
      end;
   end;
    ch:= length(input);
    taste:=IntToStr(key);
  if (taste<>'56') and (taste<>'57') then begin
    first:=true;
    chint:=input[ch];
   // if (chint = '+') or (input[ch] = '-') or (input[ch] = '*') then
// begin
// application.MessageBox('Felerhafte eingabe!!','Error!!',MB_OK);
// Edit1.text:='';
// end;
    if(chint = 'k') then
    begin
    Edit1.Text:='';
    first:= false;
    end;
    ch:=length(input);
    input:=edit1.Text;
    vare[activ]:=vare[activ]+input[ch];
    end;
   end;
end;
vertig:=vare[0]+' '+vare[1]+' '+vare[2]+' '+vare[3]+' '+vare[4];
//Label2.Caption:=vertig+'; Ac='+IntToStr(activ);
Label2.Caption:=taste+' : '+'56 or 57'+' = '+BoolToStr((taste<>'56') and (taste<>'57'));
save:=Edit1.Text;
end;
procedure TForm2.FormShow(Sender: TObject);
begin
x:=0;
y:=1;
Form2.KeyPreview:=true;
end;

procedure TForm2.Edit2Enter(Sender: TObject);
var
prüf : string;
begin
prüf:=Edit2.Text;
if (prüf = 'control') then
begin
Label2.Visible:=true;
end;
end;

procedure TForm2.Button1Click(Sender: TObject);
var
ip : integer;
rechnung : array[0..100] of Trechnung;
num : integer;
y : integer;
i : integer;
j : integer;
t : integer;
eingelesen : string;
begin
  
for i:=0 to 100 do
 begin
 j:=0;
  num:= length(vare[0]);
  while j<num do
  begin
  j:=j+1;
 // eingelesen:=vare[0];
// Label3.Caption:=eingelesen+' : '+IntToStr(j);
  eingelesen:=copy(vare[0],1,j);
  //Label3.Caption:=eingelesen;
  ip:= length(eingelesen);
   if (eingelesen[ip] = '+') and (eingelesen[ip]='-') and (eingelesen[ip]='/') and (eingelesen[ip]='*') then
   begin
   eingelesen:=copy(vare[0],1,j-1);
   rechnung[0].numer[0].zahl:=eingelesen;
   j:=num+1;
   end;
   if (eingelesen[ip] = 'V') then
   begin
   j:=j+1;
   end;
  end;
 end;
Label3.Caption:=eingelesen+' : '+rechnung[0].numer[0].zahl;
end;

procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Ord(Key) = 17 then
  begin
    self.Height:=326;
    Bevel1.Visible:=true;
    Edit2.Visible:=true;
    Form2.ActiveControl:=Edit2;
  end;
end;

procedure TForm2.Edit2Change(Sender: TObject);
var
prüf : string;
begin
prüf:=Edit2.Text;
if (prüf = 'control') then
begin
Label2.Visible:=true;
Label3.Visible:=true;
end;
end;

end.
  Mit Zitat antworten Zitat