Autor Beitrag
spezidekor
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 25

Win XP
D7
BeitragVerfasst: Sa 01.05.04 18:27 
hallo alle zusammen,

nicht lange drumrum reden. ich habe nicht viel erfahrung mit delphi und deswegen folgendes kleines problem. ich hab ein programm geschrieben (schreiben müssen), welches seine ergebnisse in einer console ausgibt. es wäre mir aber lieber die ergebnisse würden im formular erscheinen. am besten scheint mir dazu 'memo' geeignet. ich habe aber keine ahnung wie ich das programm dazu bringe. kann mir da mal jemand helfen?

im folgenden der quellcode. das programm sortiert eine liste von artikel nach ihrem warenwert und gibt dann all jene artikel aus welche nur noch 30% und weniger über ihrem Minimalbestand liegen.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Beenden(Sender: TObject);
    procedure Anzeigen(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

type
  data=record
    artnr:string[8];     {artikelnummer}
    artbez:string[30];   {artikelbezeichnung}
    menge:string[2];     {mengeneinheit}
    best:smallint;       {bestand}
    bestmax:smallint;    {maximalbestand}
    bestmin:smallint;    {minimalbestand}
    herst:string[41];    {hersteller}
    preis:single;        {stückpreis}
    preismax:single;     {maximalpreis}
    preismin:single;     {minimalpreis}
    lzeit:byte;          {lieferzeit}
end;

var
  Form1: TForm1;
  f:file of data;
  x,max:integer;
  artikel:array[1..50] of data;
  bw:array[1..50] of single;

implementation

{$R *.dfm}

procedure open_file;
begin
  x:=0;
  assignfile(f,'artikel.dat');
  reset(f);
  while not eof(f) do
    begin
      x:=x+1;
      read(f,artikel[x]);
    end;
  closefile(f);
  max:=x;
end;

procedure sort_artikel;
var i,x:integer;
    help:data;
begin
  for i:=1 to max do
    begin
      for x:=1 to max-1 do
        begin
          bw[x]:=artikel[x].preis*artikel[x].best;          {vergleicht den wert eines artikels}
          bw[x+1]:=artikel[x+1].preis*artikel[x+1].best;    {mit dem wert des darauffolgenden artikel}
          if bw[x]<bw[x+1] then
            begin
              help:=artikel[x];              {übergabe von var 1 an help}
              artikel[x]:=artikel[x+1];      {übergabe von var 2 an var 1}
              artikel[x+1]:=help;            {übergabe von help an var 2}
            end;
        end;
    end;
end;

procedure TForm1.Anzeigen(Sender: TObject);
{$apptype console}
var anz:integer;
begin
  anz:=0;
  for x:=1 to max do
    begin
      if artikel[x].best>=(0.3*artikel[x].bestmin+artikel[x].bestmin) then
        begin
          bw[x]:=artikel[x].preis*artikel[x].best;
          write(artikel[x].artnr,' | ');                     {ausgabe der artikelnummer,}
          write(artikel[x].artbez,' | ');                    {der artikelbezeichnung}
          writeln(bw[x]:8:2,' EUR');                         {und des jeweiligen wertes}
          anz:=anz+1;                                        {zählt die anzahl der zu bestellenden artikel}
        end;
    end;
  writeln;
  write('Es muessen ',anz,' Artikel bestellt werden!');
end;

procedure TForm1.Beenden(Sender: TObject);
begin
  close
end;

begin
  open_file;
  sort_artikel;

end.
:shock:

Moderiert von user profile iconMotzi: Code- durch Delphi-Tags ersetzt.


Zuletzt bearbeitet von spezidekor am Fr 07.05.04 08:37, insgesamt 1-mal bearbeitet
spezidekor Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 25

Win XP
D7
BeitragVerfasst: Sa 01.05.04 18:55 
kann mir denn gar keiner helfen???
aM0xACiLLiN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Sa 01.05.04 19:19 
Hi,

statt dem WriteLn einfach Memo1.Lines.Add benutzen. Write gibts nur indirekt, mittels Memo1.Text:=Memo1.Text+'bla', du solltest eher einen string benutzen, in dem du alles zusammenfügst was du brauchst und diesen dann mit Memo1.lines.add hinzufügen.

cu
spezidekor Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 25

Win XP
D7
BeitragVerfasst: Sa 01.05.04 21:53 
danke ich probiers gleich mal aus...
du hast recht. ich muss alles zusammenfassen, sonst bekommt er probleme mit den verschiedenen datentypen. na das werd ich hinbekommen...
spezidekor Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 25

Win XP
D7
BeitragVerfasst: Fr 07.05.04 07:25 
wie wandle ich den wert bw[x] in einen brauchbaren string um? wenn ich einfach nur str(bw[x],s); benutze kommen dabei völlig unbrauchbare strings (z.Bsp.: 4.98273645683984+005 statt: 498273.64) heraus. was muss ich also tun?
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Fr 07.05.04 07:28 
Hallo,


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var s:String;
...
...
s:=FormatFloat('#0.00', bw[x]);
...
...

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
spezidekor Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 25

Win XP
D7
BeitragVerfasst: Fr 07.05.04 07:33 
danke. leider scheint mir das nicht weiterzuhelfen, da ich im moment in meiner FH sitze und hier läuft maximal Delphi3. das scheint den befehl nicht zu kennen. gibt es noch eine möglichkeit?

edit: halt er kennt ihn doch. dennoch bekomme ich jetzt jede menge fehlermeldungen. aber ich versuch das in den griff zu bekommen.
spezidekor Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 25

Win XP
D7
BeitragVerfasst: Fr 07.05.04 08:37 
das problem wurde gelöst. habe einfach str(bw[x]:10:2,s); benutzt und das ganze am ende auch nicht in einer memo sondern einer listbox ausgegeben. das programm funktioniert jetzt tadellos... danke an alle helfer.