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 Löschen einer Ini Section über eine Listbox (https://www.delphipraxis.net/41385-loeschen-einer-ini-section-ueber-eine-listbox.html)

Grolle 2. Mär 2005 16:43


Löschen einer Ini Section über eine Listbox
 
Was ist daran nicht korrekt?
Delphi-Quellcode:
procedure TForm1.Button4Click(Sender: TObject);
begin
  ini.erasesection(ListBox1.Selected);
  ListBox1.DeleteSelected;
end;

sniper_w 2. Mär 2005 17:40

Re: Löschen einer Ini Section über eine Listbox
 
So ist es richtig.
Delphi-Quellcode:
type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    ListBox2: TListBox;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    ini : TIniFile;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
 var a:integer;
     Temp : TStringList;
begin
 Temp := TStringList.Create;
 ListBox2.Clear;
 ListBox2.Visible := falsE;
 ListBox1.Clear;
 ini.ReadSections(ListBox1.Items);
 for a:=0 to ListBox1.Count-1 do
 begin
  Temp.Clear;
  ini.ReadSectionValues( ListBox1.Items.Strings[a],Temp);
  ListBox2.Items.Add('SECTION - '+ListBox1.Items.Strings[a]);
  ListBox2.Items.AddStrings(temp);
 end;
 Temp.Free;
 ListBox2.Visible := true;
 Caption := 'Lines: '+inttostr(ListBox2.Count+ListBox1.Count);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 ini := TIniFile.Create('c:\my.ini');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
ini.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
 var selected_ : integer;
begin
 selected_ := SendMessage(ListBox1.Handle,LB_GETCURSEL,0,0);
 ini.EraseSection(ListBox1.Items.Strings[selected_]);
 ini.UpdateFile(); // only win9x
 ListBox1.Items.Delete(selected_);
end;

sniper_w 2. Mär 2005 17:44

Re: Löschen einer Ini Section über eine Listbox
 
Delphi-Quellcode:
ListBox1.Selected
Ist nicht das, was du suchst.
Denn:
Zitat:

Indicates whether a particular item is selected.

property Selected[Index: Integer]: Boolean;

Description

Use Selected to query the state of a particular item in the list box. If the item specified by the Index parameter is selected in the list box, the value of the Selected property is True. If the specified item is not selected, Selected is False. Set Selected to change the currently selected item.

The Index parameter is the item referenced by its position in the list box, with the first item having an Index value of 0.

An item is selected when the user highlights it. More than one item in the list box can be selected by setting the MultiSelect property to True. In this case, the Selected item is the one that has focus when the list box has input focus.

Grolle 2. Mär 2005 17:51

Re: Löschen einer Ini Section über eine Listbox
 
Danke...
Deine Version funktioniert einwandfrei. Kannst du mir noch kurz sagen, was
diese Zeile sagt:
selected := SendMessage(ListBox1.Handle,LB_GETCURSEL,0,0);
Will ja auch was lernen
:drunken:

Rastaman 2. Mär 2005 18:39

Re: Löschen einer Ini Section über eine Listbox
 
Das erfragt das Item das in der ListBox selectiert wurde(also den Index).
Weil bei ListBox1.Items.Strings[?] musst du ja für das ? ne zahl angeben.
Und der Sendmessagebefehl erfragt diese Zahl

mquadrat 2. Mär 2005 19:47

Re: Löschen einer Ini Section über eine Listbox
 
Also ich finde ja Listbox1.ItemIndex irgendwie handlicher ;)

sniper_w 2. Mär 2005 19:51

Re: Löschen einer Ini Section über eine Listbox
 
Zitat:

Also ich finde ja Listbox1.ItemIndex irgendwie handlicher
Nicht nur, sondern auch besser.
Aber menschlicher Gehirn ist ein kopliziertes Gerät, und manchmal kann es solche einfache Lösungen nicht sehen. :gruebel: :wall:

Rastaman 2. Mär 2005 19:54

Re: Löschen einer Ini Section über eine Listbox
 
Das kann man natürlich als unprofessionelle Alternative ansehen :wink:
Beschäftige mich haltn icht oft mit der ListBox.


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