Autor Beitrag
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Mo 13.07.09 19:28 
Hi leute!

Ich habe ein Problem mit dem Längensetzen von 2Dimensionalen arrays:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
  
SetLength(Area,Width);
  for i := 0 to length(Area) - 1 do
    SetLength(Area[i],Height);


wobei
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
type  TPhysicPixelArea = Array of Array of TPhysicPixel;

type foo

public
  property Area         : TPhysicPixelArea read FArea       write FArea;
end;


Dabei erhalte ich immer die Fehlermeldung
ausblenden Quelltext
1:
[Pascal Fehler] destructable.pas(52): E2197 Konstantenobjekt kann nicht als Var-Parameter weitergegeben werden					


Was mache ich denn falsch? *festestelldasseskeinenheulsmiliegibt:'(*
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19313
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 13.07.09 19:35 
Du kannst eine Eigenschaft nicht als Variable benutzen. ;-)
Du müsstest also ein Array definieren wie du es brauchst und kannst dieses dann als Ganzes an die Eigenschaft zuweisen.

Besser wäre, wenn du einfach einen Setter für die Größe des Arrays einführst oder so.
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Mo 13.07.09 19:36 
user profile iconFinnO hat folgendes geschrieben Zum zitierten Posting springen:
*festestelldasseskeinenheulsmiliegibt:'(*

Und ob: :bawling:
FinnO Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Mo 13.07.09 19:43 
danke, klappt super. Mir ist nur noch nicht ganz klar, warum man eine property nicht als parameter angeben darf.

Idee: Liegt daran, dass hinterher die Länge in den Parameter geschrieben wird?!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19313
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 13.07.09 19:47 
Eine Eigenschaft ist anders als eine Variable nicht direkt eine Adresse im Speicher. Und deshalb wird die Eigenschaft jeweils gelesen und gesetzt.

Das ist auch der Grund, weshalb der Zugriff auf Memo1.Text[i] extrem langsam ist. Dabei wird jeweils der String Text geholt und dann dort auf den Buchstaben zugegriffen. Bei einer Variablen könnte man direkt auf das i-te Zeichen zugreifen, das eben soundsoviel Byte vom Start des Speicherbereichs im Speicher liegt.
FinnO Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Mo 13.07.09 20:05 
okay, ich muss meine Aussage nochmal zurückziehen...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure SetAreaSize(X,Y : Integer; Area : TPhysicPixelArea);
var
  i: Integer;
begin
  SetLength(Area,X);
  for i := 0 to length(Area) - 1 do
    SetLength(Area[i],Y);
end;


bringt gar nichts, bzw. ist length(Area) immer 0 :'-(

Hat jemand einen heißen Tipp?