Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Memos synchron scrollen (https://www.delphipraxis.net/146422-memos-synchron-scrollen.html)

Muellermilchtrinker 19. Jan 2010 17:54


Memos synchron scrollen
 
Hy DP,

Ich möchte gerne zwei Memos synchron scrollen.
Ich habe auch schon was gefunden: Klick mich hart und du wirst belohnt!!!
Nur ist hier jetzt das Problem:
Wenn ich Memo1 scrolle, scrollt Memo2 auch. :-D
Soweit so gut.
Aber wenn ich Memo2 scrolle, scrollt Memo1 nicht. :cry:

Meine Frage jetzt:
Wie kann ich es auf beide anwenden.

Ich hab auch schon den Code zu kopieren und auf Memo2 anwenden. Ergebnis: Negativ. Vllt habe ich auch etwas falsch gemcht. Ich wäre dankbar wenn ihr mir helfen könnt. :thumb:

MFG
Muellermilchtrinker (der mit den vielen Fragen :stupid: )

Die Muhkuh 19. Jan 2010 18:01

Re: Memos synchron scrollen
 
Zitat:

Ich hab auch schon den Code zu kopieren und auf Memo2 anwenden
Zeig mal den Code davon

Muellermilchtrinker 19. Jan 2010 18:07

Re: Memos synchron scrollen
 
Das wär die ganze Unit:

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
    PRichEdWndProc, POldWndProc: Pointer;
    PRichEdWndProc2, POldWndProc2: Pointer;
    procedure RichEdWndProc(var Msg: TMessage);
    procedure RichEdWndProc2(var Msg: TMessage);
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  PRichEdWndProc := MakeObjectInstance(RichEdWndProc);
  POldWndProc   := Pointer(SetWindowLong(Memo1.Handle, GWL_WNDPROC,
    Integer(PRichEdWndProc)));
  PRichEdWndProc2 := MakeObjectInstance(RichEdWndProc);
  POldWndProc2    := Pointer(SetWindowLong(Memo2.Handle, GWL_WNDPROC,
    Integer(PRichEdWndProc2)));
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Assigned(PRichEdWndProc) then
  begin
    SetWindowLong(Memo1.Handle, GWL_WNDPROC, Integer(POldWndProc));
    FreeObjectInstance(PRichEdWndProc);
  end;
  if Assigned(PRichEdWndProc2) then
  begin
    SetWindowLong(Memo2.Handle, GWL_WNDPROC, Integer(POldWndProc));
    FreeObjectInstance(PRichEdWndProc2);
  end;
end;


procedure TForm1.RichEdWndProc(var Msg: TMessage);
begin
  Msg.Result := CallWindowProc(POldWndProc, Memo1.Handle, Msg.Msg,
    Msg.wParam, Msg.lParam);

  if (Msg.Msg = WM_VSCROLL) and (LOWORD(Msg.wParam) = SB_THUMBTRACK) then
  begin
    Memo2.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
    SetScrollPos(Memo2.Handle, SB_VERT, HIWORD(Msg.wParam), True);
  end;
end;

procedure TForm1.RichEdWndProc2(var Msg: TMessage);
begin
  Msg.Result := CallWindowProc(POldWndProc, Memo2.Handle, Msg.Msg,
    Msg.wParam, Msg.lParam);

  if (Msg.Msg = WM_VSCROLL) and (LOWORD(Msg.wParam) = SB_THUMBTRACK) then
  begin
    Memo2.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
    SetScrollPos(Memo1.Handle, SB_VERT, HIWORD(Msg.wParam), True);
  end;
end;

end.

Amateurprofi 19. Jan 2010 22:45

Re: Memos synchron scrollen
 
Was mir auf die Schnelle aufffällt:
In RichEdWndProc machst du ein Memo2.Perform und SetScrollPos(Memo2....)
In RichEdWndProc2 machst du ein Memo2.Perform und SetScrollPos(Memo1....)
Ich denke du müßtest in ichEdWndProc2 ein Memo1.Perform machen

Muellermilchtrinker 20. Jan 2010 13:34

Re: Memos synchron scrollen
 
Danke. :thumb:
Warn zwar noch zwei/drei andere Kleinigkeiten, funktioniert aber jetzt.

Kommt davon wenn man Copy&Paste nutzt :oops:


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:01 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz