Autor Beitrag
xus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Do 26.10.06 14:35 
hi!

ich habe folgendes problem ich hab eine art telefonbuch geschrieben mit arrays und records. hier mal der code:

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:
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:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
nit directory;

interface

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


type

tdaten = record
firstname, lastname,age,telephonenumber, email, adress: string[30];

end;

  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Edit5: TEdit;
    Edit6: TEdit;
    Label6: TLabel;
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    Edit7: TEdit;
    Edit8: TEdit;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Edit9: TEdit;
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  daten:array[1..100of tdaten; anzahl:integer;
  datendatei:file of tdaten;
implementation

{$R *.dfm}

procedure TForm1.FormActivate(Sender: TObject);
begin
showmessage('U are using XuS Directory! hf..');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
anzahl:=0;
memo1.text:='';
end;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer ;
ort:string;
begin
anzahl:=anzahl+1;
daten[anzahl].firstname:=edit1.Text;
daten[anzahl].lastname:=edit2.Text;
daten[anzahl].age:=edit3.Text;
daten[anzahl].telephonenumber:=edit4.Text;
daten[anzahl].adress:=edit5.Text;
daten[anzahl].email:=edit6.Text;

ort:=edit7.text;
assignfile(datendatei, ort+'.xus')  ;
rewrite(datendatei);
for i:=1 to anzahl do
begin
write(datendatei,daten[i]);
end;
closefile(datendatei);
showmessage('We saved ur Data!');
end;

procedure TForm1.Button2Click(Sender: TObject);
var i:integer; ort:string;
begin
ort:=edit8.text;
anzahl:=0;
assignfile(datendatei, ort + '.xus');
reset(datendatei);
while not eof(datendatei) do
begin
anzahl:=anzahl+1;
read(datendatei,daten[anzahl]);
memo1.Text:='';
for i:=1 to anzahl do
memo1.lines.Append(daten[i].firstname+ '  '+ daten[i].lastname+ ' ' +daten[i].age + '   ' + daten[i].telephonenumber + ' ' + daten[i].adress +'  '+ daten[i].email);
end;
showmessage('Ur Data schould be loaded!'+char(13)+ 'Otherwise check save or load path again!')
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Button4Click(Sender: TObject);
var fp:textfile; zeile:string;
begin
assignfile(fp, 'C:\Dokumente und Einstellungen\All Users\desktop\DATA.txt');
zeile:=memo1.text;
rewrite(fp);
writeln(fp,zeile);
closefile (fp);
showmessage('Ur data is saved in  DATA.txt on your desktop')
end;
procedure TForm1.Button5Click(Sender: TObject);
var sort:string; temp:tdaten; i,j,minindex:integer;
begin

sort:=edit9.text;

if sort =firstname then <-----------------------------------------------problem

for i:=1 to anzahl-1 do
begin
minindex:=i;
for j:=i+1 to anzahl do
if daten[j].sort < daten[minindex].sort then <-----------------------------------------------problem
begin
temp:=daten[minindex];
daten[minindex]:=daten[j];
daten[j]:=temp;
end;
end;
end;

end.



mein problem ist hier beim letzen knopf! ich möchte diesen sortier algorithmus so haben, dass wenn jemand in ein text feld in diesem fall in edit9 einen text eingibt zb:firstname in dieser zeile if daten[j].sort < daten[minindex].sort then das "sort" durch das geschriebene in edit9 ausgetausch wird ist das möglich??

mfg XuS

Moderiert von user profile iconGausi: Quote- durch Delphi-Tags ersetzt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.10.06 22:10 
Moin!

Zwei Sachen:

a) Schonmal was von Suche in: Delphi-Forum, Delphi-Library STYLEGUIDE gehört? :roll: Da kriegt man ja Augenkrebs... :? :mahn: ;)

b) Hab ich dich richtig verstanden: du willst nach verschiedenen Kriterien sortieren (also nach Name, Vorname, etc.)?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
xus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Fr 27.10.06 17:06 
hi!

das sortieren funktioniert so. er sagt immer der 1 wert ist minindex. nun geht er durch und schaut ob es einen kleineren als den minindex gibt. falls dies der fall ist tauscht er die 2 aus und macht das andere jetzt zum minindex. und damit er weis wass er sortieren soll geht der befehl ja so

if daten[j].sort < daten[minindex].sort then

ich möchte aber das "sort" mit einem anderen wort ersetzen lassen. denn records heißen ja firstname or lastname. also es soll so gehn. ich schreib in ein edit feld den zb. firstnehm nun soll "sort" mit first name erstzt werden. ich dachte mir das so geht aber nicht:

sort:=edit9.text;
if daten[j].sort < daten[minindex].sort then
...
end;

kapiert?


mfg XuS
__________________
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.10.06 21:11 
Moin!

user profile iconxus hat folgendes geschrieben:
ich möchte aber das "sort" mit einem anderen wort ersetzen lassen. denn records heißen ja firstname or lastname. also es soll so gehn. ich schreib in ein edit feld den zb. firstnehm nun soll "sort" mit first name erstzt werden.

Das geht nicht, Delphi ist eine Compilersprache, du kannst keine Befehle zur Laufzeit zusammenbauen. :?

Geht wohl eher so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
if (edit9.text = 'firstname'then begin
  if (daten[j].firstname < daten[minindex].firstname) then begin
    ...
  end
else if (edit9.text = 'lastname'then begin
  if (daten[j].lastname < daten[minindex].lastname) then begin
    ...
  end
...

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
xus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Fr 27.10.06 23:45 
ah das ist es hab mir auch schon so etwas ähnliches gedacht thx for help

mfg XuS



edit: hab noch ein problem. hab die datei im anhang gehängt versucht die zustarten und sieht selbst! plz help


mfg XuS
Einloggen, um Attachments anzusehen!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 00:18 
Moin!

Zwei Sachen:
a) Pro Thread nur eine Frage! :mahn: (ist Forumsregel) ;)

b) Ich kann RAR nicht so ohne weiteres auspacken, kannst du auch ein ZIP draus machen? (und die EXE weglassen, nur den Quelltext)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
xus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Sa 28.10.06 00:33 
schon gemacht aber wieso sollte ich die exe weglassen.. naja egal hier das neue ZIP archiv.

mfg XuS
Einloggen, um Attachments anzusehen!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 00:37 
Moin!

Bevor ich Code ausprobiere, den ich nicht kenne: Was passiert denn? ;) Kannst du das erstmal vorher beschreiben? Danke.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
xus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Sa 28.10.06 00:46 
es ist eine art telefon buch. mein info leherer hat gesdagt wir sollen was mit arrays und records machen also nichts was dir gefährlich werden könnte...


mfg xus


ps: auserdem lässt der code sich eh ni´cht starten ;)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 00:50 
Moin!

Was mir und besonders meinem System gefährlich sein könnte, entscheide ich üblichweise selbst, danke. :mrgreen:

Abgesehen davon kann ich es eh nicht starten, du hast nämlich die Projektdatei vergessen... :roll:

Nochwas: Bitte gib eine Fehlerbeschreibung und die Zeile an, in der der Fehler auftritt! Ich werde nicht deinen komplett undurchsichten (weil null formatierten) Code nach Fehlern absuchen.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
xus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Sa 28.10.06 00:56 
Hí!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
......
else if
if (edit9.text = 'age'then begin
for i:=1 to anzahl-1 do
minindex:=i;
for j:=i+1 to anzahl do
if daten[j].age < daten[minindex].age then
begin
temp:=daten[minindex];
daten[minindex]:=daten[j];
daten[j]:=temp;
end;
end

else
begin
showmessage('wrong input!');
end;                 <------------------ fehler

end;
end.


[Error] directory.pas(212): Type of expression must be BOOLEAN
[Error] directory.pas(217): Statement expected but end of file found
[Fatal Error] Project1.dpr(5): Could not compile used unit 'directory.pas'

so ich geht jetzt schlafen bis morgen

cu and good n8 xus
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 01:01 
Moin!

Hier ist dein Fehler:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
......  
else if  
if 
(edit9.text = 'age'then begin  
for i:=1 to anzahl-1 do  
minindex:=i;

Wenn du deinen Code mal formatieren würdest, hättest du das auch selbst gesehen. :D

Du hast auch noch mindestens ein begin-end vergessen, aber das habe ich halb geraten, weil der Code so undurchsichtig ist, dass man es nicht sehen kann... :roll:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Sa 28.10.06 09:44 
Hallo,

falls das Problem das Sortieren nach verschiedenen Teilen des recordes ist, könntest Du Dir dies mal anschauen:
www.webplain.de/foren/read.php?1,4846,4846 (in Turbo-Pascal, aber das Prinzip bleibt ja gleich)
Man schreibt also fuer jeden record Unterpunkt eine eigene Vergleichsfunktion, die dann von der Sortierroutine verwendet wird.
(Suche mal in der Delphi Hilfe nach CustomSort, damit kann man auch die Sortierfunktion von TStringlist, etc verändern).

Gruss Horst
xus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Sa 28.10.06 11:14 
hi!

was muss man den alles bei der formatierung des codes beachten?
naja ich habs jetzt mal geändert starten lässt sichs aber gehn tuts nicht ;)

hier der neue code:

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:
.........
else if (edit9.text = 'Age'then begin
for i:=1 to anzahl-1 do
begin
minindex:=i;
for j:=i+1 to anzahl do
if daten[j].age < daten[minindex].age then
begin
temp:=daten[minindex];
daten[minindex]:=daten[j];
daten[j]:=temp;
end;
end;
end

else
begin
showmessage('wrong input!');
end;

end;
end.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 20:27 
Moin!

user profile iconxus hat folgendes geschrieben:
was muss man den alles bei der formatierung des codes beachten?

Schau mal in dieses Tutorial, so oder so ähnlich könntest du den Code formatieren. ;) Ansonsten: Suche bei Google STYLEGUIDE

user profile iconxus hat folgendes geschrieben:
naja ich habs jetzt mal geändert starten lässt sichs aber gehn tuts nicht ;)

Hast du dich mal mit BubbleSort oder sowas beschäftigt? ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.