Autor Beitrag
LinzerASK
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: So 08.10.06 19:06 
hi!

ich hätte da eine frage bezüglich meines programmes.
ich habe über die datenbankoberfläche von delphi eine tabelle mit 5 verschiedenen einträgen erzeugt. na ja und über ein button "handy einschalten" wird das ganze gestartet!
ein weiterer button "absendeliste" sollte dann alle absender die in der datenbank eingetragen sind in eine listbox laden - es funktioniert auch, doch der letzte vorletzte eintrag wird doppelt eingetragen und der letzte geht verloren.

ich habe folgendes programmiert:

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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, Grids, DBGrids, StdCtrls, jpeg, ExtCtrls;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    Table1: TTable;
    Image1: TImage;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

type
    PSMS = ^SMS;
    SMS = Record
        Absender,Meldung:string;
        Datum,Zeit:string;
        neu:Boolean;
        Nachbar:PSMS;
         end;

var
  Form1: TForm1;
  erster,p:PSMS;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
closE;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
New(p); //Platz für erste SMS
table1.first; //geht zum Tabellenersten
              p^.Absender:=table1.fieldbyname('Absender').asstring;
              p^.Meldung:=table1.fieldbyname('Meldung').asstring;
              p^.Datum:=table1.fieldbyname('Datum').asstring;
              p^.Zeit:=table1.fieldbyname('Zeit').asstring;
              p^.Neu:=table1.fieldbyname('Neu').asboolean;
              
p^.nachbar:=NIL; //Stappel verankern! (allerletzter-Geerdet)

while not (table1.eof) do

      begin
      table1.next; //zum nächsten Datensatz in der Tabelle gehen!
      new(erster);
      erster^.Absender:=table1.fieldbyname('Absender').asstring;
      erster^.Meldung:=table1.fieldbyname('Meldung').asstring;
      erster^.Datum:=table1.fieldbyname('Datum').asstring;
      erster^.Zeit:=table1.fieldbyname('Zeit').asstring;
      erster^.Neu:=table1.fieldbyname('Neu').asboolean;
      erster^.nachbar:=p; //verketten
      p:=erster; //P als aktuell obersten setzen! :D
      end;

table1.first;


end;

procedure TForm1.Button3Click(Sender: TObject);
begin
p:=erster; //gehe an die Stappelspitz - ganz nach oben! :D
while not (p=NIL) do
 begin
   listbox1.items.add(p^.absender);
   p:=p^.nachbar; //zum nächsten in die Liste gehen!
 end;

end;

end.


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Einloggen, um Attachments anzusehen!
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: So 08.10.06 20:49 
ich habe jetzt noch einmal den ganzen syntax durchgesehene, komme aber nicht auf den fehler.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 08.10.06 22:19 
user profile iconLinzerASK hat folgendes geschrieben:
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:
28:
29:
30:
procedure TForm1.Button2Click(Sender: TObject);
begin
New(p); //Platz für erste SMS
table1.first; //geht zum Tabellenersten
              p^.Absender:=table1.fieldbyname('Absender').asstring;
              p^.Meldung:=table1.fieldbyname('Meldung').asstring;
              p^.Datum:=table1.fieldbyname('Datum').asstring;
              p^.Zeit:=table1.fieldbyname('Zeit').asstring;
              p^.Neu:=table1.fieldbyname('Neu').asboolean;
              
p^.nachbar:=NIL; //Stappel verankern! (allerletzter-Geerdet)

while not (table1.eof) do

      begin
      table1.next; //zum nächsten Datensatz in der Tabelle gehen!
      new(erster);
      erster^.Absender:=table1.fieldbyname('Absender').asstring;
      erster^.Meldung:=table1.fieldbyname('Meldung').asstring;
      erster^.Datum:=table1.fieldbyname('Datum').asstring;
      erster^.Zeit:=table1.fieldbyname('Zeit').asstring;
      erster^.Neu:=table1.fieldbyname('Neu').asboolean;
      erster^.nachbar:=p; //verketten
      p:=erster; //P als aktuell obersten setzen! :D
      end;

table1.first;


end;


Wozu dieser Aufruf? Das müsste mit table1.next gepaart doch in ner Endlosschleife enden...?

Ich kann das Programm leider nicht ausführen, weil mir dazu du Datenbankdatei fehlt. Durch eine Exception wird das Programm sofort wieder geschlossen.

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mo 09.10.06 13:25 
hallo!

tja ich weiß auch nicht weiter...

ich werde jetzt die dll datei dazugeben!
Einloggen, um Attachments anzusehen!
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 09.10.06 13:41 
Also, ich hab dir jetzt mal schnell die Routine zum einlesen der TSMS-Records korregiert. Die Sache mit der StringList und showmessage iss nur drinn, damit man das leicht überprüfen kann, ob die Daten stimmen.

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:
procedure TForm1.Button2Click(Sender: TObject);
var sl: TStringList;
begin
New(p); //Platz für erste SMS
table1.first; //geht zum Tabellenersten
//              p^.Absender:=table1.fieldbyname('Absender').asstring;
//              p^.Meldung:=table1.fieldbyname('Meldung').asstring;
//              p^.Datum:=table1.fieldbyname('Datum').asstring;
//              p^.Zeit:=table1.fieldbyname('Zeit').asstring;
//              p^.Neu:=table1.fieldbyname('Neu').asboolean;
//
//p^.nachbar:=NIL; //Stappel verankern! (allerletzter-Geerdet)
p := nil;
sl := TStringList.Create;
while not (table1.eof) do

      begin
      new(erster);
      erster^.Absender:=table1.fieldbyname('Absender').asstring;
      erster^.Meldung:=table1.fieldbyname('Meldung').asstring;
      erster^.Datum:=table1.fieldbyname('Datum').asstring;
      erster^.Zeit:=table1.fieldbyname('Zeit').asstring;
      erster^.Neu:=table1.fieldbyname('Neu').asboolean;
      erster^.nachbar:=p; //verketten
      sl.Add('"' + erster^.Absender+ '"');
      p:=erster; //P als aktuell obersten setzen! :D
      table1.next; //zum nächsten Datensatz in der Tabelle gehen!
      end;

table1.first;
showmessage(sl.text);
sl.free;
end;


Mit der while schleife werden schlichtweg alle Einträge ausgelesen, eine Sonderbehandlung für den ersten gibts nicht ;)


Allerdings finde ich diese Handhabung der SMS-Informationen etwas schwierig. Nimm doch z.B. eine TList um dort alle PSMS- Pointer drin unterzubringen. Dann kommst du später (z.B. Button3Click) auch leichter ran.

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mo 09.10.06 16:02 
es problem ist aber auch dass ich eine listbox verwenden muss.

so wurde uns die aufgabestellung gegeben!

den code habe ich ja im großen und ganzen doch wird mir immer wieder ein eintrag doppelt eingetragen!
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 09.10.06 16:06 
Also in die LB wird alles richtig eingetragen. Die Daten sind intern richtig, deshalb wird dir auch das eine Teil da nimmer doppelt kommen. Schau dir doch meine Source an (und probiers aus) :evil:

Gruß alias5000

Edit: hab oben meine Aussage korregiert

_________________
Programmers never die, they just GOSUB without RETURN
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mo 09.10.06 18:43 
ich habe deine version ausprobiert, funzt aber ebenso nicht.

könntest du nicht vl auch dein progi hochladen.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 09.10.06 19:17 
Was funtzt dabei nicht? Du musst beim Quellcode gleich noch beachten, dass ich im OnCreate den Table noch aktiviere, das ging bei mir nicht zur Entwurfszeit, weil ich die Datenbank woanders gespeichert hatte. Ansonsten hab ich nicht viel verändert.

Gruß alias5000 (wenn du die exe gleich startest, solltest du sehen, dass es geht.
Einloggen, um Attachments anzusehen!
_________________
Programmers never die, they just GOSUB without RETURN
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mo 09.10.06 20:12 
ja ich verstehe schon
nur haben wir noch nicht mit stringlist etc gearbeitet...

so wie es bei deiner exe is sollte es dann auch bei mir sein.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 09.10.06 20:27 
Den kram mit der StringList kannst du wieder rausschmeißen. Ich hab den nur benutzt, um mit Showmessage die Einträge anzuzeigen, welche eingelesen wurden. So zur Kontrolle, ob die Daten korrekt gelesen werden. Und dann hast du ja die Source. Wie gesagt, eigentlich hab ich nur die eine Codestelle, die ich weiter oben bereits erwähnt habe, verändert.

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mo 09.10.06 21:07 
ich habe jetzt das table1.first rausgegeben! und es funzt wieder nicht...
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 09.10.06 21:33 
Ganz ehrlich: langsam vergeht mir der Spaß, mich damit zu beschäftigen. Das mit dem Table1.first muss da schon stehen, ich habe deine Logik da oben falsch verstanden. Aber eigentlich müsste es doch offentlichlich sein, was ich verändert habe, wenn du mal die Source, die du hochgestellt hast, mit der, die ich dir hochgeladen habe genauer vergelichst.
:motz:

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mo 09.10.06 21:37 
ja schon aber ich führe deine source aus...und es funzt trotzdem nicht!
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mo 09.10.06 21:50 
ausblenden volle Höhe 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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, Grids, DBGrids, StdCtrls, jpeg, ExtCtrls;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    Table1: TTable;
    Image1: TImage;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

type
    PSMS = ^SMS;
    SMS = Record
        Absender,Meldung:string;
        Datum,Zeit:string;
        neu:Boolean;
        Nachbar:PSMS;
         end;

var
  Form1: TForm1;
  erster,p:PSMS;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
closE;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
New(p); //Platz für erste SMS
table1.first; //geht zum Tabellenersten
              p^.Absender:=table1.fieldbyname('Absender').asstring;
              p^.Meldung:=table1.fieldbyname('Meldung').asstring;
              p^.Datum:=table1.fieldbyname('Datum').asstring;
              p^.Zeit:=table1.fieldbyname('Zeit').asstring;
              p^.Neu:=table1.fieldbyname('Neu').asboolean;

p^.nachbar:=NIL; //Stappel verankern! (allerletzter-Geerdet)
p:= nil;

while not (table1.eof) do

      begin
      table1.next; //zum nächsten Datensatz in der Tabelle gehen!
      new(erster);
      erster^.Absender:=table1.fieldbyname('Absender').asstring;
      erster^.Meldung:=table1.fieldbyname('Meldung').asstring;
      erster^.Datum:=table1.fieldbyname('Datum').asstring;
      erster^.Zeit:=table1.fieldbyname('Zeit').asstring;
      erster^.Neu:=table1.fieldbyname('Neu').asboolean;
      erster^.nachbar:=p; //verketten
      p:=erster; //P als aktuell obersten setzen! :D
      end;

table1.first;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
p:=erster; //gehe an die Stappelspitz - ganz nach oben! :D
while not (p=NIL) do
 begin
   listbox1.items.add(p^.absender);
   p:=p^.nachbar; //zum nächsten in die Liste gehen!
 end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
table1.active:=true;
end;

end.


so der table ist jetzt auch in form1.create mir table1.active=true aktiviert.

jetzt sag mir bitte was ich noch machen soll
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 09.10.06 21:57 
AAHHHH :oops: :oops: :oops: :bawling:

Ich bin doch blöd, hab die Source kopiert, aber nicht gespeichert. Daher geht die exe, aber die Source nicht. Tut mir Leid. Im Anhang stehts jetzt dann aber wirklich. Die Sache mit der StringList lass ich raus. (Oben hab ich die Procedure ja schon gepostet, muss nur noch reinkopieren... :roll: )

Gruß alias5000

PS.: Anmelrung zur Source: das Ereignis OnFormCreate ist nicht Fehlerrelevant, war bei mir nur nötig, weil ich den Table nicht zur Entwurfszeit auf active schalten konnte. Die Zeilen sollten bei dir keinerlei Auswirkung haben.
Einloggen, um Attachments anzusehen!
_________________
Programmers never die, they just GOSUB without RETURN
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Do 12.10.06 17:32 
sodale ... jetzt habens wir dann noch auf fehler üerprüft und das projekt abgeschlossen.

ich möchte das programm aber noch weiter ausbauen!

mir schwebt da so vor dass man vielleicht eine nachricht empfangen kann also evtl wenn man über ein eingabe feld was eingibt, auf einen button "sms empfangen" klickt, und danach die felder in das string grid eingelesen werden.

wie könnte man das lösen? braucht man da DBedit felder etc?