Autor Beitrag
seoman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 19.05.04 19:57 
Hallo,

also,
da funktioniert mal wieder etwas nicht wie ich es will. :roll:

Und zwar habe ich ein ClientDataSet mit 2 Spalten.
Meinetwegen:
ausblenden Quelltext
1:
2:
ClientDataSet.FieldByName('Spalte1').AsString := '1,4'
ClientDataSet.FieldByName('Spalte2').AsString := '4,5,6'


Nun gebe ich in einer neuen Zeile folgende Werte ein:
Feld1: 1,2
Feld2: 5,6,7

Nun soll mein BeforePost-Ereignis erkennen,
dass das einige Werte schon vorhanden sind.

Es soll mir die Zeilen mixen,
und als Ergebniszeile erwünsche ich mir dann:

Feld1: 1,2,4
Feld2: 4,5,6,7

Ich bin sicher,
ihr könnt mir da irgendwie weiterhelfen!!? :wink:

thanxx
-seoman
seoman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 19.05.04 20:44 
Wäre auch schon froh
um irgend einen kleinen Tipp.
Vielleicht eine Funktion,
die hilfreich sein könnte...? :eyes:

-seoman
seoman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Do 20.05.04 09:01 
also...einen Vorschlag hätte ich ja,
aber der scheint mir noch ein wenig umständlich:

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:
102:
103:
104:
105:
106:
[...]
procedure Tform1.MixDuplicates(NewCell1, NewCell2: String);
var
  strExistingCell1,
  strExistingCell2
    : String;
  arrstrExistingWords1,
  arrstrExistingWords2,
  arrstrNewWords1,
  arrstrNewWords2
    : Array of String;
  intRowCounter,
  intWordNumber,
  intCounter1,
  intCounter2
    : Integer;
begin
  intRowCounter := 0;
  for intRowCounter to ClientDataSet.RecordCount 
  do begin

    // Zellen in Variablen laden
   strExistingCell1 := ClientDataSet.FieldByName('Spalte1').AsString;
   strExistingCell2 := ClientDataSet.FieldByName('Spalte2').AsString;

    // einzelne Wörter aus Variable1 in Array laden (markantes Zeichen ist ',')
    intWordNumber := 0
    while not (Length(strExistingCell1) = 0)
    do begin
      arrstrExistingWords1[intWordNumber] := Copy(strExistingCell1,1,(Pos(',',strExistingCell1)-1));
      Delete(strExistingCell1,1,Pos(',',strExistingCell1); // kopiertes Wort incl. Komma löschen
      intWordNumber := intWordNumber+1
    end;

    // einzelne Wörter aus Variable2 in Array laden (markantes Zeichen ist ',')
    intWordNumber := 0;
    while not (Length(strExistingCell2) = 0)
    do begin
      arrstrExistingWords2[intWordNumber] := Copy(strExistingCell2,1,(Pos(',',strExistingCell2)-1));
      Delete(strExistingCell2,1,Pos(',',strExistingCell2); // kopiertes Wort incl. Komma löschen
      intWordNumber := intWordNumber+1
    end;

    // einzelne Wörter aus Parameter1 in Array laden (markantes Zeichen ist ',')
    intWordNumber := 0;
    while not (Length(strNewCell1) = 0)
    do begin
      arrstrNewWords1[intWordNumber] := Copy(strNewCell1,1,(Pos(',',strNewCell1)-1));
      Delete(strNewCell1,1,Pos(',',strNewCell1); // kopiertes Wort incl. Komma löschen
      intWordNumber := intWordNumber+1
    end;

    // einzelne Wörter aus Parameter2 in Array laden (markantes Zeichen ist ',')
    intWordNumber := 0;
    while not (Length(strNewCell2) = 0)
    do begin
      arrstrNewWords2[intWordNumber] := Copy(strNewCell2,1,(Pos(',',strNewCell2)-1));
      Delete(strNewCell2,1,Pos(',',strNewCell2); // kopiertes Wort incl. Komma löschen
      intWordNumber := intWordNumber+1
    end;

    // Arrays1 vergleichen
    NewCell1 := '';
    intCounter1 := 0;
    intCounter2 := 0;
    for intCounter1 to (Length(arrstrNewWords1)-1)
    do begin
      if arrstrNewWords1[intCounter1] = arrstrExistingWords1[intCounter2] // wenn Wörter gleich
      then begin
        intCounter1 := intCounter1+1
        intCounter2 := 0;
      end
       else begin                                                         // wenn Wörter ungleich
         if intCounter2 = (Length(arrstrExistingWords1)-1)                // und letzte Zeile erreicht
         then NewCell1 := NewCell1+','+arrstrNewWords1[intCounter1]       // Wort nach ',' hinzufügen  
          else intCounter2 := intCounter2+1;                              // ansonsten nächsten exististente Wort
       end;
    end;

    // Arrays2 vergleichen
    NewCell2 := '';
    intCounter1 := 0;
    intCounter2 := 0;
    for intCounter1 to (Length(arrstrNewWords2)-1)
    do begin
      if arrstrNewWords2[intCounter1] = arrstrExistingWords2[intCounter2] // wenn Wörter gleich
      then begin
        intCounter1 := intCounter1+1
        intCounter2 := 0;
      end
       else begin                                                         // wenn Wörter ungleich
         if intCounter2 = (Length(arrstrExistingWords2)-1)                // und letzte Zeile erreicht
         then NewCell2 := NewCell2+','+arrstrNewWords2[intCounter1]       // Wort nach ',' hinzufügen  
          else intCounter2 := intCounter2+1;                              // ansonsten nächsten exististente Wort
       end;
    end;

    // Zur Zelle hinzufügen
    ClientDataSet.Edit;
    ClientDataSet.FieldByName('Spalte1').AsString := ClientDataSet.FieldByName('Spalte1').AsString+strNewCell1;
    ClientDataSet.FieldByName('Spalte2').AsString := ClientDataSet.FieldByName('Spalte2').AsString+strNewCell2; 
    ClientDataSet.Post;

    ClientDataSet.Next;
  end{ Ende for-Schleife }
end;


Wäre froh,
um Verbesserungen und Kritik!! :roll:

thanxx
-seoman