AGB  ·  Datenschutz  ·  Impressum  







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

Variablen Massenhaft definieren

Ein Thema von Kegasetu · begonnen am 20. Okt 2020 · letzter Beitrag vom 22. Okt 2020
Antwort Antwort
Seite 2 von 3     12 3      
Klaus01
Online

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#11

AW: Variablen Massenhaft definieren

  Alt 20. Okt 2020, 10:53
StringList ist nicht gleich StringGrid

Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat
Beach

Registriert seit: 3. Mär 2019
Ort: Hunsrück
46 Beiträge
 
FreePascal / Lazarus
 
#12

AW: Variablen Massenhaft definieren

  Alt 20. Okt 2020, 10:56
[...]
Auch den Arrays bin ich nicht unaufgeschlossen. Ich müsste nur ständig eine Liste parat haben, an der ich ablesen kann, welche Stelle für was steht.
[...]
Ich bin zwar mit Lazarus unterwegs, aber bei Delphi wird es bestimmt vergleichbar sein.
Mir kommt da der Begriff "sprechende variablen" und, wenn ich mich richtig erinnere, "enumerated Types" (?¿) in den Kopf.

Ein Beispiel
Code:
  DataLoaded_keys: (cfg, xpc, ypc, zpc);
  DataLoaded: array[cfg..zpc] of boolean;
Das Array kann ich dann "sprechend" mit DataLoaded[xpc], als Beispiel, verwenden und gibt mir dann den boolschen Hinweis ob die Daten geladen wurden oder nicht.
Es "liest" sich recht eindeutig was man gerade macht. Geht auch mit mehrdimensionalen Arrays.

Die Spezialisten hier können das bestimmt korrigieren und besser erklären.
MfG Jürgen
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#13

AW: Variablen Massenhaft definieren

  Alt 20. Okt 2020, 11:04
Wenn ich mir das Bild anschaue, würde ich mir ein Array mit Typ Record erschaffen die dann ComboBox.Index <Bauteil> gleich sind.
Das Record mit dementsprechend viele Strings bereitstellen (Konvertierung StrToInt/IntToStr würde ich da raushalten)
Bei <Abschnitt> habe ich keine Ahnung was da passiert, also lasse ich das mal außen vor.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
Kegasetu

Registriert seit: 26. Sep 2013
85 Beiträge
 
#14

AW: Variablen Massenhaft definieren

  Alt 20. Okt 2020, 11:18
Ich bedanke mich eure Hilfe. Ich nehme mir jetzt mal etwas Zeit zum experimentieren und melde mich später oder morgen nochmal.
  Mit Zitat antworten Zitat
Kegasetu

Registriert seit: 26. Sep 2013
85 Beiträge
 
#15

AW: Variablen Massenhaft definieren

  Alt 20. Okt 2020, 13:56
In mühefolster Kleinarbeit enstand in den letzten Stunden ein Gemisch aus vielen Arrays (ca. 100) und Variablen (ca. 150).
Aber es funktioniert.

Die Idee mit der Liste war gut, ich habe mich für ein Stringgrid entschieden.
  Mit Zitat antworten Zitat
Benutzerbild von holger_barntrup
holger_barntrup

Registriert seit: 1. Feb 2007
Ort: Barntrup
97 Beiträge
 
Delphi 10.4 Sydney
 
#16

AW: Variablen Massenhaft definieren

  Alt 21. Okt 2020, 05:39
Zeig doch mal wie du das gemacht hast bitte.
Gruß Holger
  Mit Zitat antworten Zitat
Kegasetu

Registriert seit: 26. Sep 2013
85 Beiträge
 
#17

AW: Variablen Massenhaft definieren

  Alt 21. Okt 2020, 06:30
Das ist der Befehl zum speichern



Delphi-Quellcode:
procedure TForm2.Button1Click(Sender: TObject);
var i,t,k: integer;
begin

lab5[Combobox1.ItemIndex*ComboBox1.ItemIndex]:= 'Morsch'; //für später

if ((ComboBox1.ItemIndex = 0) and (ComboBox2.ItemIndex = 0)) then
begin
 mb1a1 := strtofloat(edit1.Text);
  l1a1 := strtofloat(edit2.Text);
ewb1a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b1a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz1a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 1) and (ComboBox2.ItemIndex = 0)) then
begin
 mb2a1 := strtofloat(edit1.Text);
  l2a1 := strtofloat(edit2.Text);
ewb2a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b2a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz2a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 2) and (ComboBox2.ItemIndex = 0)) then
begin
 mb3a1 := strtofloat(edit1.Text);
  l3a1 := strtofloat(edit2.Text);
ewb3a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b3a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz3a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 3) and (ComboBox2.ItemIndex = 0)) then
begin
 mb4a1 := strtofloat(edit1.Text);
  l4a1 := strtofloat(edit2.Text);
ewb4a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b4a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz4a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 4) and (ComboBox2.ItemIndex = 0)) then
begin
 mb5a1 := strtofloat(edit1.Text);
  l5a1 := strtofloat(edit2.Text);
ewb5a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b5a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz5a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 5) and (ComboBox2.ItemIndex = 0)) then
begin
 mb6a1 := strtofloat(edit1.Text);
  l6a1 := strtofloat(edit2.Text);
ewb6a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b6a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz6a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 6) and (ComboBox2.ItemIndex = 0)) then
begin
 mb7a1 := strtofloat(edit1.Text);
  l7a1 := strtofloat(edit2.Text);
ewb7a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b7a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz7a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 7) and (ComboBox2.ItemIndex = 0)) then
begin
 mb8a1 := strtofloat(edit1.Text);
  l8a1 := strtofloat(edit2.Text);
ewb8a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b8a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz8a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 8) and (ComboBox2.ItemIndex = 0)) then
begin
 mb9a1 := strtofloat(edit1.Text);
  l9a1 := strtofloat(edit2.Text);
ewb9a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b9a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz9a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 9) and (ComboBox2.ItemIndex = 0)) then
begin
 mb10a1 := strtofloat(edit1.Text);
  l10a1 := strtofloat(edit2.Text);
ewb10a1 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b10a1[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz10a1[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 0) and (ComboBox2.ItemIndex = 1)) then
begin
 mb1a2 := strtofloat(edit1.Text);
  l1a2 := strtofloat(edit2.Text);
ewb1a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b1a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz1a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 1) and (ComboBox2.ItemIndex = 1)) then
begin
 mb2a2 := strtofloat(edit1.Text);
  l2a2 := strtofloat(edit2.Text);
ewb2a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b2a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz2a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 2) and (ComboBox2.ItemIndex = 1)) then
begin
 mb3a2 := strtofloat(edit1.Text);
  l3a2 := strtofloat(edit2.Text);
ewb3a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b3a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz3a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 3) and (ComboBox2.ItemIndex = 1)) then
begin
 mb4a2 := strtofloat(edit1.Text);
  l4a2 := strtofloat(edit2.Text);
ewb4a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b4a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz4a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 4) and (ComboBox2.ItemIndex = 1)) then
begin
 mb5a2 := strtofloat(edit1.Text);
  l5a2 := strtofloat(edit2.Text);
ewb5a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b5a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz5a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 5) and (ComboBox2.ItemIndex = 1)) then
begin
 mb6a2 := strtofloat(edit1.Text);
  l6a2 := strtofloat(edit2.Text);
ewb6a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b6a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz6a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 6) and (ComboBox2.ItemIndex = 1)) then
begin
 mb7a2 := strtofloat(edit1.Text);
  l7a2 := strtofloat(edit2.Text);
ewb7a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b7a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz7a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 7) and (ComboBox2.ItemIndex = 1)) then
begin
 mb8a2 := strtofloat(edit1.Text);
  l8a2 := strtofloat(edit2.Text);
ewb8a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b8a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz8a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 8) and (ComboBox2.ItemIndex = 1)) then
begin
 mb9a2 := strtofloat(edit1.Text);
  l9a2 := strtofloat(edit2.Text);
ewb9a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b9a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz9a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 9) and (ComboBox2.ItemIndex = 1)) then
begin
 mb10a2 := strtofloat(edit1.Text);
  l10a2 := strtofloat(edit2.Text);
