Autor Beitrag
Haggi80
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Fr 20.07.07 11:14 
Hallo,

ich habe mir eine Abstracte Form gebastelt, der Ich eine Art Magnetismus verpasst habe... Doch auf einmal gehts nicht mehr, und Ich weiß nicht warum...

Ich habe folgende Funktion deklariert....:

ausblenden Delphi-Quelltext
1:
    procedure WMMove            ( var    aMessage  : TWMMove);       message WM_MOVE;					


welche wie folgt implementiert ist:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TfrmAbstractChild.WMMove(var aMessage: TWMMove);
begin
  if FIgnoreMove then exit;

  try
    if FMagnet then begin
      RemoveDocks;
      SearchForDock;
    end;

    MoveAttachedForms(self.Left , self.Top);
  finally
    FLastPosition.X := aMessage.XPos;
    FLastPosition.Y := aMessage.YPos;
  end;
end;


Der Wert self.Left sowie self.Top ergeben immer irgendeinen Müll. Auch wenn ich auf aMessage.XPos, bzw. aMessage.YPos zugreife, steht dort der gleiche Müll drin.

Kann mir jemand sagen, woran das liegen könnte??

Viele Grüße,
Christian
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: Fr 20.07.07 12:45 
Da sich Self.Left und Top auf die Formular-properties eindeutig beziehen, und Du sogar in Deinem aufgerufenen Event denselben 'Müll' bekommst, das Fenster selbst aber auf dem Bildschirm korrekt sichtbar bleibt, denke ich, dass da irgendein Fehler Datenmist in die privaten Variablen der TForm-Klasse (also Deines Formulars) reindonnert. Das könnten z.B. Zuweisungen an nicht richtig initialisierte Zeiger sein.

So im Stehgreif jdf. schwer zu sagen. Vielleicht gibst Du mal etwas mehr Code, falls es nicht zu viel ist, könnten wir den Fehler vielleicht eingrenzen...

Wenn Du Delphi 2005/6 besitzen solltest, schau halt mal in der Historie nach, vor welcher einschneidenden Änderung der Code noch fehlerhaft lief.

_________________
Es gibt keine Probleme - nur Lösungen!
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: Fr 20.07.07 12:47 
Oops. Sag mal, fehlt in Deiner Message-Prozedur nicht ein Inherited? Vielleicht liegt's daran, dass die untergeordneten Klassen die Message nicht richtig mitkriegen...

_________________
Es gibt keine Probleme - nur Lösungen!
Haggi80 Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Fr 20.07.07 15:16 
Hallo,

und vielen Dank schonmal für die Antwort! Na ja, man könnte es hinschreiben, aber bringen würde es nichts, da die Klasse ja nicht abgeleitet ist. Habs auch gerade ausprobiert. Das bewirgt garnichts.

Ich hab wohl vorhin vergessen zu erwähnen, dass die Form tatsächlich an diese Positionen springt. (Also aus dem Sichtbaren Bereich abhaut.)

Also, es gibt im groben 2 relevante Funktionen:

zum einen ist das SearchForDock, welche eine Form sucht, an die sich SELF andocken kann. und MoveAttachedForms, welche dafür sorgen soll, das angedockte Forms mitverschoben werden.

Das hat auch schonmal funktioniert (als MDI Anwendung). Leider benutzten wir hier eine Übersetzungskomponente, welche nicht mit MDI klarkommt, von daher habe Ich halt normale Formen draus gemacht. Ich weiß nicht, ob es vieleicht hiermit zusammenhängen könnte. (Hab lediglich den Formstyle verstellt)...

Ich hoffe Du / Ihr könnt was damit anfangen....

Gruß,
Christian

