Autor Beitrag
nas4killer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 19.05.04 11:00 
hi,

ich wollt in meine Listbox maximal 3 gleiche items erlauben ansonsten soll eine Fehlermeldung rausspringen. Das schon drei vorhanden sind. Wie mach ich das am besten ?

Danke
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Mi 19.05.04 12:42 
Mit Items.Count selbst prüfen ob bereits drei Items drinn sind.

ausblenden Delphi-Quelltext
1:
if ListBox1.Items.Count > 3 then Error;					

_________________
Gruß
Martin
nas4killer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 19.05.04 13:14 
Sobald ich versuche

if ListBox1.Items.Count > 3 then Error;

einzufügen will komt eine fehler meldung
" Anweisung erforderlich aber Ausdruck von typ Interger Gefunden"

Ich vermute mal da du gesagt hast mit Items.Count selbst prüfen das ich da was falsch gemacht habe. Könntest ud mir das etwas näher erklären ? Danke.
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Mi 19.05.04 13:20 
Mein Error in if ListBox1.Items.Count > 3 then Error ist natürlich nur ein Dummy Funktion. Die gibt es nicht. Ich dachte nicht, daß du so wenig Programmiererfahrung hast, daß du ohne sich den Quelltxt anzusehen ihn einfach nur per Copy&Paste übernimmst.

Denk bitte in Zukunft über einen Quelltext selbst nach bevor du ihn einfügst.

_________________
Gruß
Martin
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mi 19.05.04 13:31 
Hallo,

der von MartinPb gepostete Code löst auch nicht das Problem der Frage. Er will nämlich wissen, wie er verhindern kann, dass mehr als 3-mal der gleiche Eintrag in die Liste eingetragen wird.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function TForm1.CheckObEintragSchon3MalVorhanden(const aEintrag:String):Bool;
var i, anzahl:Integer;
begin
  anzahl:=0;
  for i:=0 to ListBox1.Items.Count-1 do
    if SameText(aEintrag, ListBox1.Items[i]) then Inc(anzahl);
  Result:=(anzahl>3);
end;


Aufgerufen wird das ganze dann so:

