Autor Beitrag
Nightfly
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Mo 27.10.03 12:45 
Hier mal der Beginn meiner Prozedur:
ausblenden volle Höhe 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:
Procedure TKosten.Berechne;
Var
loop,asum,maxRec,key,m1,m2,mloop : Integer;
matrix          : T13x13;
Begin
for m1 := 1 to 15 do
    begin
      for m2 := 1 to 12 do
        begin
        matrix[m1,m2] := 0;
        end;
    end;
key := Table2Key.Value;
Table2.FindFirst;
maxRec := Table2.RecordCount;
for loop := 0 to maxRec do
    begin
      case Table2Key.Value of
      1..9:     for mloop := 1 to 12 do matrix[1,mloop] := Table2.Fields[mloop+5].asInteger + matrix[1,mloop];
      101..149: for mloop := 1 to 12 do matrix[2,mloop] := Table2.Fields[mloop+5].asInteger + matrix[2,mloop];
      201..499: for mloop := 1 to 12 do matrix[4,mloop] := Table2.Fields[mloop+5].asInteger + matrix[4,mloop];
      601..699: for mloop := 1 to 12 do matrix[6,mloop] := Table2.Fields[mloop+5].asInteger + matrix[6,mloop];
      801..899: for mloop := 1 to 12 do matrix[8,mloop] := Table2.Fields[mloop+5].asInteger + matrix[8,mloop];
      end;
      Table2.Edit;
      Table2Summe.Value := 0;
      for mloop := 1 to 12 do Table2Summe.Value := Table2.Fields[mloop+5].asInteger + Table2Summe.Value;
     Table2.FindNext;
    end;                                     
 Table2.FindKey([0]);
   Table2.Edit;
   Table2Summe.Value := 0;
   for mloop := 1 to 12 do Table2.Fields[mloop+5].asInteger := matrix[1,mloop];    
   for asum := 1 to 12 do  Table2Summe.Value := Table2Summe.Value + matrix[1,asum]; 
 Table2.FindKey([100]);
   Table2.Edit;
   Table2Summe.Value := 0;
   for mloop := 1 to 12 do Table2.Fields[mloop+5].asInteger := matrix[2,mloop];
   for asum := 1 to 12 do  Table2Summe.Value := Table2Summe.Value + matrix[2,asum];
 Table2.FindKey([200]);


Ja, ich bin noch anfänger :roll:
Mein Problem ist nun Folgendes: ich würde die Prozedur gern öfter verwenden. Allerdings nicht nur für TAble2, sondern auch für andere Tabellen. Mit ist da etwas mit with ... do in erinnerung. Aber davon hab ich keine ahnung,könnte ir das nochmal jemand erklären?
Wie mach ich diese Prozedur am besten variabel?
joerg68
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 116

Win 2000
D5Enterprise
BeitragVerfasst: Mo 27.10.03 12:52 
Übergib der Prozedur doch einfach eine Tabelle

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
Procedure TKosten.Berechne (Tabelle : TTable);
...

Tabelle.FindFirst

...


Gruß
Jörg

_________________
Aus den Chaos sprach eine Stimme " Lächele und sei froh denn es könnte schlimmer kommen". Und ich lächelte und ich war froh.
UND ES KAM SCHLIMMER
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mo 27.10.03 12:57 
Hi,

dafür gibt es prozedur-parameter:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Procedure TKosten.Berechne(table:TTable?? ;tableKey:TTableKey??); // <-- paramter
Var 
loop,asum,maxRec,key,m1,m2,mloop : Integer; 
matrix          : T13x13; 
Begin 
for m1 := 1 to 15 do 
    begin 
      for m2 := 1 to 12 do 
        begin 
        matrix[m1,m2] := 0
        end
    end
key := tableKey.Value; 
table.FindFirst; 
maxRec := table.RecordCount; 
for loop := 0 to maxRec do 
    begin 
      case tableKey.Value of 
....


du übergibst dann einfach verschiedene tables etc. in verschiedenen aufrufen :wink:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
...
Berechne(Table2,Table2Key);
...
Berechne(Table233,Table233Key);


cu,

_________________
mfg.
mâximôv
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mo 27.10.03 12:57 
Hi,

du könntest die Tabellen als Parameter der Prozedur übergeben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TKosten.Berechne(Tabelle: TTable); 
begin
  with Tabelle do
  begin
    // ......................

  end;
end;


Deine Code-Formatierung ist übrigens auch nicht Object Pascal Style Guide Konform.

MFG

- Ernesto -

// Edit: mal wieder zu langsam :lol:
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mo 27.10.03 12:59 
*lol* dreifach hält besser...

_________________
mfg.
mâximôv
joerg68
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 116

Win 2000
D5Enterprise
BeitragVerfasst: Mo 27.10.03 15:58 
Na wenigsten waren wir mal alle einer Meinung :D

Gruß
Jörg

_________________
Aus den Chaos sprach eine Stimme " Lächele und sei froh denn es könnte schlimmer kommen". Und ich lächelte und ich war froh.
UND ES KAM SCHLIMMER