Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Lisbox History - Problemchen (https://www.delphipraxis.net/53125-lisbox-history-problemchen.html)

turboPASCAL 10. Sep 2005 19:41


Lisbox History - Problemchen
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hi, nu hab ich auch mal wieder ein kleines Problemchen...

...Ich habe ein kleines Programm erstellt (na so was ;)) mit einer Listbox in der ich eine History, äh Verlauf eingebaut habe:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Clear;
 
  if ComboBox1.Text <> '' then
  begin
    RunConsoleApp(ComboBox1.Text, Memo1.Lines);

    // Historie
    if ComboBox1.Text <> ComboBox1.Items[0] then
    begin
      ComboBox1.Items.Insert(0, ComboBox1.Text);

      if ComboBox1.Items.Count > 5 then
        ComboBox1.Items.Delete(ComboBox1.Items.Count-1);
    end;
  end;
end;
...das funktioniert soweit ganz gut, aber wenn ich den letzten Eintrag aus der Liste aufrufe dann verschwindet in der Eingabezeile mein Text nachdem ich den "Start" Button gedrückt habe.

Ich finde das Problem nicht, kann es jemand finden ?

marabu 10. Sep 2005 20:20

Re: Lisbox History - Problemchen
 
Hi Matti,

Zitat:

Zitat von turboPASCAL
Ich finde das Problem nicht

dann ist ja alles in Ordnung.

Um dein Problem zu verstehen müsste man wissen, ob du mit den Standardeinstellungen der ComboBox arbeitest, aus welchem EventHandler dein Code stammt, etc.

Die einfache history Funktionalität finde ich nicht so berauschend - mit einer kleinen Erweiterung erhalte ich eine MRU Funktionalität (most recently used):

Delphi-Quellcode:
const
  MAX_HISTORY = 5;

procedure TDemoForm.ComboBoxKeyPress(Sender: TObject; var Key: Char);
var
  index: integer;
begin
  if Key = Chr(VK_RETURN) then
    with Sender as TComboBox do
    begin
      // no duplicates
      index := Items.IndexOf(Text);
      if index > -1 then
        Items.Delete(index);
      // store new item
      Items.Insert(0, Text);
      // watch for limit
      if Items.Count > MAX_HISTORY then
        Items.Delete(MAX_HISTORY);
    end;
end;
Grüße vom marabu

turboPASCAL 10. Sep 2005 20:29

Re: Lisbox History - Problemchen
 
So, habe den Code oden vervollständigt.

Werde mir morgen mal deine Version zu gemüte führen, für heute mach ich erst mal schluss mit Delphi. Thx.

(habe mir meine Esc-Taste abgebrochen... :wall: )


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:19 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 by Thomas Breitkreuz