Autor Beitrag
curtiss
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 59



BeitragVerfasst: Mo 24.01.05 20:16 
Hi,

Ich habe dass problem das ich nicht weis wie ich eine array variable an meine prozedur
übergebe!

In der Hilfe habe ich nichts gefunden.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure schaden(var s_warenwert[1..12] :real;s_schaden[1..12]:real;
                 s :integer;sg : real);
var
i : integer;

begin
  for i:=1 to s do
      begin
           randomize;
           if random(2) >=1 then
           s_schaden[i] := s_warenwert[i] * (sg/ 10) * random(1);
      end;
end;


So hatte ich imr das gedacht aber es funzt net!

Danke im voraus!

MFG
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 24.01.05 20:19 
:welcome:

Definier die Arrays als Typen und übergib die Typen der Funktion

AXMD
curtiss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 59



BeitragVerfasst: Mo 24.01.05 20:34 
aaaaaaalles klar!!!

ne im ernst, ich habe kein plan! kenne keine typen.
was soll das sein?

Und nochwas!

Wie kann ich strings an meine prozedur übergeben=? Da meggert der auch rum.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mo 24.01.05 20:38 
entweder:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
type array12 = array [1..12] of real;


procedure schaden(var warenwert: array12; var schaden: array12;   
                 s :integer;sg : real);   
var   
i : integer;   

begin   
  for i:=1 to s do   
      begin   
           randomize;   
           if random(2) >=1 then   
           s_schaden[i] := s_warenwert[i] * (sg/ 10) * random(1);   
      end;   
end;


oder:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure schaden(var warenwert: array of real; var schaden: array of real;   
                 s :integer; sg : real);   
var   
i : integer;   

begin   
  for i:=1 to s do   
      begin   
           randomize;   
           if random(2) >=1 then   
           s_schaden[i] := s_warenwert[i] * (sg/ 10) * random(1);   
      end;   
end;
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 24.01.05 20:40 
Es war sowas gemeint:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
type 
  TWarenwert = Array[1..12] of real;
[...]
procedure schaden(var s_warenwert:TWarenwert; s_schaden:TWarenwert; s :integer;sg : real);


Was klappt denn nicht mit Strings? Sollte allgemein gehen. Oder nimmst du da auch was wie string[20]?

_________________
We are, we were and will not be.
curtiss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 59



BeitragVerfasst: Mo 24.01.05 21:10 
hier mein hauptprogramm =

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:
var
s_warenwert : array[1..12] of real;
s_schaden   : array[1..12] of real;

[...]

procedure schaden(var s_warenwert : array12;s_schaden : array12;
                      s : integer; sg : real);
var
i : integer;

begin
  for i:=1 to s do
      begin
           randomize;
           if random(2) >=1 then
           s_schaden[i] := s_warenwert[i] * (sg/ 10) * random(1);
      end;
end; 

[...]

begin
[...]
type array12 = array [1..12] of real;


und, wie soll ich es sagen, es funzt net!

und nochwas, dass midn strings hat sich erledigt !
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 24.01.05 21:11 
type oben deklarieren

AXMD
curtiss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 59



BeitragVerfasst: Mo 24.01.05 21:43 
wie soll ich dann meine globalen variablen übergeben??

wenn ich so tu :
ausblenden Delphi-Quelltext
1:
schaden(s_warenwert,s_schaden,s,sg);					


sachta typen nicht miteinander vereinbar.

??? thx allot
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 24.01.05 22:20 
weil du dann auch den Typ der Variablen anpassen musst?
array[1..12] of real und array12 mag ja dasselbe sein, aber der Delphi-Compiler ist da pingelig.

btw.: Gewöhn dir am besten an, Typenbezeichnungen mit einem T zu beginnen. Also z.B. Tarray12. Dann weiss man später, was ein Variablenname, und was ein Typbezeichner ist.

_________________
We are, we were and will not be.
curtiss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 59



BeitragVerfasst: Mo 24.01.05 22:41 
wie soll ich dass den schreien?

wenn ich dass so mache

schaden(s_schaden[1..12]) -> da meggert er
schaden(s_schaden:array12) -> da meggert er

wis soll ichs denn machen?
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mo 24.01.05 23:10 
schaden(s_schaden) ?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 24.01.05 23:14 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
//erstens: Oben Typen deklarieren
type array12 = array [1..12] of real;   

//Die Prozedur dann so deklarieren und entsprechend implementierem
procedure schaden(var warenwert: array12; var schaden: array12;       
                 s :integer;sg : real); 


//Aufruf der Funktion: z.B.:
procedure TForm1.button1click(sender:TObject)
var warenwert, schaden: array12;
begin
//[...]
schaden(warenwert,schaden,42,3.14);
//[...]
end;

_________________
We are, we were and will not be.