Autor Beitrag
Krefti
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Fr 16.05.08 14:52 
hi zusammen

hab eine kurze frage:

ich habe mir ein Record mit mehreren unterschiedlichen Datentypen. Davon hab ich mir wiederum einen Array abgeleitet.

Nun schreibe ich Daten von einem Messgerät rüber, dieser gibt mir aber zuerst den neusten Wert. Wie kann ich dass Array sortieren oder umgedreht auslesen??

bis jetzt les ich es so aus, schreibe es in mein Memo feld und speicher es in dass jeweilige recordfeld. aus diesem recordfeld speicher ich es dann in ein stringgrid, nur leider in der falschen reihenfolge. könnt ihr mir bitte helfen??

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
   Memo.Lines.Add('X-Werte');
   for I := 0 to IAnzahl -1 do                  //x werte übertragen
   begin
       Com.PutStringext('Hx'+inttostr(i)+',i');
       Com.getString(Ergebnis,okay);
       Memo.Lines.Add(Ergebnis);
       MeineWerte[i].XWert := StrTofloat(Ergebnis);

           // y,z,s werte genau so..
   end;

..
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
   for I := 1 to IAnzahl   do        // von eins bis anzahl,erste reihe string grid(0)  überschrift                                                           
    begin
       x := MeineWerte[i-1].XWert;
       y := MeineWerte[i-1].YWert;
       z := MeineWerte[i-1].ZWert;
       s := MeineWerte[i-1].SWert;

       if inifWerte.Einheit = '[dB]' then                 //Wenn Einheit [dB] ausgewählt
       begin

         sgTabelle.Cells[0,i] := inttostr(i);             // laufende Nummer

         sgTabelle.Cells[1,i] := floattostr(x);     //X-Werte in Tabelle

         sgTabelle.Cells[2,i] := floattostr(y);     //Y-Werte in Tabelle

         sgTabelle.Cells[3,i] := floattostr(z);     //Z-Werte in Tabelle

         sgTabelle.Cells[4,i] := floattostr(s);     //S-Werte in Tabelle
       end;


vielen dank schon mal für eure hilfe.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 16.05.08 15:05 
Meinst du jetzt einfach for I := IAnzahl - 1 downto 0 do, oder hab ich da was komplizierteres übersehen? :gruebel:

_________________
We are, we were and will not be.
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Fr 16.05.08 15:19 
user profile iconGausi hat folgendes geschrieben:
Meinst du jetzt einfach for I := IAnzahl - 1 downto 0 do, oder hab ich da was komplizierteres übersehen? :gruebel:



so was ähnliches, als ich möchte halt, dass der letzte der erste wert ist und der 2. der vorletzte..weißt was ich mein?? funktioniert des mit dem downto??
gispos
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 94

WIN 7
XE10, D2007
BeitragVerfasst: Fr 16.05.08 15:49 
Ja

Hab aber auch ein Beispiel für ein Quick-Sort von Arrays, hatte mir das mal
geschrieben. Musst es aber evt. an deine Bedürfnisse anpassen.
Start = 0; Count = High(Array)
Beispiel: QuickSort(BWA, 0, High(BWA));
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
type
  TBaseWideArray = Array of packed record
    WS: WideString;
  end;

procedure Exchange(BWA: TBaseWideArray; Index1, Index2: Integer);
var
  Temp: Integer;
  Item1: Integer;
begin
  Item1 := Integer(BWA[Index1].WS);
  Temp := item1;
  Integer(BWA[Index1].WS) := Integer(BWA[Index2].WS);
  Integer(BWA[Index2].WS) := Temp;
end;

procedure QuickSort(BWA: TBaseWideArray; Start, Count: Integer);
var
  I, J, P: Integer;
begin
  repeat
    I := Start;
    J := Count;
    P := (Start + Count) shr 1;
    repeat
      while WideCompareText(BWA[I].WS, BWA[P].WS) < 0 do Inc(I);
      while WideCompareText(BWA[J].WS, BWA[P].WS) > 0 do Dec(J);
      if I <= J then
      begin
        Exchange(BWA, I, J);
        if P = I then
          P := J
        else if P = J then
          P := I;
        Inc(I);
        Dec(J);
      end;
    until I > J;
    if Start < J then QuickSort(BWA, Start, J);
    Start := I;
  until I >= Count;
end;


Gruß gispos
Fabian E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: Sa 17.05.08 15:29 
user profile iconKrefti hat folgendes geschrieben:
user profile iconGausi hat folgendes geschrieben:
Meinst du jetzt einfach for I := IAnzahl - 1 downto 0 do, oder hab ich da was komplizierteres übersehen? :gruebel:



so was ähnliches, als ich möchte halt, dass der letzte der erste wert ist und der 2. der vorletzte..weißt was ich mein?? funktioniert des mit dem downto??


Also mit downto kannst du zwar das Array nicht "umdrehen" aber du kannst dir es falschherum ausgeben lassen.

Mit
ausblenden Delphi-Quelltext
1:
2:
for i := 9 downto 0 do
  DoSomething(Array[i]);

wird als erstes der 9te Wert ausgelesen, dann der 8te... Als letztes dann der 1te(0te).

gruß
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Mo 19.05.08 07:19 
Guten morgen..

also dieses downto wäre schon genau das richtige, was ich suche. Dabei ergibt sich jetzt aber folgendes problem: wenn ich es normal ausgebe, sprich  I := 1 to IAnzahl , dann werden die werte auch ganz normal in mein stringgrid geschrieben, wenn ich es aber umdrehen  i := IAnzahl downto 1 dann wird mit trotzdem die bisherige reihenfolge ausgegeben..

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
for I := IAnzahl downto 1  do
    begin
       x := MeineWerte[i-1].XWert;
       y := MeineWerte[i-1].YWert;
       z := MeineWerte[i-1].ZWert;
       s := MeineWerte[i-1].SWert;

       if inifWerte.Einheit = '[dB]' then                 //Wenn Einheit [dB] ausgewählt
       begin
         for w := 1 to IAnzahl do
           begin
           sgTabelle.Cells[0,i] := inttostr(i);             // laufende Nummer
           end;

         sgTabelle.Cells[1,i] := floattostr(x);     //X-Werte in Tabelle

         sgTabelle.Cells[2,i] := floattostr(y);     //Y-Werte in Tabelle

         sgTabelle.Cells[3,i] := floattostr(z);     //Z-Werte in Tabelle

         sgTabelle.Cells[4,i] := floattostr(s);     //S-Werte in Tabelle
       end;

       if inifWerte.Einheit = '[m/s²]' then                    //Wenn Einheit [dB] ausgewählt
       begin

         sgTabelle.Cells[0,i] := inttostr(i);             // laufende Nummer

          //X-Wert
         x := power(10,x / 20) * 1E-6;
         x := round(x * 100000) / 100000;

         sgTabelle.Cells[1,i] := floattostr(x);     //X-Werte in Tabelle

         //Y-Wert
         y := power(10,y / 20) * 1E-6;
         y := round(y * 100000) / 100000;

         sgTabelle.Cells[2,i] := floattostr(y);     //Y-Werte in Tabelle

         //Z-Wert
         z := power(10,z / 20) * 1E-6;
         z := round(z * 100000) / 100000;

         sgTabelle.Cells[3,i] := floattostr(z);     //Z-Werte in Tabelle

         //S-Wert
         s := power(10,s / 20) * 1E-6;
         s := round(s * 100000) / 100000;

         sgTabelle.Cells[4,i] := floattostr(s);     //S-Werte in Tabelle
       end;

       if i > 1 then                         //Rechnung Sekunden > 60
         begin
            sek := sek + mit;
         if sek >= 60 then
           begin
             restM := Round(sek div 60); // minuten errechnen
             sek := sek Mod 60;        // restliche sekunden errechnen
             min := min + restM;  // Ende Rechnung
           end;

         if min >= 60 then
         begin
           restS := Round(min div 60);  //stunden errechnen
           min := min mod 60;            //restliche minuten errechnen
           std := std + restS;
         end;

       end; //ende if i > 1       

       sekAusgabe := inttostr(sek);            //umwandlung errechneter werte in string
       minAusgabe := inttostr(min);
       stdAusgabe := inttostr(std);

      if strtoint(sekAusgabe) < 10 then           // sekunde unter 10 dann 0 hinzufügen
         begin
           sekAusgabe := '0'+sekausgabe;
         end;

       if strtoint(minAusgabe) < 10 then           // sekunde unter 10 dann 0 hinzufügen
         begin
         minAusgabe := '0'+ minAusgabe;
         end;
                                                              // Messwert Uhrzeit zusammenbasteln
       Zeit := stdAusgabe + ':' + minAusgabe + ':' + sekAusgabe  +
               ' ' + MeineWerte[i-1].Tag + '.' + MeineWerte[i-1].Monat + '.' + MeineWerte[i-1].Jahr;

       sgTabelle.Cells[5,i] := Zeit;
    end;

    sgTabelle.height := form1.Clientheight -80;   //höhe Stringgrid nach befüllen
    b0 := 50;                            // breite stringgrid nach befüllen
    b := Form1.ClientWidth - getSystemMetrics(SM_CXHThumb)-b0;
    b := b - (sgTabelle.Colcount -2) * 2   ;
    sgTabelle.colwidths[0] := b0;
    for I := 1 to 5 do
       begin
          sgTabelle.colwidths[i] := b div (sgTabelle.ColCount -1);
       end;


kann mir jemand helfen??

edit : übrigens, wenn ich den string zusammenbastel und ihn über die Zwischenablage z.B. nach word exportieren möchte, dann klappt das mit der Reihenfolgenänderung auch, aber mit dem Stringgrid leider nicht.
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Mo 19.05.08 10:26 
habs hinbekommen..thx für eure hilfe mit dem downto!!!
gruß