Autor Beitrag
SpaghettiCodix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52
Erhaltene Danke: 1

WIN XP
Delphi 2 Standart und Delphi 2005 Pers.
BeitragVerfasst: So 14.10.07 13:54 
Da gibts ein Problem mit der Übergabe eines Dyn. Arrays:
ausblenden 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:
Procedure TForm1.Berechnen_Arrayfuellen(K:array of TKredit;idz:integer);
var
  i, tmp:byte;
   KJahr:word;
begin
KJahr:=KredJahr;
K[1].Jahr:=KredJahr;
K[1].Monat:=KredMonat;
tmp:=KredMonat;
 setlength(K,idz);          <-[Fehler] Raten2.pas(72): E2008 Inkompatible Typen
  For i:=0 to (idz-1) do
  begin
   if i =0 then K[i].bezahlt:=Rate_1 else
   K[i].bezahlt:=K[i-1].bezahlt+Rate;
   K[i].Rate_Nr:=i;
   K[i].Jahr:=KredJahr;
   K[i].Monat:=tmp;
   if tmp > 12 then
     begin
      tmp:=1;
      K[i].Monat:=tmp;
      inc(Kjahr);
      K[i].Jahr:=KJahr;
     end;                  //<-If
   inc(tmp);
 end;                  //<-For
end;                                   //<-Proc

.......


Wenn ich die Arraylänge vor dem Aufruf der Prozedur mit 'SetLenght' setze, funzt es:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.FormCreate(Sender: TObject);
begin
BorderIcons := [biSystemmenu];
Form1.caption:='Astra Raten - Stand: '+DatetoStr(Date);
....
....
setlength(Kredit,48);
Berechnen_Arrayfuellen(Kredit,Ratenzahl);


Hätte die 'SetLength' aber lieber in der Prozedur, geht das?
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 14.10.07 14:43 
Hi,

probiers mal so:

ausblenden Delphi-Quelltext
1:
Procedure TForm1.Berechnen_Arrayfuellen(var K:array of TKredit;idz:integer);					


damit änderst du dann aber auch das Array in OnCreate
ausblenden Delphi-Quelltext
1:
Berechnen_Arrayfuellen(Kredit,Ratenzahl); //<- hier wird das Array auch verändert					


wenn du willst, dass es sich nur in der Funktion Arrayfuellen ändert, dann musst du es erst "umfüllen", also in ein lokales array z.B.

Xion

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
SpaghettiCodix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52
Erhaltene Danke: 1

WIN XP
Delphi 2 Standart und Delphi 2005 Pers.
BeitragVerfasst: So 14.10.07 15:01 
user profile iconXion hat folgendes geschrieben:
Hi,

probiers mal so:

ausblenden Delphi-Quelltext
1:
Procedure TForm1.Berechnen_Arrayfuellen(var K:array of TKredit;idz:integer);					


damit änderst du dann aber auch das Array in OnCreate
ausblenden Delphi-Quelltext
1:
Berechnen_Arrayfuellen(Kredit,Ratenzahl); //<- hier wird das Array auch verändert					



Xion

ausblenden Delphi-Quelltext
1:
Procedure TForm1.Berechnen_Arrayfuellen(var K:array of TKredit;idz:integer);					

Ändert nix. Die Fehlermeldung bleibt :-(
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 14.10.07 15:21 
Hallo!

Versuch's mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
type
  TKreditArray = Array of TKredit;

...

Procedure TForm1.Berechnen_Arrayfuellen(K: TKreditArray;idz:integer);

...

var
  Kredit: TKreditArray;

...

Berechnen_Arrayfuellen(Kredit,Ratenzahl);


Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
SpaghettiCodix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52
Erhaltene Danke: 1

WIN XP
Delphi 2 Standart und Delphi 2005 Pers.
BeitragVerfasst: So 14.10.07 16:28 
user profile iconChristian S. hat folgendes geschrieben:
Hallo!

Versuch's mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
type
  TKreditArray = Array of TKredit;

...

Procedure TForm1.Berechnen_Arrayfuellen(K: TKreditArray;idz:integer);

...

var
  Kredit: TKreditArray;

...

Berechnen_Arrayfuellen(Kredit,Ratenzahl);


Grüße
Christian


Geht nicht, die Procedure scheint überhaupt nicht aufgerufen zu werden:
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:
type
  TKredit = record
   Monat  : word;
   Jahr   : word;
   Rate_Nr: word;
   bezahlt:currency;
 end;

Type
TKreditArray = array of TKredit;

type
  TForm1 = class(TForm)
    StatusBar1: TStatusBar;
............
............
  public
    { Public-Deklarationen }
    procedure DatumDecod;
    Procedure Berechnen_Arrayfuellen(var K:TKreditArray;idz:integer);
    function Ausgabe(var K:TKreditArray;idz:Integer):TKredit;
  end;

var
  Form1: TForm1;
  Kredit:TKreditArray;

procedure TForm1.FormCreate(Sender: TObject);
var
  a:TKredit;
begin
BorderIcons := [biSystemmenu];
......................
......................
//setlength(Kredit,Ratenzahl);
Berechnen_Arrayfuellen(Kredit,Ratenzahl);
.........
.........
Procedure TForm1.Berechnen_Arrayfuellen(var K:TKreditArray;idz:integer);
var
  i, tmp:byte;
   KJahr:word;
begin
setlength(K,idz);
KJahr:=KredJahr;
K[0].Jahr:=KredJahr;
K[0].Monat:=KredMonat;
tmp:=KredMonat;
Label11.Caption:='HALLO';  //<- wird nicht angezeigt, also kein Aufruf der Proc ?!!?
  For i:=0 to (idz-1) do
  begin
   if i =0 then K[i].bezahlt:=Rate_1 else
   K[i].bezahlt:=K[i-1].bezahlt+Rate;
   K[i].Rate_Nr:=(i+1);
   K[i].Jahr:=KredJahr;
   K[i].Monat:=tmp;
   if tmp > 12 then
     begin
      tmp:=1;
      K[i].Monat:=tmp;
      inc(Kjahr);
      K[i].Jahr:=KJahr;
     end;                //<-If
   inc(tmp);
 end;                  //<-For
end;