Autor Beitrag
Tex
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Sa 15.12.07 18:10 
Hallo,

ich habe ein Problem.

Ich habe eine Procedure welche Daten (Strings) in ein Array schreibt. Momentan steht das Array fest in der Procedure.

Ich möchte nun aber die Procedure im Programm mehrfach aufrufen. Dabei sollen die Werte der Procedure jedes mal in ein anderes Array geschreiben werden. Ich müßte also den Namen des Array`s wo das Ergebnis hin soll mit an die Procedure übergeben. Aber wie??

Macht man so etwas mit Pointern? Ich habe mir dazu ein Tutorial zu Pointern durchgelesen, aber damit nix zu stande gebracht.

Kein mir vielleicht jemand einen Tipp geben?


Danke,

Tex

_________________
"Alles was du hast, hat irgendwann dich." Tyler Durden
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: Sa 15.12.07 18:14 
Übergib der Prozedur doch einfach das Array als weiteren Parameter. Variablen über ihren Namen identifizieren geht bei Delphi afaik nicht. Sowas wie FindComponent für Variablen gibts nicht.

_________________
We are, we were and will not be.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Sa 15.12.07 18:15 
Ich habe zwar nicht ganz verstanden, was Du willst, aber die Nutzung von TStringList und TStringList sollte einiges vereinfachen,

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:
FText: TStringList;

procedure Init;
begin
  FText := TStringList.Create;
end;

procedure Done;
begin
  FText.Free;
  FText := nil;
end;

procedure Proc1;
var
  HCopy: TSTringList;
begin
  HCopy := TStringList.Create;
  HCopy.Assign(FText);
  //verarbeiten
  HCopy.Free;
end;

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Tex Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Sa 15.12.07 20:55 
Danke für die schnellen antworten...

@Gausi: genau das will ich tun, aber wie?
@Kroko: ene Stringlist is ja im Prinzip auch nur ein Array oder?

Ich hab mal schnell was gebastelt, was mein Vorhaben veranschaulichen soll. (So funzt es natürlich nicht)

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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure schreibearray(arrayname: array of string);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  array1, array2: array[0..2] of string;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
schreibearray(array1);
end;


procedure TForm1.schreibearray(arrayname: array of string);
begin
arrayname[0]:='test';
end;

end.


Also:

- wenn ich Button1 drücke soll danach "Test" im Ersten Eintrag des Array1 stehen.
- eenn ich aber Button2 drücke soll die Procedure "schreibearray" "Test" in Array2 schreiben.

Ich muss also den Namen des Zielarrays (array1 oder array2) mit an die Procedure "schreibearray" übergeben.
Aber wie??

_________________
"Alles was du hast, hat irgendwann dich." Tyler Durden
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: Sa 15.12.07 21:05 
Das geht so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
type 
  TMyArray = array[0..2] of string;

//...

var 
  array1, array2: TMyArray;

//...

procedure TForm1.schreibearray(EinArray: TMyArray); 
begin 
  EinArray[0]:='test'; 
end;

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  schreibearray(array1); 
end;

_________________
We are, we were and will not be.
Tex Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Sa 15.12.07 21:18 
ohh, so einfach. Super, Danke.
Der Compiler meckert nicht mehr. Aber irgendwo hab ich noch einen Fehler.
Bei dem Code müßten die Buttons doch nach dem klick mit "test" beschriftet sein, oder? Sie haben aber keine Beschriftung.

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:
unit Unit1;

interface

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


type
 meinarray = array[0..2] of string;

type
    TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure schreibearray(arrayname: meinarray);
    procedure Button2Click(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  array1, array2: meinarray;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
schreibearray(array1);
Button1.Caption:=array1[0];
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
schreibearray(array2);
Button2.Caption:=array2[0];
end;

procedure TForm1.schreibearray(arrayname: meinarray);
begin
arrayname[0]:='test';
end;


end.

_________________
"Alles was du hast, hat irgendwann dich." Tyler Durden
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 15.12.07 21:44 
Fast.
Über die Deklaration
ausblenden Delphi-Quelltext
1:
Procedure TForm1.schreibearray(arrayname: meinarray);					

Sagst Du dem Kompiler, das er in der Routine 'schreibearray' mit einer Kopie von 'ArrayName' arbeiten soll. Das ist so, als ob ich Dir einen Vertrag zum unterschreiben gebe, aber Du eine Kopie anfertigst, und den unterschreibst. Eben damit das Original nicht verändert wird.

Du sollst aber das Original unterschreiben. Dazu musst Du angeben, das der Vertrag direkt verändert werden soll. Unter Delphi geht das so:

ausblenden Delphi-Quelltext
1:
Procedure TForm1.schreibearray(VAR arrayname: meinarray);					


Fertig.

Übrigens, wonach Du fragst, nennt sich 'Call by Name' und ist eine Parameterübergabekonvention aus den Anfängen der Programmierung. Heutzutage gibt es imho eigentlich nur noch 'Call by Value' ('Mach ne Kopie') und 'Call by Reference' (Verändere das Original).

_________________
Na denn, dann. Bis dann, denn.
Tex Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Sa 15.12.07 21:48 
Super! Jetzt loofts...
Danke an alle.
:-)

_________________
"Alles was du hast, hat irgendwann dich." Tyler Durden