Edit: Leider muss Ich hier D5 Enterprise verwenden :-(

Hier die Funktionen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TfrmAbstractChild.MoveAttachedForms( MyPosX , MyPosY : Integer);
var i           : Integer;
    locForm     : TfrmAbstractChild;
begin
  // move the attached Forms!!
  if not assigned(FAttachedForms) then exit;

  for i := 0 to FAttachedForms.Count-1 do begin
    locForm := TfrmAbstractChild(FAttachedForms.Items[i]);
    locForm.Magnet := False;
    locForm.SetPos ( (locForm.Left + (MyPosX - FLastPosition.X)) , locForm.Top   + (MyPosY - FLastPosition.Y) );
    locForm.Magnet := True;
  end;
end;



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:
procedure TfrmAbstractChild.SearchForDock;
var i, locDist, locDist2               : Integer;
    My, Its                            : TACChildDimension;
    bLeft, bRight, bTop, bBottom       : Boolean;
    locForm                            : TfrmAbstractChild;
    temp                               : TPoint;
begin
  inherited;

  try
    if (not FMagnet)  then exit;

    locForm := NIL;

    My.L    := self.Left;
    My.R    := self.Left + self.Width;
    My.T    := self.Top;
    My.B    := self.Top + self.Height;

    for i := 0 to Application.ComponentCount-1 do begin
      if (not Application.Components[i].InheritsFrom(TfrmAbstractChild))
      or (Application.Components[i] = self ) then continue;
      locForm := TfrmAbstractChild(Application.Components[i]);
      if not FormIsDockingStation ( locForm ) then continue;

      temp.X  := self.Left;
      temp.Y  := self.Top;

      Its.L := locForm.Left;
      Its.R := locForm.Left + locForm.Width;
      Its.T := locForm.Top;
      Its.B := locForm.Top + locForm.Height;

      bLeft    := (Abs ( My.L - Its.R ) < FMagnetArea) and (My.T < Its.B) and (My.B > Its.T); // Distance my Left   to its Right      // take care about the top and bottom, too!!
      bRight   := (Abs ( My.R - Its.L ) < FMagnetArea) and (My.T < Its.B) and (My.B > Its.T); // Distance my Right  to its Left
      bTop     := (Abs ( My.T - Its.B ) < FMagnetArea) and (My.R > Its.L) and (My.L < Its.R); // Distance my Top    to its Bottom
      bBottom  := (Abs ( My.B - Its.T ) < FMagnetArea) and (My.R > Its.L) and (My.L < Its.R); // Distance my Bottom to its Top

      // get the Position, i have to place to
            if bLeft    then  temp.X := Its.R + 1
      else  if bRight   then  temp.X := Its.L - 1 - Self.Width;
            if bTop     then  temp.Y := Its.B + 1
      else  if bBottom  then  temp.Y := Its.T - 1 - Self.Height;

      // if nothing matched --> continue
      if not (bLeft or bRight or bTop or bBottom) then begin
        locForm := NIL;
        continue;
      end;

      // check if we can align the 2 forms to each other (same corners!)
      if (bLeft or bRight) then begin
        locDist   := Abs (My.B - Its.B);
        locDist2  := Abs (My.T - Its.T);
        if (locDist  < FMagnetArea) and (locDist < locDist2) then temp.Y := Its.B - Self.Height;
        if (locDist2 < FMagnetArea) and (locDist > locDist2) then temp.Y := Its.T;
      end else if (bTop or bBottom) then begin
        locDist   := Abs (My.R - Its.R);
        locDist2  := Abs (My.L - Its.L);
        if (locDist < FMagnetArea) and (locDist < locDist2) then temp.X := Its.R - Self.Width;
        if (locDist < FMagnetArea) and (locDist > locDist2) then temp.X := Its.L;
      end;

      // a Position is found, but now, we need to check, if there is enough space!
      {
      if  (temp.X >= 0)
      and (temp.Y >= 0)
      and ((temp.X + (Self.Width))  < Application.MainForm.Width)
      and ((temp.Y + (Self.Height)) < Application.MainForm.Height) then break;
      }

      break;
    end;

    if not assigned(locForm) then exit;

    // finally, there is only one step to do ... attach SELF to the IT, so, if IT
    // will be moved, SELF should be Moved too...
    locForm.AttachForm ( Self );

    // and the real Move! (maybe, we could do it nicer, but for now it works...)
    FMagnet := False;
    try
      Self.SetPos ( temp.X, temp.Y );
    finally
      FMagnet := True;
    end;
  except end;
end;



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TfrmAbstractChild.SetPos(X, Y: Integer);
begin
  FIgnoreMove := True;
  try
    Self.Left := X;
    FIgnoreMove := False;
    Self.Top  := Y;
  finally
    FIgnoreMove := False
  end;
end;


Zuletzt bearbeitet von Haggi80 am Fr 20.07.07 15:22, insgesamt 1-mal bearbeitet
Haggi80 Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Fr 20.07.07 15:18 
Falls es mal jemand bei sich ausprobieren möchte..... hier mal die ganze Unit. Ist ne Abstrakte Form, von der Ich alle anderen Ableite...


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:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
unit uFrmChildAbstract;

interface

uses Windows, Messages, Classes, Graphics, Forms, Controls, StdCtrls, Dialogs, Sysutils, contnrs,

     dxTL, dxTLClms, dxCntner, dxExEdtr,

     uTypesAndConsts, ExtCtrls, ComCtrls, dxfConnection, FormSize,
  Traducteur;

type
  TACChildDimension = record
    L, R, T, B  : Integer;
  end;

  TACFormPositionSave = record
    Left, Top, Width, Height : Integer;
    FormStyle                : TFormStyle;
    BorderStyle              : TFormBorderStyle;
    BorderIcons              : TBorderIcons
  end;

  TACOnDataClick      = procedure (const aType      : Integer;
                                   const aTreelist  : TdxTreelist;
                                   const aNode      : TdxTreelistNode;
                                   const aFrom      : TForm
                                  ) of object;
  TACOnBeginDrag      = TACOnDataClick;
  TACOnEndDrag        = TNotifyEvent;
  TACDossierChanged   = procedure (const aDossierID : Integer) of object;

  TfrmAbstractChild = class;

  TfrmAbstractChild = class(TForm)
    pcMain      : TPageControl;
    tsBase      : TTabSheet;
    pnlMain     : TPanel;
    pnlLeft     : TPanel;
    lblHeadline : TPanel;

    procedure FormCreate            (Sender: TObject);
    procedure FormDestroy           (Sender: TObject);
    procedure FormClose             (Sender: TObject; var Action: TCloseAction);
    procedure FormResize            (Sender: TObject);
    procedure lblHeadlineDblClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);

  private
    FMovable                    : Boolean;
    FMagnet                     : Boolean;
    FMagnetArea                 : Integer;
    FLastPosition               : TPoint;

    FAttachedForms              : TObjectlist;        // the List of Forms, which are attached to me
    FAttachedTo                 : TObjectlist;        // the List of Forms, i am attached to

    FSavedPosition              : TACFormPositionSave;
    FIgnoreMove                 : Boolean;
    function GetIDTraduction: Integer;

  protected
    FOnBeginDrag                : TACOnBeginDrag;
    FOnEndDrag                  : TACOnEndDrag;
    FOnDataClick                : TACOnDataClick;
    FOnDataChanged              : TNotifyEvent;

    FOnDossierChanged           : TACDossierChanged;    

    procedure CreateParams            (var Params: TCreateParams);                    override;
    procedure SearchForDock;                                                          virtual;
    function  FormIsDockingStation    (const aForm : TfrmAbstractChild ) : Boolean;   virtual;

    function GetActualDossierID       : Integer;
    function GetActualUserGroupID     : Integer;
    function GetCurrentDragNode       : TACDragNode;

    procedure SetCurrentDragNode      ( const aType      : Integer;
                                        const aTreelist  : TdxTreelist;
                                        const aNode      : TdxTreelistNode;
                                        const aForm      : TForm
                                      );
    procedure ReleaseCurrentDragNode  ( Sender : TObject );

    procedure WMNCHitTest       ( var    aMessage  : TWMNCHitTest);  message WM_NCHitTest;
    procedure WMMove            ( var    aMessage  : TWMMove);       message WM_MOVE;
    procedure MoveAttachedForms ( MyPosX , MyPosY  : Integer);

  public
    function GetNodeAtMousePos  ( const aTreelist : TdxTreelist ) : TdxTreelistNode;
    function GetScreen          ( aType : TACScreenType )         : TfrmAbstractChild;

    procedure AttachForm        ( const  aForm     : TfrmAbstractChild); virtual;
    procedure DetachForm        ( const  aForm     : TfrmAbstractChild); virtual;
    procedure RemoveDocks;
    function  IsFormAttached    ( const  aForm     : TfrmAbstractChild) : Boolean;

    procedure SetPos            ( X, Y : Integer);

    procedure LoadFormSettings;
    procedure SavePosition;
    procedure RestorePosition;
    procedure MakeStandardWindow;

    property AttachedForms      : TObjectlist         read FAttachedForms;
    property AttachedTo         : TObjectlist         read FAttachedTo;

    property ActualUserGroupID  : Integer             read GetActualUserGroupID;
    property ActualDossierID    : Integer             read GetActualDossierID;

    property ID_Traduction      : Integer             read GetIDTraduction;

    property IgnoreMove         : Boolean             read FIgnoreMove         write FIgnoreMove;

  published
    property Movable            : Boolean             read FMovable            write FMovable       default True;
    property Magnet             : Boolean             read FMagnet             write FMagnet        default True;
    property MagnetArea         : Integer             read FMagnetArea         write FMagnetArea    default 40;

    property OnBeginDrag        : TACOnBeginDrag      read FOnBeginDrag        write FOnBeginDrag;
    property OnEndDrag          : TACOnEndDrag        read FOnEndDrag          write FOnEndDrag;
    property OnDataClick        : TACOnDataClick      read FOnDataClick        write FOnDataClick;
    property OnDataChanged      : TNotifyEvent        read FOnDataChanged      write FOnDataChanged;

    property OnDossierChanged   : TACDossierChanged   read FOnDossierChanged   write FOnDossierChanged;
  end;

implementation

uses Main;

{$R *.DFM}

procedure TfrmAbstractChild.FormCreate(Sender: TObject);
begin
  inherited;

  pcMain.Align    := alClient;
  FMovable        := True;
  FMagnet         := True;
  MagnetArea      := 40;

  FAttachedForms  := TObjectlist.Create(False);
  FAttachedTo     := TObjectlist.Create(False);

  FLastPosition.X := Self.Left;
  FLastPosition.Y := Self.Top;

  SavePosition;

//  FormSize.SaveKey := Self.Name;
//  FormSize.LoadFormSettings;

//  Traducteur.CodeLangueSpecial := GetCodeLang;
//  Traducteur.Utilisateur       := frmMain.Utilisateur;
end;

procedure TfrmAbstractChild.FormDestroy(Sender: TObject);
begin
  inherited;

  FreeAndNIL(FAttachedForms);
  FreeAndNIL(FAttachedTo);
end;

procedure TfrmAbstractChild.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams( Params ) ;
  Params.Style := Params.Style and (not WS_CAPTION) ;
end;

procedure TfrmAbstractChild.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

function TfrmAbstractChild.GetNodeAtMousePos(const aTreelist: TdxTreelist): TdxTreelistNode;
var P : TPoint;
begin
  result := NIL;
  if not assigned(aTreelist) then exit;

  GetCursorPos(P);
  P := aTreelist.ScreenToClient(P);
  result := aTreelist.GetNodeAt(P.X ,P.Y);
end;

procedure TfrmAbstractChild.WMNCHitTest(var aMessage: TWMNCHitTest);
begin
  inherited;

  if FMovable and (aMessage.Result = htClient) then
    aMessage.Result := htCaption;
end;

procedure TfrmAbstractChild.WMMove(var aMessage: TWMMove);
begin
  inherited;
  
  if FIgnoreMove then exit;

  try
    if FMagnet then begin
      RemoveDocks;
      SearchForDock;
    end;

    MoveAttachedForms(self.Left , self.Top);
  finally
    FLastPosition.X := aMessage.XPos;
    FLastPosition.Y := aMessage.YPos;
  end;
end;

procedure TfrmAbstractChild.MoveAttachedForms( MyPosX , MyPosY : Integer);
var i           : Integer;
    locForm     : TfrmAbstractChild;
begin
  // move the attached Forms!!
  if not assigned(FAttachedForms) then exit;

  for i := 0 to FAttachedForms.Count-1 do begin
    locForm := TfrmAbstractChild(FAttachedForms.Items[i]);
    locForm.Magnet := False;
    locForm.SetPos ( (locForm.Left + (MyPosX - FLastPosition.X)) , locForm.Top   + (MyPosY - FLastPosition.Y) );
    locForm.Magnet := True;
  end;
end;

procedure TfrmAbstractChild.FormResize(Sender: TObject);
begin
//  if assigned(FormSize) then
//    FormSize.SaveFormSettings;
end;

procedure TfrmAbstractChild.AttachForm(const aForm: TfrmAbstractChild);
begin
  if assigned(aForm) and (FAttachedForms.IndexOf(aForm) = -1) then begin
    FAttachedForms.Add(aForm);
    aForm.AttachedTo.Add(self);
  end;
end;

procedure TfrmAbstractChild.DetachForm(const aForm: TfrmAbstractChild);
begin
  FAttachedForms.Remove(aForm);
  aForm.AttachedTo.Remove(Self);
end;

procedure TfrmAbstractChild.RemoveDocks;
var i : Integer;
begin
  for i := 0 to FAttachedTo.Count-1 do
    TfrmAbstractChild(FAttachedTo.Items[i]).DetachForm(Self);
end;

procedure TfrmAbstractChild.SearchForDock;
var i, locDist, locDist2               : Integer;
    My, Its                            : TACChildDimension;
    bLeft, bRight, bTop, bBottom       : Boolean;
    locForm                            : TfrmAbstractChild;
    temp                               : TPoint;
begin
  inherited;

  try
    if (not FMagnet)  then exit;

    locForm := NIL;

    My.L    := self.Left;
    My.R    := self.Left + self.Width;
    My.T    := self.Top;
    My.B    := self.Top + self.Height;

    for i := 0 to Application.ComponentCount-1 do begin
      if (not Application.Components[i].InheritsFrom(TfrmAbstractChild))
      or (Application.Components[i] = self ) then continue;
      locForm := TfrmAbstractChild(Application.Components[i]);
      if not FormIsDockingStation ( locForm ) then continue;

      temp.X  := self.Left;
      temp.Y  := self.Top;

      Its.L := locForm.Left;
      Its.R := locForm.Left + locForm.Width;
      Its.T := locForm.Top;
      Its.B := locForm.Top + locForm.Height;

      bLeft    := (Abs ( My.L - Its.R ) < FMagnetArea) and (My.T < Its.B) and (My.B > Its.T); // Distance my Left   to its Right      // take care about the top and bottom, too!!
      bRight   := (Abs ( My.R - Its.L ) < FMagnetArea) and (My.T < Its.B) and (My.B > Its.T); // Distance my Right  to its Left
      bTop     := (Abs ( My.T - Its.B ) < FMagnetArea) and (My.R > Its.L) and (My.L < Its.R); // Distance my Top    to its Bottom
      bBottom  := (Abs ( My.B - Its.T ) < FMagnetArea) and (My.R > Its.L) and (My.L < Its.R); // Distance my Bottom to its Top

      // get the Position, i have to place to
            if bLeft    then  temp.X := Its.R + 1
      else  if bRight   then  temp.X := Its.L - 1 - Self.Width;
            if bTop     then  temp.Y := Its.B + 1
      else  if bBottom  then  temp.Y := Its.T - 1 - Self.Height;

      // if nothing matched --> continue
      if not (bLeft or bRight or bTop or bBottom) then begin
        locForm := NIL;
        continue;
      end;

      // check if we can align the 2 forms to each other (same corners!)
      if (bLeft or bRight) then begin
        locDist   := Abs (My.B - Its.B);
        locDist2  := Abs (My.T - Its.T);
        if (locDist  < FMagnetArea) and (locDist < locDist2) then temp.Y := Its.B - Self.Height;
        if (locDist2 < FMagnetArea) and (locDist > locDist2) then temp.Y := Its.T;
      end else if (bTop or bBottom) then begin
        locDist   := Abs (My.R - Its.R);
        locDist2  := Abs (My.L - Its.L);
        if (locDist < FMagnetArea) and (locDist < locDist2) then temp.X := Its.R - Self.Width;
        if (locDist < FMagnetArea) and (locDist > locDist2) then temp.X := Its.L;
      end;

      // a Position is found, but now, we need to check, if there is enough space!
      {
      if  (temp.X >= 0)
      and (temp.Y >= 0)
      and ((temp.X + (Self.Width))  < Application.MainForm.Width)
      and ((temp.Y + (Self.Height)) < Application.MainForm.Height) then break;
      }

      break;
    end;

    if not assigned(locForm) then exit;

    // finally, there is only one step to do ... attach SELF to the IT, so, if IT
    // will be moved, SELF should be Moved too...
    locForm.AttachForm ( Self );

    // and the real Move! (maybe, we could do it nicer, but for now it works...)
    FMagnet := False;
    try
      Self.SetPos ( temp.X, temp.Y );
    finally
      FMagnet := True;
    end;
  except end;
end;

function TfrmAbstractChild.GetActualDossierID: Integer;
begin
  result := frmMain.ActualDossierID;
end;

function TfrmAbstractChild.GetActualUserGroupID: Integer;
begin
  result := frmMain.ActualUserGroupID;
end;

function TfrmAbstractChild.GetCurrentDragNode: TACDragNode;
begin
  result := frmMain.CurrentDragNode;
end;

procedure TfrmAbstractChild.SetCurrentDragNode(const aType: Integer; const aTreelist: TdxTreelist; const aNode: TdxTreelistNode; const aForm: TForm);
begin
  frmMain.SetCurrentDragNode(aType, aTreelist, aNode, aForm);
end;

procedure TfrmAbstractChild.ReleaseCurrentDragNode(Sender : TObject);
begin
  frmMain.ReleaseCurrentDragNode(Sender);
end;

function TfrmAbstractChild.FormIsDockingStation(const aForm: TfrmAbstractChild): Boolean;
begin
  // The Form is a possible DockingStation for me,
  // 1. if i am not attached to it and
  // 2. the Form is not attached to me, or one of my Childs!!
  result := (aForm.AttachedForms.IndexOf(Self) = -1) and (not IsFormAttached(aForm));
end;

function TfrmAbstractChild.IsFormAttached(const aForm: TfrmAbstractChild): Boolean;
var i : Integer;
begin
  result := (FAttachedForms.IndexOf ( aForm ) <> -1);
  if not result then begin
    for i := 0 to FAttachedForms.Count-1 do begin
      result := TfrmAbstractChild(FAttachedForms.Items[i]).IsFormAttached( aForm );
      if result then break;
    end;
  end;
end;


procedure TfrmAbstractChild.lblHeadlineDblClick(Sender: TObject);
begin
  Self.Top := 0;
  Self.Height := frmMain.GetClientHeight;
end;

function TfrmAbstractChild.GetScreen(aType: TACScreenType): TfrmAbstractChild;
begin
  result := frmMain.GetScreen(aType);
end;

procedure TfrmAbstractChild.RestorePosition;
begin
  Self.Formstyle    := FSavedPosition.Formstyle;
  Self.BorderStyle  := FSavedPosition.BorderStyle;
  Self.BorderIcons  := FSavedPosition.BorderIcons;
  Self.SetPos ( FSavedPosition.Left , FSavedPosition.Top );
  Self.Width        := FSavedPosition.Width;
  Self.Height       := FSavedPosition.Height;

  Application.MainForm.Enabled := True;  
end;

procedure TfrmAbstractChild.SavePosition;
begin
  FSavedPosition.Formstyle    := Self.Formstyle;
  FSavedPosition.BorderStyle  := Self.BorderStyle;
  FSavedPosition.BorderIcons  := Self.BorderIcons;
  FSavedPosition.Left         := Self.Left;
  FSavedPosition.Top          := Self.Top;
  FSavedPosition.Width        := Self.Width;
  FSavedPosition.Height       := Self.Height;
end;

procedure TfrmAbstractChild.MakeStandardWindow;
begin
  Formstyle     := fsStayOnTop;
  Borderstyle   := bsNone;
  Width         := FSavedPosition.Width;
  Height        := FSavedPosition.Height;
  Left          := FSavedPosition.Left  + Application.MainForm.Left;
  Top           := FSavedPosition.Top   + Application.MainForm.Top + TfrmMain(Application.MainForm).GetClientTop;

  Application.MainForm.Enabled := False;
end;

procedure TfrmAbstractChild.LoadFormSettings;
begin
//  FormSize.LoadFormSettings;
end;

procedure TfrmAbstractChild.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
//  FormSize.SaveFormSettings;
  CanClose := True;
end;

function TfrmAbstractChild.GetIDTraduction: Integer;
begin
  result := 1;
end;

procedure TfrmAbstractChild.SetPos(X, Y: Integer);
begin
  FIgnoreMove := True;
  try
    Self.Left := X;
    FIgnoreMove := False;
    Self.Top  := Y;
  finally
    FIgnoreMove := False
  end;
end;

end.