![]() |
AW: einen Datensatzmitgliedsnamen dynamisch zuweisen
Deklaration und Implementierung nur zu Testzwecken ist fertig. Aber das Programm hat jetzt viele Fehler im Anwendungsteil. Ich kann es also nicht als Ganzes kompilieren.
Code:
Jetzt ist die Frage, wie ich das Ganze modifizieren kann, damit ich den Code im Anwendungsteil ändern kann, zum Beispiel gibt es so eine Funktion:
type TBasicSettings = class // the ini.basic
private fGroups: array[0..1] of TBasicGroupSettings; function getA_(G:String): String; procedure setA_(G:String; V: String); function getA(Index: Integer): String; procedure setA(Index: Integer; V: String); function getAA(Index: Integer): String; procedure setAA(Index: Integer; V: String); public AA: TBasicGroupSettings; BB: TBasicGroupSettings; property basic[G:String]: String read GetA_ write SetA_; property A: String Index 0 read GetA write SetA; property B: String Index 1 read GetA write SetA; property group[Index: Integer]: String read GetA write SetA;default; constructor Create; end; type TSettings = record basic: TBasicSettings; // the ini end; implementation constructor TBasicSettings.Create; begin end; function TBasicSettings.getA_(G:String): String; begin Result := 'test'; end; procedure TBasicSettings.setA_(G:String; V: String); begin G := V; end; function TBasicSettings.getA(Index: Integer): String; begin Result := 'test'; end; procedure TBasicSettings.setA(Index: Integer; V: String); begin Index := 0; end; function TBasicSettings.getAA(Index: Integer): String; begin Result := fGroups[0].path; end; procedure TBasicSettings.setAA(Index: Integer; V: String); begin Index := 0; end;
Code:
// definition part - This must be edited to work correctly with newly created properties
procedure get_prefix_and_zeros_count(ini: TSettings; var prefix: string; var count: byte); var i: byte; begin with ini.bVal.A do prefix := copy(start,1,length(start)-length(ini.basic.A.first)); i:=length(prefix); count := 0; repeat if prefix[i]='0' then inc(count); dec(i); until (prefix[i]<>'0') or (i=1); prefix := copy(prefix, 1, length(prefix)-count); end;
Code:
Ich persönlich denke, es wäre am besten, es so anzugehen:
// application part - This must be edited to work correctly with newly created properties
get_prefix_and_zeros_count(ini, ini.bVal.A.prefix, ini.bVal.A.maxZeros2Add); get_prefix_and_zeros_count(ini, ini.bVal.B.prefix, ini.bVal.B.maxZeros2Add);
Code:
get_prefix_and_zeros_count('A');
get_prefix_and_zeros_count('B');
Code:
Aber ist eine Zuordnung auf diese Weise überhaupt möglich?
// definition part changed
procedure get_prefix_and_zeros_count(g: string); var count, i: byte; begin // ini.bVal(g).maxZeros2Add is count of zeros with ini.bVal(g) do begin prefix := copy(start,1,length(start)-length(ini.basic(g).first)); i:=length(prefix); count := 0; repeat if prefix[i]='0' then inc(count); dec(i); until (prefix[i]<>'0') or (i=1); ini.bVal(g, count); prefix := copy(prefix, 1, length(prefix)-count); end; end;
Code:
Also sollte ich es nicht wiederholen, damit es so geht?
ini.bVal(g).prefix :=
Code:
ini.bVal.A.prefix :=
Code:
oder eher
ini.bVal.B.prefix :=
Code:
bVal ist Basic ähnlich, hat aber abgeleitete und berechnete Werte, während Basic die Einstellungen aus der INI-Datei hat.
ini.bVal[g].prefix :=
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:18 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 by Thomas Breitkreuz