Autor Beitrag
diego
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Do 29.08.02 09:02 
hi,

also ich möchte gerne ein Tabellenfeld und ein editfeld miteinander verknüpfen. d.h. wenn ich in das edit feld was reinschreibe und enter drücke soll es in der tabelle erscheinen.

Hier mal mein quelltext:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var temp:String;
begin
if key = #13 then
 begin
    with DBGrid1.SelectedField do
    begin
      AdsTable1.Active:=False;
      AdsTable1.Exclusive := True;
      AdsTable1.Active:=True;
      DBGrid1.SelectedField.Text:=Form1.Edit1.Text;
      AdsTable1.Active:=False;
      AdsTable1.Exclusive := False;
      AdsTable1.Active:=True;
    end;
 end;
end;

naja funzt halt irgendwie net!!???????

Code-Tags hinzugefügt. TINO
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 29.08.02 09:46 
Hallo,

lese dir am besten mal dieses Tutorial durch. Dann kommst kannst du auf eine lösung kommen die in etwa so aussieht:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
    with DBGrid1.SelectedField do begin
      AdsTable1.Edit;
      AdsTable1.FieldByName('FeldName').AsString := Form1.Edit1.Text;
      AdsTable1.Post;
    end;
  end;
end;


Die ganze geschichte mit dem Exclusiven zugriff brauchst du nicht.

Gruß
Klabautermann

PS: Desweiteren solltest du deine Quelltexte mir Code Tags klammern. Also einfach [code ] davor und [/code ] dahinter Schreiben (Leerzeichen vor der schließenden Klammer weg lassen).
diego Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Do 29.08.02 09:59 
danke erstmal!


allerdings passiert da nix. ich drück enter und da geht nix. kein fehler. er läuft alle zeilen durch aber es funzt irgendwie net?????????
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 29.08.02 10:05 
Hallo,

warscheinlich passiert schon was, du siehst es nur nicht weil du die Daten nicht Aktuallierst.
Probiere es mal nachdem du die Funktion so erweiterst hast:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
 if key = #13 then begin
  with DBGrid1.SelectedField do begin
   AdsTable1.Edit;
   AdsTable1.FieldByName('FeldName').AsString := Form1.Edit1.Text;
   AdsTable1.Post;
   AdsTable1.Refresh;
  end;
 end;
end;


Gruß
Klabautermann
diego Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Do 29.08.02 10:22 
okay danke es funktioniert :D


nur noch eine frage

wenn ich das für mehrere felder machen will mus ich doch eigentlich nur den "Feldname" ändern!

ausblenden Quelltext
1:
AdsTable1.FieldByName('FeldName').AsString := Form1.Edit1.Text;					


allerdings nimmt er dann wieder den ersten wert.

also Bie Vorname trägt er Tom ein und Als nachname dann auch!????
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 29.08.02 10:59 
Hallo,

was du in das Feld Schreibst liegt an dem element rechts vom :=.

Wenn ich dich richtig verstehe willst du soetwas machen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
   with DBGrid1.SelectedField do begin
    AdsTable1.Edit;
    AdsTable1.FieldByName('Vorname').AsString := 'Tom';
    AdsTable1.FieldByName('Nachname').AsString := 'Schulze';
    AdsTable1.Post;
    AdsTable1.Refresh;
   end;
  end;
end;


oder mit Edit Feldern:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
   with DBGrid1.SelectedField do begin
    AdsTable1.Edit;
    AdsTable1.FieldByName('Vorname').AsString := Edit1.Text;
    AdsTable1.FieldByName('Nachname').AsString := Edit2.Text;
    AdsTable1.Post;
    AdsTable1.Refresh;
   end;
  end;
end;


Gruß
Klabautermann
diego Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Do 29.08.02 11:55 
okay danke es funzt