ausblenden Delphi-Quelltext
1:
2:
  if CheckObEintragSchon3MalVorhanden('MeinEintrag'then
    ShowMessage('Der Eintrag ist schon mindestens 3 Mal vorhanden...');

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
nas4killer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 19.05.04 14:16 
Diesen Source stelle mit abhängigkeit vom einfügen eines Items:

ausblenden Delphi-Quelltext
1:
2:
if CheckObEintragSchon3MalVorhanden('MeinEintrag'then 
    ShowMessage('Der Eintrag ist schon mindestens 3 Mal vorhanden...');


das versteh ich noch . Der Source

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function TForm1.CheckObEintragSchon3MalVorhanden(const aEintrag:String):Bool; 
var i, anzahl:Integer; 
begin 
  anzahl:=0
  for i:=0 to ListBox1.Items.Count-1 do 
    if SameText(aEintrag, ListBox1.Items[i]) then Inc(anzahl); 
  Result:=(anzahl>3); 
end;


Soll wohl der sein damit er weis was er mahcen soll. Doch wie füge ich noch diese Funktion ein ? bzw wo.

Danke

PS: Tut mir leid habe mir da für meine Kenntnise wohl was zuviel vorgenommen.
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mi 19.05.04 14:35 
einfach über die procedure wo du den aufrufen willst

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
nas4killer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 19.05.04 16:02 
Dann kommt immer die fehlermeldung "undefinirter bezeichner TForm1.CheckObEintragSchon3MalVorhanden"
ich muss im bestimmt erstmal sagen was "TForm1.CheckObEintragSchon3MalVorhanden" heßen soll
Ich Bins
ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 197

Win XP Prof
D5 Prof
BeitragVerfasst: Mi 19.05.04 19:06 
Wenn die Funktion TForm1.Check usw. heißt, dann musst du ganz oben in der unit unter type TForm1=Class den namen der Funktion ohne das "TForm1." nochmal einfügen, damit er die funktion TForm1 unterordnet

_________________
Diese Nachricht wurde mit einer Taschenlampe in das offenliegende Ende eines Glasfaserkabels gemorst!
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Mi 19.05.04 20:49 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
type
  TForm1 = class(TForm)
    //...
  private
    { Private-Deklarationen }
    function CheckObEintragSchon3MalVorhanden(const aEintrag:String):Bool; //<<<<<<<<<<<
  public
    { Public-Deklarationen }
  end;

_________________
Gruß
Martin
nas4killer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 20.05.04 10:03 
Also jetzt kommt keine Fehlermeldung aber es funktioniert immer noch nicht. Ich habe jetzt mal den kompletten Souurce hier eingefügt. Könntet ihr bitte mal drüber sehen. Und mir erklären was ihr mit dem i macht das meiste verstehe ich nur nicht für was das i ist. Danke

ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    function CheckObEintragSchon3MalVorhanden(const aEintrag:String):Bool;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
function TForm1.CheckObEintragSchon3MalVorhanden(const aEintrag:String):Bool;  
var i, anzahl:Integer;  
begin  
  anzahl:=0;  
  for i:=0 to ListBox1.Items.Count-1 do  
    if SameText(aEintrag, ListBox1.Items[i]) then Inc(anzahl);  
  Result:=(anzahl>3);  
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckObEintragSchon3MalVorhanden('MeinEintrag'then  
    ShowMessage('Der Eintrag ist schon mindestens 3 Mal vorhanden...');
  Listbox1.Items.Add(Edit1.Text);
end;

end.
Martin77
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 282

XP Prof
D6 Prof, D7 Personal, D7 Enterprise, D8 personal
BeitragVerfasst: Do 20.05.04 10:15 
Was kommt denn für eien Fehlermeldung
ausblenden Delphi-Quelltext
1:
function CheckObEintragSchon3MalVorhanden(const aEintrag:String):Bool;					

ist auch falsch, soweit ich weiss kennt Delphi Bool nicht, es müsste
ausblenden Delphi-Quelltext
1:
function CheckObEintragSchon3MalVorhanden(const aEintrag:String):Boolean;					

heissen ;)


Martin
nas4killer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 20.05.04 11:35 
Du hast wohl nicht richtig gelesen. Es kommt KEINE Fehlermeldung mehr. Nur das kein Effekt kommt das heßt ich kann trozdem 4 und mehr gleiche items einfügen.

Das mit boolean habe ich probier bringt aber auch nichts ist genau das gleiche. Delphi 5 versteht glaub ich aber auch bool.
Martin77
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 282

XP Prof
D6 Prof, D7 Personal, D7 Enterprise, D8 personal
BeitragVerfasst: Do 20.05.04 11:39 
Ok, hab mich "verdenkt" dachte er meckert an der Funktion.

Ok, aber auch das mit dem anhängen ist logisch
ausblenden Delphi-Quelltext
1:
2:
3:
if CheckObEintragSchon3MalVorhanden('MeinEintrag'then  
    ShowMessage('Der Eintrag ist schon mindestens 3 Mal vorhanden...');
  Listbox1.Items.Add(Edit1.Text);



Gibt dir zwar die Meldung das da schon 3 gleiche Einträge sind. Dir fehlt der Else Fall
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if CheckObEintragSchon3MalVorhanden('MeinEintrag'then  
  ShowMessage('Der Eintrag ist schon mindestens 3 Mal vorhanden...')
else
  Listbox1.Items.Add(Edit1.Text);


Also nur anhängen wenn noch keine 3 Einträge da sind.
Martin
nas4killer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 20.05.04 13:56 
leider immer noch keine funktion. Ich habe mal das als prog zum download freigegeben. Wenn ihr mal sehen wollt. Vielleicht ist es so einfacher den fehler zu finden.

www.isis.de/~bogicf/3mal.rar
Default112
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 76

Win XP
D6 Prof
BeitragVerfasst: Do 20.05.04 14:06 
Ändere:

ausblenden Delphi-Quelltext
1:
2:
if CheckObEintragSchon3MalVorhanden(edit1.text) then
  ShowMessage('Der Eintrag ist schon mindestens 3 Mal vorhanden...')


Und:

ausblenden Delphi-Quelltext
1:
anzahl:=1;					


Dann funzt es :)
Martin77
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 282

XP Prof
D6 Prof, D7 Personal, D7 Enterprise, D8 personal
BeitragVerfasst: Do 20.05.04 14:06 
So, 2 Probleme waren in dem Source
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function TForm1.CheckObEintragSchon3MalVorhanden(const aEintrag:String):Bool;
var i, anzahl:Integer;
begin
  anzahl:=0;
  for i:=0 to ListBox1.Items.Count-1 do
    if SameText(aEintrag, ListBox1.Items[i]) then Inc(anzahl);
  Result:=(anzahl>2);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if CheckObEintragSchon3MalVorhanden(Edit1.text) then
    ShowMessage('Der Eintrag ist schon mindestens 3 Mal vorhanden...')
  else
    Listbox1.Items.Add(Edit1.Text);
end;

1. In CheckOb.... prüfst du auf >3 ab, das heisst die 3 wäre noch ok, also würde er erst nach dem 4. Eintragsagen "so, ich will nicht mehr"
2. Du übergibst irgendeinen String an die Routine, aber nicht den der im Edit steht. Du musst natürlich auch den Text übergeben den du prüfen willst.

Ich lege es dir nahe dir die Delphi Grundlagen anzutun, Du findest hier ziemlich viele Tutorials, die dir weiterhelfen können die Grundlagen zu lernen.

Martin
nas4killer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 20.05.04 23:36 
Vielenvielen dank. Es hat endlich geklappt.