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 Items einer CheckListBox mit Strings eines Memos abgleichen (https://www.delphipraxis.net/54338-items-einer-checklistbox-mit-strings-eines-memos-abgleichen.html)

kingflo 2. Okt 2005 11:48


Items einer CheckListBox mit Strings eines Memos abgleichen
 
Hallo erstmal...

Ich bräuchte leider etwas hilfe. Ich möchte gerne die prüfen, welche strings in Memo4 stehen, und wenn ein String von memo4 auch als Item in einer ChecklistBox existiert, dann soll dieses Item auf checked gesetzt werden.
Aber ich bekomme das Irgendwie net so hin.
Ich habe schon tausend mal meine Schleifen um strukturiert aber es klappt nicht.
der letzte Versuch sah so aus.
Code:
 i:=0; y:=0;
 while i<=AssoBox.Items.Count-1 do
 begin

  while y <=memo4.Lines.Count-1  do
  begin
    if AssoBox.Items.Strings[i]=memo4.Lines.Strings[y] then
    assoBox.Checked[i]:=true;
    y:=y+1;
  end;

  i:=i+1;
 end;

Sharky 2. Okt 2005 11:54

Re: Items einer CheckListBox mit Strings eines Memos abgleic
 
Hai kingflo,

ich würde das so machen:
Delphi-Quellcode:
procedure TForm1.btn_TestClick(Sender: TObject);
var
  ndx : integer;
  index : integer;
begin
  for ndx := 0 to Pred(CheckListBox1.Count) do // Alles auf UnChecked
  begin
    CheckListBox1.Checked[ndx] := False;
  end;

  for ndx := 0 to Pred(mem_Memo1.Lines.Count) do // Alle Zeilen des Memos
  begin
    index := CheckListBox1.Items.IndexOf(mem_Memo1.Lines[ndx]);
    if (index <> -1) then
    begin
      CheckListBox1.Checked[index] := True;
    end;
  end;
end;
Oder noch einfacher
Delphi-Quellcode:
procedure TForm1.btn_Test2Click(Sender: TObject);
var
  ndx : integer;
begin
  for ndx := 0 to Pred(CheckListBox1.Count) do
  begin
    CheckListBox1.Checked[ndx] := mem_Memo1.Lines.IndexOf(CheckListBox1.Items[ndx]) <> -1;
  end;
end;

kingflo 2. Okt 2005 11:59

Re: Items einer CheckListBox mit Strings eines Memos abgleic
 
cool danke so gehts....

Sharky 2. Okt 2005 12:00

Re: Items einer CheckListBox mit Strings eines Memos abgleic
 
Zitat:

Zitat von kingflo
cool danke so gehts....

Guckst Du das UpDate ;-)


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:58 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz