Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Simular evento OnScroll para ScrollBox (https://www.clubdelphi.com/foros/showthread.php?t=69018)

Kandorf 21-07-2010 01:44:26

Simular evento OnScroll para ScrollBox
 
Antes de nada plantearé mi problema.
Estoy creando un programa en el que tengo que crear muchos objetos y los muestro en un ScrollBox, el problema está en que cuando creo demasiados me da un error de Violación de acceso de memoria, así que lo que se me ha ocurrido es crear sólo los objetos que deverían verse en el ScrollBox en ese momento, para ello he pensado que sería necesario utilizar el evento OnResize, del que dispone el objeto ScrollBox, y el evento OnScroll, que no lo tiene, este es el más importante, ya que habrá que mostrar los nuevos objetos y borrar los que no se tengan que ver al mover la posición del scrollbox.
Explico el problema y el programa más detalladamente en el siguiente post: http://www.clubdelphi.com/foros/showthread.php?p=370790

He encontrado un post (http://www.mandacojones.com/foros/sh...ad.php?t=34990) en el se explican cómo hacer algo así, pero yo creo un procedimiento llamado:
Código Delphi [-]procedure TFrmPrincipal.ScbMapaWndProc(var Msg: TMessage);

Pero no me captura en evento, y si intento poner un breakpoint en el código lo marca como si fuera un comentario

Un saludo y gracias por vuestro tiempo.

ecfisa 21-07-2010 06:53:50

Hola Kandorf.

Revisá esto: http://wall.riscom.net/books/delphi/del_faqs/779.html

Saludos.

Kandorf 21-07-2010 10:39:44

Hola, muchas gracias por la respuesta, por la descripción parece ser que solucionaría mi problema, el caso es que no sé dónde meter ese código, ¿Hay que redefinir la clase ScrollBox?
He probado a copiarlo después de los uses y también después de la definición del tipo del formulario y en ambos sitios me da errores, ¿Dónde tendría que copiarlo?

Saludos.

ecfisa 21-07-2010 20:19:30

Hola Kandorf.

Lo hubiqué así y no da error:
Código Delphi [-]
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
{$IFDEF WIN32}
  WParameter = LongInt;
{$ELSE}
  WParameter = Word;
{$ENDIF}
  LParameter = LongInt;
  TForm1 = class(TForm)
    ScrollBox1: TScrollBox;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
 OldWindowProc : Pointer;
implementation
{$R *.dfm}
function NewWindowProc(WindowHandle : hWnd;
                        TheMessage   : WParameter;
                        ParamW       : WParameter;
                        ParamL       : LParameter) : LongInt
                        {$IFDEF WIN32} stdcall;
                        {$ELSE} ; export; {$ENDIF}
var
  TheRangeMin : integer;
  TheRangeMax : integer;
  TheRange : integer;
begin
  if TheMessage = WM_VSCROLL then
  begin
    {Get the min and max range of the horizontal scroll box}
    GetScrollRange(WindowHandle,
                   SB_HORZ,
                   TheRangeMin,
                   TheRangeMax);
    {Get the vertical scroll box position}
    TheRange := GetScrollPos(WindowHandle,
                             SB_VERT);
    {Make sure we wont exceed the range}
    if TheRange < TheRangeMin then
      TheRange := TheRangeMin else
    if TheRange > TheRangeMax then
      TheRange := TheRangeMax;
    {Set the horizontal scroll bar}
    SetScrollPos(WindowHandle,
                 SB_HORZ,
                 TheRange,
                 true);
  end;
  if TheMessage = WM_HSCROLL then begin
  {Get the min and max range of the horizontal scroll box}
    GetScrollRange(WindowHandle,
                   SB_VERT,
                   TheRangeMin,
                   TheRangeMax);
  {Get the horizontal scroll box position}
    TheRange := GetScrollPos(WindowHandle,
                             SB_HORZ);
  {Make sure we wont exceed the range}
    if TheRange < TheRangeMin then
      TheRange := TheRangeMin else
    if TheRange > TheRangeMax then
      TheRange := TheRangeMax;
  {Set the vertical scroll bar}
    SetScrollPos(WindowHandle,
                 SB_VERT,
                 TheRange,
                 true);
  end;
  { Call the old Window procedure to }
  { allow processing of the message. }
  NewWindowProc := CallWindowProc(OldWindowProc,
                                  WindowHandle,
                                  TheMessage,
                                  ParamW,
                                  ParamL);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Set the new window procedure for the control }
{ and remember the old window procedure.       }
  OldWindowProc := Pointer(SetWindowLong(ScrollBox1.Handle,
                                         GWL_WNDPROC,
                                         LongInt(@NewWindowProc)));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{ Set the window procedure back }
{ to the old window procedure.  }
  SetWindowLong(ScrollBox1.Handle,
                GWL_WNDPROC,
                LongInt(OldWindowProc));
end;
end.

Nota: Para probarlo agregué un TScrollBox con varios botones.

Saludos.


La franja horaria es GMT +2. Ahora son las 14:18:35.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi