AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

StringGrid ausrechnen??

Ein Thema von MondoShiva · begonnen am 16. Aug 2007 · letzter Beitrag vom 23. Aug 2007
Antwort Antwort
MondoShiva

Registriert seit: 14. Aug 2007
Ort: Mönchengladbach
63 Beiträge
 
Delphi XE2 Professional
 
#1

StringGrid ausrechnen??

  Alt 16. Aug 2007, 10:06
Ich versuche seit einigerzeit einen stringgrid auszurechnen, jedoch stellt sich mir delphi als eine unüberwindbare wand dar und lässt mich leiden!hier soweit ich bin nur das ausrechnen der zellen geht nicht

beispiels weise steht in der aritmatik:

minus #9 12 #9 23
usw.
(#9 tab)

Delphi-Quellcode:
type
  TForm1 = class(TForm)
    Panel: TPanel;
    Open: TButton;
    save: TButton;
    calculate: TButton;
    StringGrid: TStringGrid;
    OpenDialog: TOpenDialog;
    SaveDialog: TSaveDialog;
    Transport: TButton;
    procedure OpenClick(Sender: TObject);
    procedure TransportClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.OpenClick(Sender: TObject);
begin
    opendialog.Execute;
// RichEdit.Lines.LoadFromFile(opendialog.FileName);
// opendialog.Execute;
// richedit.linies.
// stringGrid.Cells[1,1] := 'fdggjkfdgjkg';//.LoadFromFile(opendialog.FileName);

end;

procedure TForm1.TransportClick(Sender: TObject);
var
  f: textfile;
  Spalte1,spalte2: String;
  i, count: Integer;
  delimiter: char;
  mylist : tstringlist;

begin
  opendialog.Execute;
  mylist := TStringList.Create;
  mylist.LoadFromFile(Opendialog.FileName);
  mylist.Delimiter := #9;
  mylist.DelimitedText := mylist.Text;
  count := 0;
  i:=0;


// if then ;


  while count < mylist.Count do
  begin
     stringgrid.Cells[1,i+1] := mylist.Strings[count];
     stringgrid.Cells[2,i+1] := mylist.Strings[count+1];
     stringgrid.Cells[3,i+1] := mylist.Strings[count+2];
     count := count + 3;
     inc(i);
  end;


end;

end.
kann mir einer helfen das problem zu bewältigen?
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: StringGrid ausrechnen??

  Alt 16. Aug 2007, 10:11
Ein StringGrid heißt so, weil in ihm Strings (Text) stehen.
Markus Kinzler
  Mit Zitat antworten Zitat
MondoShiva

Registriert seit: 14. Aug 2007
Ort: Mönchengladbach
63 Beiträge
 
Delphi XE2 Professional
 
#3

Re: StringGrid ausrechnen??

  Alt 23. Aug 2007, 10:13
wollte nur einmal posten wie es nun aussieht! porblem gelöst

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls, Grids;

type
  TForm1 = class(TForm)
    Panel: TPanel;
    Open: TButton;
    save: TButton;
    calculate: TButton;
    StringGrid: TStringGrid;
    OpenDialog: TOpenDialog;
    SaveDialog: TSaveDialog;
    Transport: TButton;
    Button: TButton;
    procedure OpenClick(Sender: TObject);
    procedure TransportClick(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
    procedure StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormShow(Sender: TObject);
  private
    ergebnis: real;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.OpenClick(Sender: TObject);
begin
    opendialog.Execute;
// RichEdit.Lines.LoadFromFile(opendialog.FileName);
// opendialog.Execute;
// richedit.linies.
// stringGrid.Cells[1,1] := 'fdggjkfdgjkg';//.LoadFromFile(opendialog.FileName);

end;

procedure TForm1.TransportClick(Sender: TObject);
var
  f: textfile;
  Spalte1,spalte2: String;
  i, count: Integer;
  delimiter: char;
  mylist : tstringlist;
begin
  opendialog.Execute;
  mylist := TStringList.Create;
  mylist.LoadFromFile(Opendialog.FileName);
  mylist.Delimiter := #9;
  mylist.DelimitedText := mylist.Text;
  count := 0;
  i:=0;

// if mylist.Strings[count] = 'minus' then ;
// mylist.strings[count+3]:= inttostr(strtoint(mylist.Strings[count+1])-strtoint(mylist.Strings[count+2]));
  ergebnis:=0;

  while count < mylist.Count do
  begin
     stringgrid.Cells[1,i+1] := mylist.Strings[count];
     stringgrid.Cells[2,i+1] := mylist.Strings[count+1];
     stringgrid.Cells[3,i+1] := mylist.Strings[count+2];
     if mylist.Strings[count] = 'minusthen
        stringgrid.Cells[4,i+1] := inttostr(strtoint(mylist.Strings[count+1]) - strtoint(mylist.Strings[count+2]));
     if mylist.Strings[count] = 'summethen
        stringgrid.Cells[4,i+1] := inttostr(strtoint(mylist.Strings[count+1]) + strtoint(mylist.Strings[count+2]));
     if mylist.Strings[count] = 'malthen
        stringgrid.Cells[4,i+1] := inttostr(strtoint(mylist.Strings[count+1]) * strtoint(mylist.Strings[count+2]));
     if mylist.Strings[count] = 'teilenthen
        stringgrid.Cells[4,i+1] := floattostr(strtoint(mylist.Strings[count+1]) / strtoint(mylist.Strings[count+2]));
     ergebnis:= ergebnis + strtofloat(stringgrid.Cells[4,i+1]);
     count := count + 3;
     inc(i);
        //stringgrid.Cells[5, 13] := floattostr(strtoint(mylist.Strings[count+1]) + strtoint(mylist.Strings[count+2]));
  end;

end;

procedure TForm1.ButtonClick(Sender: TObject);
begin
  stringgrid.Cells[4,14] := floattostr(ergebnis);
  Stringgrid.Cells[4,13] := 'Ergebnis';
end;

procedure TForm1.StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  keineahnung: integer;
begin
   if (ACol=4) and (StringGrid.Cells[ACol,ARow] <> '') then
   begin
     StringGrid.Canvas.Brush.Color := clYellow;
     if (ACol=4) and ((ARow = 13) or (ARow = 14)) then
       StringGrid.Canvas.Brush.Color := clRed;
   end;
   if (Stringgrid.Cells[acol,arow] <> '') and (TryStrToInt(StringGrid.Cells[ACol,ARow],keineahnung)) then
   begin
     if not (ACol=4) then
     begin
       if strtoint(Stringgrid.Cells[acol,arow]) <20 then
          StringGrid.Canvas.Brush.Color := clGreen;
       if strtoint(Stringgrid.Cells[acol,arow]) >20 then
          StringGrid.Canvas.Brush.Color := clBlue;
       if strtoint(Stringgrid.Cells[acol,arow]) <10 then
          StringGrid.Canvas.Brush.Color := clPurple;
     end;
// if StrToBool(Stringgrid.Cells[acol,arow])=(StringGrid.Cells[ACol,ARow] <> '') then
// StringGrid.Canvas.Brush.Color := clYellow;
   end;
   if (ACol > 0) and (ARow > 0) then
   begin
      StringGrid.Canvas.FillRect(Rect);
      StringGrid.Canvas.TextOut(Rect.Left, Rect.Top, StringGrid.Cells[ACol,ARow]);
   end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
// StringGrid.Cells[4,10] := 'text';
end;

end.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:50 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz