Autor Beitrag
Sauger Chris
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: So 28.12.03 14:47 
hallo weiß einer von euch wie ich
Listbox1 und Listbox2 vergleichen kann und wenn ein Item doppelt ist soll es
in listbox3 erscheinen.

Danke

Chris(Delphi7)
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: So 28.12.03 14:53 
Hallo,

am einfachsten ist es wohl, wenn Du Dich durch die Items aus Listbox1 "durchhangelst" und dann mit jedem Item dann in
Listbox 2 mittels Indexof prüfst, ob es das Item gibt.

Wenn ja, dann fügst Du es einfach in die Listbox3 ein..
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: So 28.12.03 17:27 
Hi,
ich habe das so gemacht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
var x,i:integer;
begin
for i:= 0 to listbox1.Items.Count-1 do
  for x:= 0 to listbox2.Items.Count-1 do
   if listbox1.Items[i]=listbox2.Items[x] then
   listbox3.Items.Add(listbox2.Items[x]);
end;


MfG hibbert

Moderiert von user profile iconPeter Lustig: Code- durch Delphi-Tags ersetzt

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 28.12.03 17:36 
es geht noch andres:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function LöscheMirDieDoppeltenItems;
var
  i:Integer;
begin
  for i:=0 to ListBox1.items.Count-1 do begin
    if ListBox2.Items.IndexOf( Listbox1.Items[i] ) > 0 then
      ListBox3.Items.Add(ListBox2.Items[i]);
  end;
end;

macht das gleich wie von hibbert nur auf einen andern weg und dürfte auch "etwas" schneller sein, weil du dir eine forschleife sparst.

_________________
MFG
Michael Springwald, "kann kein englisch...."
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: So 28.12.03 17:40 
das eine begin und end kannst du dir aber auch sparen :wink:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function LöscheMirDieDoppeltenItems; 
var 
  i:Integer; 
begin 
  for i:=0 to ListBox1.items.Count-1 do 
    if ListBox2.Items.IndexOf( Listbox1.Items[i] ) > 0 then 
      ListBox3.Items.Add(ListBox2.Items[i]); 
end;

dann ist es noch kürzer :wink:

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 28.12.03 17:45 
das ist egal wobei:
aus meiner erfarhung weiß ich, das delphi damit probleme bekommt, wenn du else hinzufügen würdes, aber in meinen fall von oben hast du natürlich recht :D :D

_________________
MFG
Michael Springwald, "kann kein englisch...."
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: So 28.12.03 17:49 
ja, natürlich :roll:

aber das mit dem weglassen bringt nicht viel, es ist halt nur kürzer.

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 28.12.03 17:57 
und es kommt auf den zweck an z.b. du willst einen if block schreiben der mehre anweisung hat dann musst du begin und end schreiben

_________________
MFG
Michael Springwald, "kann kein englisch...."
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: So 28.12.03 18:02 
denn eine if anweisung führt immer nur die nächste zeile aus, wenn die bedingung erfüllt wurde.

ist schon klar. wenn man also 2 anweisungen ausführen möchte, wenn die bedingung erfüllt wurde, dann muss man das halt mit begin und end machen.

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mo 29.12.03 19:25 
machst du z.b. sowas hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  if test = true then
    Hallo
  else
    if test1 = False then
      keine_anaung
    else
      ...


damit hat er probleme !!!

_________________
MFG
Michael Springwald, "kann kein englisch...."
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Di 30.12.03 00:52 
ich habe dsa mal übertragen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
begin
if edit1.Text='1' then
showmessage('ok1') else
if edit2.Text='2' then
showmessage('ok2') else
showmessage('nicht ok');
end;


und bei mir funzt das...

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Di 30.12.03 02:03 
es ist zufall, bei mir war das mal der fehler, warum was nicht funktionierte :( :(

_________________
MFG
Michael Springwald, "kann kein englisch...."
Alexander F
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 149

Win XP, Win 2000
D6 PE, D7 Prof, D8 Prof
BeitragVerfasst: Di 30.12.03 10:38 
Das ist kein Zufall :mrgreen:

mimi hat folgendes geschrieben:
macht das gleich wie von hibbert nur auf einen andern weg und dürfte auch "etwas" schneller sein, weil du dir eine forschleife sparst.

DAs ist nicht unbedingt schneller, da Borland IndexOf ebenfalls mit ner For-Schleife realisiert hat (meine ich jedenfalls, kann gerne noch mal nachkucken).
Es ist nur kürzer im Quelltext und damit übersichtlicher...

Grüße aus Oldenburg ;-)
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Di 30.12.03 10:59 
Zitat:
DAs ist nicht unbedingt schneller, da Borland IndexOf ebenfalls mit ner For-Schleife realisiert hat


... es ist sogar langsamer. Wenn es sich machen lässt sollte man sich Methodenaufrufe sparen.
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Di 30.12.03 13:35 
Langasammer?
das mess mal mit Ticketcount oder wie diese winAPI funktion hieß *G*

_________________
MFG
Michael Springwald, "kann kein englisch...."
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Di 30.12.03 13:47 
Da gibts nichts zu messen. Ein Prozeduraufruf ist immer langsamer als der direkte Code. Und wenn du es nicht glaubst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
var
 i: integer;

procedure foo;
begin
 inc(i);
end;

procedure test;
var
 j: integer;
 zeit: real;
begin
 i := 0;
 zeit := now;
 for j := 0 to 100000000 do
  foo;
 zeit := now-zeit;
 showmessage(floattostr(zeit));

 i := 0;
 zeit := now;
 for j := 0 to 100000000 do
  inc(i);
 zeit := now-zeit;
 showmessage(floattostr(zeit));
end;


die Procedure braucht 4/3 Mal so lang wie das einfache inc. Ganz einfach weil ein paar CALLs eingespart werden.
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Di 30.12.03 18:22 
hast recht, ein proc oder funktion aufruft dauert meisntes länger.
dafür ist der code kürtzer und übersichtlicher wobei ich mal gelesen habe das for schleifen langsammer sein sollen als while schleifen kann das angehen ???

_________________
MFG
Michael Springwald, "kann kein englisch...."
Alexander F
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 149

Win XP, Win 2000
D6 PE, D7 Prof, D8 Prof
BeitragVerfasst: Mi 31.12.03 13:12 
Eben...

Das würde ich nicht unbedingt sagen, allerdings gefallen mir persönlich While-Schleifen besser, naja kommt immer auf den Verwendungszweck an.

PS: Freu mich schon auf D8 :mrgreen:

Edit: @mimi die API heißt GetTickCount
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 31.12.03 17:21 
ja genau, ich wende die funktion nie oder selten an und daher.....

_________________
MFG
Michael Springwald, "kann kein englisch...."