![]() |
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Zitat:
|
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Array-Property, das ist sowas, wie bei TList/TStrings/TStringList ... halt wie beim Array.
Delphi-Quellcode:
Default-Property, sind jene, welche "implizit" genutzt werden können.
property Strings[Index: Integer]: string read GetString write SetStrings;
SL.Strings[index] SL.Value[Name]
Delphi-Quellcode:
dagegen die Default-Value bzw. Default-Property-Value
property Strings[Index: Integer]: string read GetString write SetStrings; default;
SL.Strings[index] // direkt SL[index] // default
Delphi-Quellcode:
property Cool: Boolean read GetCool write SetCool default True;
Die Klasse Instanz neu erstelt, da ist der Wert True ... bzw. eigentlich heißt es, dass "True" nicht in der DFM gespeichert wird, also nur "False" steht drin. (stimmen beide Aussagen aber nicht überein, dann hast du ein Problem, beim Laden einer DFM ... also aufpassen, wenn du Klassen baust)
Delphi-Quellcode:
property StringEx: string index 123 read GetString write SetStrings;
SL.StringEx // Index nur intern, z.B. zur Haldung von Kontroll-Daten und/oder um für mehrere Property nur "einen" Getter/Setter zu nutzen // aber so fällt bestmmt auf, dass diese beiden "Index" nicht das Gleiche sind property StringEx[Index2: Integer]: string index 123 read GetString write SetStrings; // der Getter und Setter sieht hier erstmal gleich aus property A: string index 1 read GetABC write SetABC; property B: string index 2 read GetABC write SetABC; property C: string index 3 read GetABC write SetABC; property X[Index: Integer]: string read GetABC write SetABC; procedure GetABC(Index: Integer): string; begin //Assert((Index => 1) and (Index <= 3), 'peng'); case Index of 1: Result := 'Aaa'; 2: Result := 'Bbb'; 3: Result := 'Ccc'; else raise Exception.Create('peng'); end; end; |
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Ich habe versucht, dem Beispiel in
![]()
Code:
[Error] constants_ini.pas(47): ':' expected but identifier 'TBasicGroupSettings' found
TBasicGroupSettings = record
path: string; check_files_exist: boolean; start_name: string; // first_filename first: string; // first_filename last: string; // end_frame end; // ini.basic has some general settings too type TBasicSettings = class is_scroll_vertical: boolean; is_image_direction_up: boolean; is_search_colors_HSL: boolean; check_files_exist_A: boolean; check_files_exist_B: boolean; RAM_disk: string; RAM_free: LongWord; // v MB A: TBasicGroupSettings; B: TBasicGroupSettings; fps: byte; scroll_max_shift: integer; property basic[G:String] TBasicGroupSettings read Get_A write Set_A; end;
Code:
property basic[G:String] TBasicGroupSettings read Get_A write Set_A;
|
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Die Hilfe ist kaputt ... bei der automatischen Übersetzung sind ein paar Zeichen verloren gegangen.
Zitat:
Delphi-Quellcode:
und dann in TBasicSettings.Create die beiden Instanzen erstellen.
BasicGroupSettings = class
Und natürlich im TBasicSettings.Destroy wieder freigeben, oder Beides als
Delphi-Quellcode:
, beim Erstellen das den Owner auf Self und automatisch freigeben lassen.
= class(TComponent)
Zitat:
Delphi-Quellcode:
// bei einem RECORD landet "first" nur im Result von Get_A, aber wird nicht automatisch in Set_A zurückgeschrieben.
basicsetting.basic['A'].first := 'abc'; // daher .... als CLASS gäbe es dieses Problem nicht // eventuell vorher auslesen: temp := basicsetting.basic['A']; temp.first := 'abc'; basicsetting.basic['A'] := temp; |
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Dann habe ich versucht, es mit einem Array zu tun, aber dort sagt es mir inkompatible Typen hinter dem Wort write.
Code:
type TBasicSettings = class
private fGroups: array[0..1] of TBasicGroupSettings; function getA(Index: byte): TBasicGroupSettings; function getB(Index: byte): TBasicGroupSettings; procedure setA(Index: byte; O: TBasicGroupSettings); procedure setB(Index: byte; O: TBasicGroupSettings); public is_scroll_vertical: boolean; // scroll_type=vertical is_image_direction_up: boolean; // image_direction is_search_colors_HSL: boolean; check_files_exist_A: boolean; check_files_exist_B: boolean; RAM_disk: string; RAM_free: LongWord; // v MB start_name_A: string; // A: TBasicGroupSettings; // B: TBasicGroupSettings; fps: byte; scroll_max_shift: integer; // property basic[G:String] TBasicGroupSettings read Get_A write Set_A; property A: TBasicGroupSettings Index 0 read GetA write SetA; property B: TBasicGroupSettings Index 1 read GetB write SetB; end; |
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
In Delphi 7 gibt es diese Möglichkeiten noch nicht.
|
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Zitat:
![]()
Code:
Das habe ich in Beitrag 15# nicht gesehen.
7.Property Name[Index : IndexType] : BaseType read Getter {default;}
Sie erklären auch das Standardwort, das mir unklar war. "Default allows the Getter and Setter method calls to be replaced as in the following example:"
Code:
:
myValue := MyClass.Getter(23);
// can be replaced by : myValue := MyCLass[23]; |
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Array-Property gingen in D7, aber Einiges davon funktioniert oftmals nur, wenn es auch als Default deklariert ist, sonst nicht.
Darum ist es in der StringList auch so
Delphi-Quellcode:
weil es so nicht ging
property Value[Name: String]: String ...
property ValueByIndex[Index: Integer]: String ...
Delphi-Quellcode:
seit den class-operators hatte ich mir dann so beholfen
property Value[Name: String]: String ...
property Value[Index: Integer]: String ...
Delphi-Quellcode:
ja, hier wäre auch Variant möglich , aber alles da oben stellt sicher, dass "nur" Integer oder String rein geht (Float, Boolean und Anderes wird direkt vom Compiler bemängelt)
type
TIndexName = record Index: Integer; Name: string; class operator Implicit(Value: Integer): TIndexName; class operator Implicit(Value: String): TIndexName; end; property Value[Name: TIndexName]: String ...; default;
Delphi-Quellcode:
property Value[Name: Variant]: String ...; default;
um sowas machen zu können
Delphi-Quellcode:
xyz.Value[123]
xyz.Value['abc'] xyz[123] xyz['abc'] |
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Also habe ich verschiedene Dinge ausprobiert, aber alles falsch ...
property A: TBasicGroupSettings Index 0 read GetA write SetA;default; property B: TBasicGroupSettings Index 1 read GetB write SetB;default; property group[Index: byte]: TBasicGroupSettings read GetB write SetB;default; Denn dort muss String vorhanden sein, nicht Objekt. Das Objekt, das ich manuell in den Getter- und Setter-Implementierungscode implementieren muss. |
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Wo ist da ein "String"?
Und was ist "Falsch"?
Delphi-Quellcode:
gibt es ausschließlich für Array-Property.
; default;
Delphi-Quellcode:
, bzw.
default EineOrdinaleKonstante;
Delphi-Quellcode:
, gibt es dagegen nur für einfache Property.
stored TrueOderFalseOderFunktion;
String: Meinst du sowas?
Delphi-Quellcode:
property Value[GroupABC: Char; Value: string]: string read GetValue write SetValue;
xxx.Value['A', 'start_name'] := 'abc'; xxx['A', 'start_name'] := 'abc'; // wenn mit "default" PS:
Delphi-Quellcode:
läßt der Compiler erstmal durch, aber dann beim Setter/Getter knallt es, weil
property group[Index: Byte = 0]: TBasicGroupSettings read GetB write SetB;
Delphi-Quellcode:
zwar noch geht,
procedure GetB(Index: Byte = 0): TBasicGroupSettings);
es aber hier
Delphi-Quellcode:
leider nicht.
procedure SetB(Index: Byte = 0; Value: TBasicGroupSettings {= nil});
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:49 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz