Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Items aus einem Memo-feld sortieren (https://www.delphipraxis.net/73210-items-aus-einem-memo-feld-sortieren.html)

phoffi1 13. Jul 2006 17:14


Items aus einem Memo-feld sortieren
 
Hallo,

es geht um folgendes:
Ich habe ein Memo-Feld mit verschiedenen Seriennummern:

z.B.:

|--------|
| E604 |
| E603 |
| E609 |
| E603 |
| E609 |
| E612 |
| E642 |
| E604 |
| E603 |
| E612 |
|--------|

Nun möchte ich die Seriennummern sortieren, sodass jede Seriennummer nur einmal vorkommt.
Dies soll dann in einem zweiten Memo-Feld ausgegeben werden.
Das würde dann z.B. so aussehen:

|--------|
| E603 |
| E604 |
| E609 |
| E612 |
| E642 |
|--------|


Ich hab schon vieles probiert aber brauche Hilfe.
Danke
Patrick

Klaus01 13. Jul 2006 17:19

Re: Items aus einem Memo-feld sortieren
 
Aus der Hilfe von TStringList:

Zitat:

Specifies whether duplicate strings can be added to sorted lists.

property Duplicates: TDuplicates;

Description

Set Duplicates to specify what should happen when an attempt is made to add a duplicate string to a sorted list. The CaseSensitive property controls whether two strings are considered duplicates if they are identical except for differences in case.

The value of Duplicates should be one of the following.

Value Meaning

dupIgnore Ignore attempts to add duplicate strings to the list.
dupError Raise an EStringListError exception when an attempt is made to add duplicate strings to the sorted list.
dupAccept Permit duplicate strings in the sorted list.

Set Duplicates before adding any strings to the list. Setting Duplicates to dupIgnore or dupError does nothing about duplicate strings that are already in the list.

Note: Duplicates does nothing if the list is not sorted.


Da kannst Du die Zeilen des Memofeldes in eine StringList übertragen.
Die Stringlist dann wieder in das Memofeld schreiben.
Ob sich das Ausfiltern direkt im Memo machen läßt weiß ich nicht.

Grüße
Klaus

semo 13. Jul 2006 17:26

Re: Items aus einem Memo-feld sortieren
 
à la Klaus01: (bzw. für die Französischkenner unter euch "à le Klaus01" *g*):
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  aSL: TStringList;
begin
  aSL := TStringList.Create;
  aSL.Sorted := true;
  aSL.Duplicates := dupAccept;
  aSL.Assign(Memo1.Lines);

  Memo1.Lines.Assign(aSL);

  aSL.Free;
end;
im Memo direkt sortieren ist nicht möglich,
die Stringlist ist ja extra dafür geschaffen worden um TStrings sortieren zu können.

phoffi1 13. Jul 2006 17:34

Re: Items aus einem Memo-feld sortieren
 
Danke, hat alles geklappt.


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:32 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