ewb10a2 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b10a2[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz10a2[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;
if ((ComboBox1.ItemIndex = 0) and (ComboBox2.ItemIndex = 2)) then
begin
 mb1a3 := strtofloat(edit1.Text);
  l1a3 := strtofloat(edit2.Text);
ewb1a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b1a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz1a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 1) and (ComboBox2.ItemIndex = 2)) then
begin
 mb2a3 := strtofloat(edit1.Text);
  l2a3 := strtofloat(edit2.Text);
ewb2a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b2a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz2a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 2) and (ComboBox2.ItemIndex = 2)) then
begin
 mb3a3 := strtofloat(edit1.Text);
  l3a3 := strtofloat(edit2.Text);
ewb3a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b3a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz3a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 3) and (ComboBox2.ItemIndex = 2)) then
begin
 mb4a3 := strtofloat(edit1.Text);
  l4a3 := strtofloat(edit2.Text);
ewb4a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b4a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz4a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 4) and (ComboBox2.ItemIndex = 2)) then
begin
 mb5a3 := strtofloat(edit1.Text);
  l5a3 := strtofloat(edit2.Text);
ewb5a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b5a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz5a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 5) and (ComboBox2.ItemIndex = 2)) then
begin
 mb6a3 := strtofloat(edit1.Text);
  l6a3 := strtofloat(edit2.Text);
ewb6a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b6a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz6a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 6) and (ComboBox2.ItemIndex = 2)) then
begin
 mb7a3 := strtofloat(edit1.Text);
  l7a3 := strtofloat(edit2.Text);
ewb7a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b7a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz7a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 7) and (ComboBox2.ItemIndex = 2)) then
begin
 mb8a3 := strtofloat(edit1.Text);
  l8a3 := strtofloat(edit2.Text);
ewb8a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b8a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz8a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 8) and (ComboBox2.ItemIndex = 2)) then
begin
 mb9a3 := strtofloat(edit1.Text);
  l9a3 := strtofloat(edit2.Text);
ewb9a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b9a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz9a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 9) and (ComboBox2.ItemIndex = 2)) then
begin
 mb10a3 := strtofloat(edit1.Text);
  l10a3 := strtofloat(edit2.Text);
ewb10a3 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b10a3[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz10a3[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;
if ((ComboBox1.ItemIndex = 0) and (ComboBox2.ItemIndex = 3)) then
begin
 mb1a4 := strtofloat(edit1.Text);
  l1a4 := strtofloat(edit2.Text);
ewb1a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b1a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz1a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 1) and (ComboBox2.ItemIndex = 3)) then
begin
 mb2a4 := strtofloat(edit1.Text);
  l2a4 := strtofloat(edit2.Text);
ewb2a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b2a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz2a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 2) and (ComboBox2.ItemIndex = 3)) then
begin
 mb3a4 := strtofloat(edit1.Text);
  l3a4 := strtofloat(edit2.Text);
ewb3a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b3a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz3a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 3) and (ComboBox2.ItemIndex = 3)) then
begin
 mb4a4 := strtofloat(edit1.Text);
  l4a4 := strtofloat(edit2.Text);
ewb4a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b4a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz4a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 4) and (ComboBox2.ItemIndex = 3)) then
begin
 mb5a4 := strtofloat(edit1.Text);
  l5a4 := strtofloat(edit2.Text);
ewb5a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b5a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz5a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 5) and (ComboBox2.ItemIndex = 3)) then
begin
 mb6a4 := strtofloat(edit1.Text);
  l6a4 := strtofloat(edit2.Text);
ewb6a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b6a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz6a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 6) and (ComboBox2.ItemIndex = 3)) then
begin
 mb7a4 := strtofloat(edit1.Text);
  l7a4 := strtofloat(edit2.Text);
ewb7a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b7a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz7a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 7) and (ComboBox2.ItemIndex = 3)) then
begin
 mb8a4 := strtofloat(edit1.Text);
  l8a4 := strtofloat(edit2.Text);
ewb8a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b8a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz8a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 8) and (ComboBox2.ItemIndex = 3)) then
begin
 mb9a4 := strtofloat(edit1.Text);
  l9a4 := strtofloat(edit2.Text);
ewb9a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b9a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz9a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;

if ((ComboBox1.ItemIndex = 9) and (ComboBox2.ItemIndex = 3)) then
begin
 mb10a4 := strtofloat(edit1.Text);
  l10a4 := strtofloat(edit2.Text);
ewb10a4 := strtofloat(edit3.Text);
k:= 1;
  for i := 1 to 4 do
      for t := 1 to 13 do
      begin
          b10a4[k] := strtofloat(stringgrid1.Cells[i,t]);
          bz10a4[k] := stringgrid1.Cells[0,t];
        k:=k+1;
      end;
end;


end;
  Mit Zitat antworten Zitat
Jumpy

Registriert seit: 9. Dez 2010
Ort: Mönchengladbach
1.733 Beiträge
 
Delphi 6 Enterprise
 
#18

AW: Variablen Massenhaft definieren

  Alt 21. Okt 2020, 09:28
Wenn mb,l,ewb als 2-dimensionale Arrays angelegt wären, könnte man schreiben:

Delphi-Quellcode:
 mb[ComboBox1.ItemIndex,ComboBox2.ItemIndex] := strtofloat(edit1.Text);
 l[ComboBox1.ItemIndex,ComboBox2.ItemIndex] := strtofloat(edit2.Text);
 ewb[ComboBox1.ItemIndex,ComboBox2.ItemIndex] := strtofloat(edit3.Text);
Wenn dann b und bz 4-dimensionale Array wären und man die Schleifenreihenfolge umdreht könnte man k weglassen und schreiben
Delphi-Quellcode:
  for t := 1 to 13 do
    begin
    bz[ComboBox1.ItemIndex,ComboBox2.ItemIndex,0,t] := stringgrid1.Cells[0,t];
    for i := 1 to 4 do
      begin
          b[ComboBox1.ItemIndex,ComboBox2.ItemIndex,i,t] := strtofloat(stringgrid1.Cells[i,t]);
      end;
    end;
Oder Alternativ ein 3-dimensionales Array mit k, wobei man k statt hochzuzählen auch aus i und t berechnen könnte (k:=t+(i-1)*13).
Auf jeden Fall hätte man sich viel Code gespart.
Ralph

Geändert von Jumpy (21. Okt 2020 um 09:32 Uhr)
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
3.908 Beiträge
 
Delphi 12 Athens
 
#19

AW: Variablen Massenhaft definieren

  Alt 21. Okt 2020, 12:23
Die Idee mit der Liste war gut, ich habe mich für ein Stringgrid entschieden.
Ja das Grid ist wohl die richtige Entscheidung, wenn es um Unmengen an Variablen zur Eingabe geht
(siehe Excel).
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

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

AW: Variablen Massenhaft definieren

  Alt 21. Okt 2020, 13:50
Delphi-Quellcode:
uses
  System.SysConst, System.SysUtils;

type
  // bei uralten Delphi z.B. als "TEdit = class(StdCtrls.TEdit)" über die TForm1-Deklaration
  TEditHelper = class helper for TEdit
  strict private
    function GetFloat: Float;
    procedure SetFloat(Value: Float);
  public
    property AsFloat: Float read GetFloat write SetFloat;
  end;

function TEditHelper.GetFloat: Float;
{begin
  Result := StrToFloat(Self.Text);
end;}

begin
  it not TryStrToFloat(Self.Text, Result) then begin
    if Self.CanFocus then
      Self.SetFocus;
    raise EConvertError.CreateFmt('%s: ' + LoadStr(@SInvalidFloat), [Self.Name, Self.Text]);
  end;
end;

procedure TEditHelper.SetFloat(Value: Float);
begin
  Self.Text := FloatToStr(Value); // oder Format oder sonstwas
end;
Dann gibst du deinen Edits endlich mal ordentliche Namen und lässt das scheinbar nutzlose Umkopieren sein (von KeineAhnungEdit in SoLalaVariable).

Statt StrToFloat(Edit1.Text) ein la4.AsFloat , oder vielleicht mit einem noch "verständlicherem" Namen.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 3     12 3      


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 11:46 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