Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi const array of record (https://www.delphipraxis.net/42902-const-array-record.html)

Quake 25. Mär 2005 17:51


const array of record
 
Wie kann ich einem Array of Record Konstanten zuordnen?
Delphi-Quellcode:
type
  TRec = record
    Text: string;
    Zahl: integer;
  end;

const
  MyArray: array[0..1] of TRec = (('Str1',4),('str2',7)); // wie muss dieser Syntax richtig aussehen?
ciao

Dax 25. Mär 2005 17:54

Re: const array of record
 
So muss es gehen ;-)
Delphi-Quellcode:
type
  TRec = record
    Text: string;
    Zahl: integer;
  end;

const
  MyArray: array[0..1] of TRec = ((Text: 'Str1'; Zahl: 4), (Text: 'str2'; Zahl: 7));

Quake 25. Mär 2005 18:55

Re: const array of record
 
Danke Dir :thumb:

e-gon 17. Sep 2010 14:49

AW: const array of record
 
Hallo,

aber was ist, wenn im Record selbst ein Array steht. Wie kann man dieses dann zuordnen?
Delphi-Quellcode:
type
  TRec = record
    Text: string;
    Zahlen: Array [0..1] of Byte;
  end;
Das geht leider nicht:
Delphi-Quellcode:
const
  MyArray: array[0..1] of TRec =
    ((Text: 'Str1'; Zahlen[0]: 4; Zahlen[1]: 2),
     (Text: 'Str2'; Zahlen[0]: 9; Zahlen[1]: 3));
Hier heißt es 'Inkompatible Typen: Array und Set':
Delphi-Quellcode:
const
  MyArray: array[0..1] of TRec =
    ((Text: 'Str1'; Zahlen: [4,2]),
     (Text: 'Str2'; Zahlen: [9,3]));
Und bei dieser Variante bekomme ich mit D6 immer einen DCC60.dll-Fehler:
Delphi-Quellcode:
const
  MyArray: array[0..1] of TRec =
    ((Text: 'Str1'; Zahlen: 4; Zahlen: 2),
     (Text: 'Str2'; Zahlen: 9; Zahlen: 3));

Neutral General 17. Sep 2010 14:57

AW: const array of record
 
Hallo,

Versuchs mal so:

Delphi-Quellcode:
const
  MyArray: array[0..1] of TRec =
    ((Text: 'Str1'; Zahlen: (4,2)),
     (Text: 'Str2'; Zahlen: (9,3)));
(aber keine Garantie)

e-gon 17. Sep 2010 15:13

AW: const array of record
 
Sieht gut aus, danke! :thumb:

ConnorMcLeod 29. Sep 2011 09:03

AW: const array of record
 
Hallo, weiß jemand, wie die Konstantendeklaration in diesem Fall aussieht?:
Delphi-Quellcode:
type
  TZahl = record // ist natürlich Unsinn, aber als Beispiel genügt es...
    Vorkomma: integer;
    Nachkomma: integer;
  end;

  TRec = record
    Text: string;
    Zahlen: Array of TZahl;
  end;
Also ein <array of record> innerhalb eines records.
Danke schonmal!

p80286 29. Sep 2011 09:41

AW: const array of record
 
Ich weiß jetzt nicht ob ein dyn Array in einer const geht aber die Wertübergabe müßte so aussehen:
Delphi-Quellcode:
const
  myvalue:trec=('meintext',(1,2),(3,4),(5,6));
ohne Gewehr solche Konstrukte hab ich lang nicht mehr benutzt.

Gruß
K-H

himitsu 29. Sep 2011 16:53

AW: const array of record
 
Zitat:

Hallo, weiß jemand, wie die Konstantendeklaration in diesem Fall aussieht?:
Geht nicht.

Man kann keine Konstanten für dynamische Arrays anlegen. (leider)

ConnorMcLeod 30. Sep 2011 10:22

AW: const array of record
 
Zitat:

Zitat von himitsu (Beitrag 1127542)
Geht nicht.

Hab ich befürchtet, danke trotzdem ... für die Bestätigung!


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz