Thema: Delphi Probleme beim sortieren

Einzelnen Beitrag anzeigen

Benutzerbild von SnuffMaster23
SnuffMaster23

Registriert seit: 13. Feb 2006
Ort: Kempten
253 Beiträge
 
#4

Re: Probleme beim sortieren

  Alt 11. Mär 2006, 08:50
Hi Leute,

ich habs jetzt (ganz) anders gemacht:

Mit diesen Typen/Variablen...
Delphi-Quellcode:
type

  TIconInfo = record
    Size : Word;
    BitCount: Byte;
  end;


var
  IconInfos : array[Byte] of TIconInfo;
  IconCount : Integer;
...diese (hardgecodete) Liste...
Delphi-Quellcode:
  IconInfos[0].Size := 100;
  IconInfos[0].BitCount := 8;
  IconInfos[1].Size := 16;
  IconInfos[1].BitCount := 4;
  IconInfos[2].Size := 48;
  IconInfos[2].BitCount := 8;
  IconInfos[3].Size := 32;
  IconInfos[3].BitCount := 3;
  IconInfos[4].Size := 16;
  IconInfos[4].BitCount := 8;
  IconInfos[5].Size := 48;
  IconInfos[5].BitCount := 4;
  IconInfos[6].Size := 32;
  IconInfos[6].BitCount := 4;
  IconInfos[7].Size := 32;
  IconInfos[7].BitCount := 24;
  IconInfos[8].Size := 16;
  IconInfos[8].BitCount := 24;
  IconInfos[9].Size := 16;
  IconInfos[9].BitCount := 7;
  IconInfos[10].Size := 32;
  IconInfos[10].BitCount := 8;
  IconInfos[11].Size := 48;
  IconInfos[11].BitCount := 24;

  IconCount := 12;
...mit diesem Code sortieren:
Delphi-Quellcode:
function SortList(var IconList: array of TIconInfo): TStrings;
var
  i, j, min: Integer;
  SwBuffer : TIconInfo;
  List : TStringList;
  StrBuffer: string;
begin
  List := TStringList.Create;
  for i := 0 to IconCount - 2 do //
  begin // Array sortieren
    min := i; //
    for j := i + 1 to IconCount - 1 do //
      if (IconList[j].Size shl 8 or IconList[j].BitCount) < (IconList[min].Size shl 8 or IconList[min].BitCount) then
        min := j; //
    if min <> i then //
    begin //
      SwBuffer := IconList[i]; //
      IconList[i] := IconList[min]; //
      IConList[min] := SwBuffer; //
    end; //
  end; //

  for i := 0 to IconCount - 1 do //
  begin // sortierte Liste ausgabefähig machen
    StrBuffer := IntToStr(IconList[i].Size) + ' x ' + IntToStr(IconList[i].Size) + ' - '; // (In StrngList umwandeln)
    case IconList[i].BitCount of //
      0..8: StrBuffer := StrBuffer + IntToStr(Round(Power(2, IconList[i].BitCount))) + ' Farben'; //
      24 : StrBuffer := StrBuffer + '24 bpp'; //
      else StrBuffer := StrBuffer + '?? Farben'                                                       //
    end; //
    List.Add(StrBuffer); //
  end; //
  Result := List;
end;
Delphi-Quellcode:
procedure TForm1.ListBox1Click(Sender: TObject);
begin
  Listbox1.Items.Assign(SortList(IconInfos));
end;
Das Programm kann mit den Daten dies hier sortiert viel mehr anfangen als mit den Strings . Außerdem hab ich so alles auf einmal sortiert.
"Conspiracy is the poor man's mapping of the world" - Fredric Jameson
  Mit Zitat antworten Zitat