Autor Beitrag
buSC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Sa 13.03.10 16:55 
Hallo
ich habe mal ein 4*3 array .
ich will jeweils eine zeile dieses Array lesen und in array "arr" speichern ,warum klappt die copy function hier nicht ich bekomme den Fehler :"incompatible types"
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  mat:array of array of Shortint;
  i,j:integer;
  arr:array of Shortint;
begin
 SetLength(mat,4,3);
 setlength(arr,length(mat[0]));
  for i:= 1 to 4 do
    for j:=1 to 3 do
     mat[i-1,j-1]:=j;
 arr:=copy(mat[1]);//warum klappt diese Zeile nicht !!!
end;
Danke im Voraus

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 13.03.10 17:18 
Hi, versuch mal mit arr[0] oder so. :wink:
Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 13.03.10 17:41 
Copy ist doch eigentlich nur für Strings gedacht, um da einzelne Zeichen rauszukopieren?

Such mal nach MemCopy oder so ähnlich.

Edit: Ähhh. oder versuch einfach mal Arr := mat[1];

_________________
PROGRAMMER: A device for converting coffee into software.
buSC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Sa 13.03.10 18:03 
ertmal Danke sehr an die Freunde ,die versucht haben mich zu antworten
ja ich habe arr:=mat[1] , arr[0]:=mat[1] ausprobiert und nicht geklappt.
uebrigens habe ich kein memcopy function gefunden.
:)
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 13.03.10 18:12 
ich glaube es muss so sein,
arr := copy(mat[1,1])
mat ist ein mehrdimensionales array und arr ein eindimensionales!

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
buSC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Sa 13.03.10 18:21 
danke an alf fuer die Antwort
ich glaube nicht dass es klappt,weil mat[1,1] ein nummer ist waehrend "arr" ein array ist.
aber kann ich es mal ausprobieren. :)
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 13.03.10 18:47 
Du willst doch den inhalt von mat[0] in ein anderes array copieren!?
mat[0] hat aber noch 3 felder, mat[0,0] mat[0,1] mat[0,2] z.b
Um das zu copieren muss das andere Array auch mehrdimensional sein!
also vom gleichen Typ!

Ansonsten geht es glaube nur mit arr[0]:= mat[0,0], arr[1]:= mat[0,1] usw.
Gruss Alf

P.S hoffe jetzt nix falsch gesagt zu haben?

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 13.03.10 18:55 
user profile iconALF hat folgendes geschrieben Zum zitierten Posting springen:
Du willst doch den inhalt von mat[0] in ein anderes array copieren!?
mat[0] hat aber noch 3 felder, mat[0,0] mat[0,1] mat[0,2] z.b
Um das zu copieren muss das andere Array auch mehrdimensional sein!

Ne, eben nicht. Er möchte die n-te Dimension von mat in ein anderes Array umkopieren, warum auch immer.

Also, neuer Vorschlag:
Du definierst im Interface einen neuen Typen.
ausblenden Delphi-Quelltext
1:
2:
type
  TMyShortIntArray = array of Shortint;

Dann baust du deine Deklarationen um:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
  mat:array of TMyShortIntArray;
  i,j: integer;
  arr: TMyShortIntArray;


und DANN kannst du das auch zuweisen ;) arr := mat[0];

_________________
PROGRAMMER: A device for converting coffee into software.
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 13.03.10 19:11 
Sollte ich sein Code so Falsch verstanden haben?
sein Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  mat : array of array of Shortint; //<= mehrdimensional
  i,j : integer;
  arr : array of Shortint; //<= eindimensional

....
....

arr := copy(mat[1]); //mat{1] hat mat[1,0] mat[1,1] mat[1,2] mit copy in ein eindimensionales array????

sollte ich so falsch liegen dann sorry :oops:

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 13.03.10 19:32 
mat[1,1] ist vom Typ Shortint, das kannst du nicht mehr einem array zuweisen. (höchstens an eine bestimmtes Stelle)
mat[1] wäre schon korrekt, aber der Compiler kapiert nicht, dass "array of Shortint" und "array of Shortint" das selbe ist. Deswegen muss man da einen Typen für definieren, von dem beide abstammen. Dann würde das auch wieder mit arr:=copy(mat[1]); funktionieren.

_________________
PROGRAMMER: A device for converting coffee into software.
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 13.03.10 23:45 
user profile iconXentar alles richtig was Du sagts, habs mal durchgemacht :wink:
Aber trotzdem sehr irreführend :gruebel:
ausblenden Delphi-Quelltext
1:
2:
mat : array of array of Shortint
arr : array of Shortint;

Danke hab was gelernt :D

Sorry user profile iconbuSC für meine falschen infos :oops:

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
buSC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: So 14.03.10 17:31 
vielen Dank an die Beide Freunde Alf und Xentar fuer ihre Antworte.
an Alf: kein Problem, es ist mir wichtig ,dass du versucht hast mich zu beantworten :)