AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

einen Datensatzmitgliedsnamen dynamisch zuweisen

Ein Thema von neumimnemecky · begonnen am 6. Jul 2022 · letzter Beitrag vom 7. Jul 2022
 
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.578 Beiträge
 
Delphi 12 Athens
 
#4

AW: einen Datensatzmitgliedsnamen dynamisch zuweisen

  Alt 6. Jul 2022, 13:34
Die Datenstruktur ändern
und gleiche Teile zusammenfassen?
(und dann nachfolgend den größten Teil ignorieren)

Delphi-Quellcode:
// nicht
ini.basic.path_A := pars[1]
ini.basic.path_B := pars[1]
// sondern
ini.basic.A.path := pars[1]
ini.basic.B.path := pars[1]

// für Objekte statt Records ... bei Records andersrum, also erst den Temp-Record füllen und dann zuweisen
if pars[0] = 'Bthen X := ini.basic.B;
X.path := pars[1];





Delphi-Quellcode:
//if pars[0] = 'first_frame' then k := 'first_'+group
//else if pars[0] = 'end_frame' then k := 'last_'+group
//else if pars[0] = 'first_filename' then k := 'start_name_'+group
//else if pars[0] = 'path' then k := 'path_'+group
//else if pars[0] = 'check_if_files_exist' then k := 'check_files_exist_'+group
//else ; // was ist k, wenn nichts trifft?

// wozu den ersten Teil umbennen?
// sowas würde sich nur lohnen, wenn du anschließend mit diesen Namen via RTTI nach den Feldern suchen tätest.
TRTTIContext.Create.GetType(TIniBasicRecordIrgendwas).GetField(k).SetValue(ini.basic, pars[1]); // abgesehn vom check_if_files_exist
// es gibt auch Funktionen/Klassen/Frameworks, z.B. für INI/XML/JSON zu Record/Klasse, auch inkl. Umbenennen von SpeicherName zu FeldName

k := pars[0] + group;
if group = 'Athen begin
  if k = 'path_Athen ini.basic.path_A := pars[1]
  else if k = 'first_frame_Athen ini.basic.first_A := pars[1]
  else if k = 'end_frame_Athen ini.basic.last_A := pars[1]
  else if k = 'first_filename_Athen ini.basic.start_name_A := pars[1]
  else if k = 'check_if_files_exist_Athen ini.basic.check_files_exist_A := true;
end else if group = 'Bthen begin
  if k = 'path_Bthen ini.basic.path_B := pars[1]
  else if k = 'first_frame_Bthen ini.basic.first_B := pars[1]
  else if k = 'end_frame_Bthen ini.basic.last_B := pars[1]
  else if k = 'first_filename_Bthen ini.basic.start_name_B := pars[1]
  else if k = 'check_if_files_exist_Bthen ini.basic.check_files_exist_B := true;
end;
end; // ein end zuviel?
wozu nochmal die group extra vergleichen, wenn die schon in K enthalten ist?
Delphi-Quellcode:
k := pars[0] + group;
if k = 'path_Athen ini.basic.path_A := pars[1]
else if k = 'first_Athen ini.basic.first_A := pars[1]
else if k = 'last_Athen ini.basic.last_A := pars[1]
else if k = 'start_name_Athen ini.basic.start_name_A := pars[1]
else if k = 'check_files_exist_Athen ini.basic.check_files_exist_A := true
else if k = 'path_Bthen ini.basic.path_B := pars[1]
else if k = 'first_Bthen ini.basic.first_B := pars[1]
else if k = 'last_Bthen ini.basic.last_B := pars[1]
else if k = 'start_name_Bthen ini.basic.start_name_B := pars[1]
else if k = 'check_files_exist_Bthen ini.basic.check_files_exist_B := true;
bzw.
Delphi-Quellcode:
case IndexText(pars[0] + group, ['path_A', 'first_A', 'last_A' , 'start_name_A' , 'check_files_exist_A' , 'path_B' , 'first_B' , 'last_B' , 'start_name_B', 'check_files_exist_B']) oF
  0: ini.basic.path_A := pars[1];
  1: ini.basic.first_A := pars[1];
  2: ini.basic.last_A := pars[1];
  3: ini.basic.start_name_A := pars[1];
  4: ini.basic.check_files_exist_A := true;
  5: ini.basic.path_B := pars[1];
  6: ini.basic.first_B := pars[1];
  7: ini.basic.last_B := pars[1];
  8: ini.basic.start_name_B := pars[1];
  9: ini.basic.check_files_exist_B := true;
end;


oder wozu unnötig umbenennen (Group anhängen), wenn die Groups eh getrennt behandelt werden?
Delphi-Quellcode:
//if pars[0] = 'first_frame' then k := 'first'
//else if pars[0] = 'end_frame' then k := 'last'
//else if pars[0] = 'first_filename' then k := 'start_name'
//else if pars[0] = 'path' then k := 'path'
//else if pars[0] = 'check_if_files_exist' then k := 'check_files_exist';

if group = 'Athen begin
  if pars[0] = 'paththen ini.basic.path_A := pars[1]
  else if pars[0] = 'first_framethen ini.basic.first_A := pars[1]
  else if pars[0] = 'end_framethen ini.basic.last_A := pars[1]
  else if pars[0] = 'first_filenamethen ini.basic.start_name_A := pars[1]
  else if pars[0] = 'check_if_files_existthen ini.basic.check_files_exist_A := true;
end else if group = 'Bthen begin
  if k = 'paththen ini.basic.path_B := pars[1]
  else if pars[0] = 'first_framethen ini.basic.first_B := pars[1]
  else if pars[0] = 'end_framethen ini.basic.last_B := pars[1]
  else if pars[0] = 'first_filenamethen ini.basic.start_name_B := pars[1]
  else if pars[0] = 'check_if_files_existthen ini.basic.check_files_exist_B := true;
end;
bzw.
Delphi-Quellcode:
i := IndexText(pars[0] + group, ['path', 'first', 'last', 'start_name', 'check_files_exist']);
case group of
  'A':
    case i oF
      0: ini.basic.path_A := pars[1];
      1: ini.basic.first_A := pars[1];
      2: ini.basic.last_A := pars[1];
      3: ini.basic.start_name_A := pars[1];
      4: ini.basic.check_files_exist_A := true;
    end;
  'B':
    case i oF
      0: ini.basic.path_B := pars[1];
      1: ini.basic.first_B := pars[1];
      2: ini.basic.last_B := pars[1];
      3: ini.basic.start_name_B := pars[1];
      4: ini.basic.check_files_exist_B := true;
    end;
end;
Ein Therapeut entspricht 1024 Gigapeut.

Geändert von himitsu ( 6. Jul 2022 um 13:43 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:21 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