Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 21.05.09 07:53 
Hi, Delpher,
mal wieder eine "Nuss":

Mit diesem Code übertrage ich eine Zeile aus einem Stringgrid (tntstringgrid1) in ein DBGrid. Die Variable StartDrag ist als private in diesem (und auch in einem anderen) Formular deklariert.

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:
procedure TForm4.TntStringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin  TntStringgrid1.DragMode := dmAutomatic; end;

procedure TForm4.TntStringGrid1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin  TntStringgrid1.DragMode := dmManual;    end;

procedure TForm4.TntStringGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  if StartDrag then  //Merken, welche Reihe wir sind wenn the dragging started.
  begin                   //wichtig::  OI:TntStringgrid1.DragMode := dmautomatic;
    TntStringGrid1.MouseToCell(X,Y,c,r);
    StartDrag := False;
  end
end;

procedure TForm4.TntStringGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin  StartDrag := True;  end;  //falls zurück auf das TntStringGrid

procedure TForm4.DBGrid4DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin  Accept := Source is TTntStringGrid;  end;

procedure TForm4.DBGrid4DragDrop(Sender, Source: TObject; X, Y: Integer);
var n, k: integer;
    leer: boolean;
begin
  if Source is TTntStringGrid then
  begin
    showmessage('Reihe: '+ inttostr(r));
    if r > 0 then
    begin
      leer := true;
      for n := 0 to tntstringgrid1.ColCount-1 do
        if tntstringgrid1.Cells[n,r] <> '' then leer := false;
      if leer = false then
      begin
        Table3.Append;
          for n := 0 to tntstringgrid1.ColCount-1 do
            Table3.Fieldbyname(tntstringgrid1.cells[n,0]).asstring := TntStringgrid1.cells[n,r];
        Table3.Post;
        showmessage('Tabellen werden geladen ...');
          form1.lade_schueler(self);
          for k := 1 to tntstringgrid1.rowcount-1 do
            for n := 0 to tntstringgrid1.ColCount-1 do tntstringgrid1.Cells[n,k] := '';
        showmessage('Tabellen sind aktuell');
      end
      else showmessage('Datensatz ist leer');
    end
    else showmessage('Think');
    StartDrag := True;
  end;
end;


Dieser Code funktioniert prächtig, aber nur nicht beim ersten Aufruf - da ist r immer Null, sonst wird wie gewünscht die richtige Zeilennummer angegeben und verarbeitet.

Wo liegt da der Fehler?

Danke für eure Hilfe,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Do 21.05.09 08:16 
Also ich würde mir eher bei onMouseDown() merken, auf welcher Zelle das genau war und dann bei MouseUp() gucken, ob das dort rein passt. Wenn ja, dann kannst Du doch Dein Drag&Drop ohne weiteres auf genau diese (von mir beschriebene) Art machen - oder?
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 21.05.09 17:25 
Hi ffgorki,

ja, das hatte ich auch erst gedacht, aber siehe da, ohne Erfolg / Änderung.
Ich habe jetzt initialisiert beim Aufruf des Formulars, und jetzt geht es - also wenn ich an insgesamt zwei Stellen initialisiere (mit StartDrag := true) .

Danke für deine Antwort,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas