Autor |
Beitrag |
daBennson
Hält's aus hier
Beiträge: 3
|
Verfasst: Mo 24.10.05 18:28
hallo,
ich möchte eine art datenbank erstellen, dabei sollen die einträge nach den namen sortiert sein. nun habe ich jedoch ein problem und find ihn einfach nicht. dachte ich mir ich kann ja hier mal fragen. so füg den quelltext dann mal ein:
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: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
| const n=100; type TPerson=Record HName: String[30]; VName: String[30]; BDay: String[100]; VDate: String[100]; end; TGruppe=Array[1..n] of TPerson;
var Datei: File of TPerson; Form1: TForm1; y,r,t,i: integer; Person: TPerson; Gruppe: TGruppe; implementation
{$R *.DFM}
procedure eintragen; begin i:=i+1; if i>100 then Form1.StringGrid1.Rowcount:=Form1.StringGrid1.Rowcount+1; Form1.StringGrid1.cells[0,i]:=IntToStr(i); Form1.StringGrid1.cells[1,i]:=Form1.HName.text; Form1.StringGrid1.cells[2,i]:=Form1.VName.text; Form1.StringGrid1.cells[3,i]:=Form1.BDay.Text; Form1.StringGrid1.cells[4,i]:=Form1.VDate.text; Form1.HName.text:=''; Form1.VName.text:=''; Form1.BDay.text:=''; Form1.VDate.text:=''; end;
procedure Save(); begin Assignfile(Datei,'M:\bday.dat'); {$i-} reset(Datei); {$i+} if IOResult<>0 then Rewrite(Datei) else t:=filesize(Datei); if y<>0 then t:=y; begin Seek(Datei,t); Person.HName:=Form1.HName.text; Person.VName:=Form1.VNAme.text; Person.BDay:=Form1.BDay.text; Person.VDate:=Form1.VDate.text; write(Datei,Person); end; closefile(Datei); y:=0; end;
procedure Laden(); begin r:=0; Assignfile(Datei,'M:\BDay.dat'); {$i-} reset(Datei); while not EOF(Datei) do begin r:=r+1; read(Datei,Person); Form1.StringGrid1.cells[0,r]:=IntToStr(r); Form1.StringGrid1.cells[1,r]:=Person.HName; Form1.StringGrid1.cells[2,r]:=Person.VName; Form1.StringGrid1.cells[3,r]:=Person.BDay; Form1.StringGrid1.cells[4,r]:=Person.VDate; i:=r; if i>3 then Form1.StringGrid1.RowCount:=i+2 ; end; closefile(Datei); end;
procedure TForm1.FormCreate(Sender: TObject); begin laden(); i:=r; Label2.caption:=DateToStr(Date); StringGrid1.cells[1,0]:='Name'; StringGrid1.cells[2,0]:='Vorname'; StringGrid1.cells[3,0]:='Geburtstag'; StringGrid1.cells[4,0]:='Vereinseintritt'; end;
procedure TForm1.BitBtn2Click(Sender: TObject); begin close; end;
procedure TForm1.BitBtn1Click(Sender: TObject); begin save(); eintragen(); end;
procedure TForm1.Button1Click(Sender: TObject); var a,b,c:Byte; Hilf:TPerson; begin For a:=1 to n-1 do For b:=a+1 to n do if Gruppe[a].HName<Gruppe[b].HName then Begin Hilf:=Gruppe[b]; Gruppe[b]:=Gruppe[a]; Gruppe[a]:=Hilf; end; For c:=1 to n do Form1.StringGrid1.cells[1,c]:=Gruppe[c].HName; Form1.StringGrid1.cells[2,c]:=Gruppe[c].VName; Form1.StringGrid1.cells[3,c]:=Gruppe[c].BDay; Form1.StringGrid1.cells[4,c]:=Gruppe[c].VDate; end;
end. |
okay...bedanke mich schon mal im vorraus...daBennson[delphi]
Moderiert von raziel: Code- durch Delphi-Tags ersetzt
Zuletzt bearbeitet von daBennson am Di 25.10.05 17:56, insgesamt 1-mal bearbeitet
|
|
azubi_20
Beiträge: 593
WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
|
Verfasst: Di 25.10.05 13:15
daBennson hat folgendes geschrieben: | ... nun habe ich jedoch ein problem und find ihn einfach nicht.
|
was für ein Problem ?
daBennson hat folgendes geschrieben: | ... dachte ich mir ich kann ja hier mal fragen. |
dann frag mal !
sorry, aber ohne Frage kann man auch nicht antworten.
|
|
daBennson
Hält's aus hier
Beiträge: 3
|
Verfasst: Di 25.10.05 16:24
sorry ich dachte meine überschrift sagt genug aus,
also wie glaube schön gesagt möchte ich eine art datenbank erstellen. dort sollen die einträge nach namen sortiert werden. jedoch muss irgendwo in meiner sortier procedure ein fehler sein, da er die laufvariable immer wieder ehöht und auch in stringgrid ausgibt. jedoch wird die liste einfach nicht sortiert. also es passiert nichts damit. ich glaube es liegt an meiner sortier procedure oda an der speicher procedure.
okay...sorry noch mal.
|
|
Martin1966
Beiträge: 1068
Win 2000, Win XP
Delphi 7, Delphi 2005
|
Verfasst: Di 25.10.05 16:35
Hallo Willkommen in der Ecke
Wofür ist denn die Variable y? Außerdem wäre es schön wenn du deinen Sourcecode etwas formatieren würdest (Einrückungen).
Lg Martin
_________________ Ein Nutzer der Ecke
|
|
azubi_20
Beiträge: 593
WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
|
Verfasst: Mi 26.10.05 14:53
Ich habe deine Sortier-Funktion etwas modifiziert :
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| procedure TForm1.Button1Click(Sender: TObject); var a,b,c:Byte; Hilf:TPerson; begin For a:=1 to n do For b:=1 to n-a do if Gruppe[b].HName>Gruppe[b+1].HName then Begin Hilf:=Gruppe[b]; Gruppe[b]:=Gruppe[b+1]; Gruppe[b+1]:=Hilf; end; For c:=1 to n do begin Form1.StringGrid1.cells[1,c]:=Gruppe[c].HName; Form1.StringGrid1.cells[2,c]:=Gruppe[c].VName; Form1.StringGrid1.cells[3,c]:=Gruppe[c].BDay; Form1.StringGrid1.cells[4,c]:=Gruppe[c].VDate; end; end. |
So müsste es funktionieren (ist aber ungetestet).
Schönen Gruss
Marwin
|
|
daBennson
Hält's aus hier
Beiträge: 3
|
Verfasst: Mi 26.10.05 20:59
hallo....danke für den Hilfe-Versuch...jedoch funktioniert auch dies nicht...dabei löscht er mir alle aus dem StringGrid..trotzdem danke...bin für neue vorschläge offen
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Do 27.10.05 00:34
Moin!
Dein Ansatz ist gelinde gesagt sehr unpraktisch...
Probier das mal so:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| procedure TForm1.Button1Click(Sender: TObject); var a,b: Integer; Hilf: TPerson; begin for a := Form1.StringGrid1.RowCount-1 downto 1 do for b := 1 to a do if (Gruppe[b].HName < Gruppe[b+1].HName) then begin Hilf := Gruppe[b]; Gruppe[b] := Gruppe[b+1]; Gruppe[b+1] := Hilf; end; for a := 1 to n do begin Form1.StringGrid1.Cells[1,a] := Gruppe[a].HName; Form1.StringGrid1.Cells[2,a] := Gruppe[a].VName; Form1.StringGrid1.Cells[3,a] := Gruppe[a].BDay; Form1.StringGrid1.Cells[4,a] := Gruppe[a].VDate; end; end; |
Vermutete Fehler (hab grad keine Lust, mir eine Testumgebung für deinen unvollständigen Code zu basteln):
- Laufvariablen für das BubbleSort waren nicht 'sauber' angelegt (konkret: das ganze Array sortieren dürfte haufenweise Leerstrings an den Anfang befördert haben...)
- Vergleich war nicht auf die benachbarten Elemente angelegt
- Kopierschleife hatte kein begin/end
- Unnütze Variable c entfernt und Wertebereich "sinnvoll" angepasst.
Empfehlungen:
- Benutze INI-Dateien zum Speichern der Daten, das ist für deine Zwecke einfacher und besser handzuhaben
- Der Array-Ansatz ist für die Datenhaltung ungeeignet -> besser dynamisch anlegen
- Du benutzt viel zu viele globale Variablen
cu
Narses
|
|
|