Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #3  
Antiguo 24-10-2011
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.806
Poder: 22
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Aquí tienes el código del que te hablé antes.
Pon un TMemo llamado Memo1 alineado alTop y deja un espacio abajo para que aparezcan los dos paneles.

Código Delphi [-]
unit UPruebaDragAndDrop;

interface

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

type
  TPanelDragAndDrop = class(TCustomPanel)
  private
    FFiles : TStrings;
    OriginalPanelWindowProc : TWndMethod;
    FOnFileDrop : TNotifyEvent;
    procedure PanelWindowProc (var Msg : TMessage);
    procedure PanelFilesDrop (var Msg : TWMDROPFILES);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property OnFileDrop : TNotifyEvent read FOnFileDrop write FOnFileDrop;
    property Files : TStrings read FFiles write FFiles;
  end;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure PanelFileDrop(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

/// ********** ********** ********** ********** ********** **********
/// TPanelDragAndDrop
/// ********** ********** ********** ********** ********** **********
/// Descendiente de TCustomPanel
/// Acepta que le hechen archivos
/// Publica un evento OnFileDrop
/// Publica la lista de archivos que le cayeron
/// NO VACIA LA LISTA DE ARCHIVOS

procedure TPanelDragAndDrop.PanelWindowProc(var Msg: TMessage);
begin
  if Msg.Msg = WM_DROPFILES then
    PanelFilesDrop(TWMDROPFILES(Msg))
  else
    OriginalPanelWindowProc(Msg);
end;

procedure TPanelDragAndDrop.PanelFilesDrop(var Msg: TWMDROPFILES);
const
  MAXFILENAME = 255;
var
  cnt, FileCount : integer;
  FileName : array [0..MAXFILENAME] of char;
begin
  FileCount := DragQueryFile(msg.Drop, $FFFFFFFF, FileName, MAXFILENAME);
  for cnt := 0 to -1 + FileCount do
  begin
     DragQueryFile(msg.Drop, cnt, FileName, MAXFILENAME);
     FFiles.Add(FileName);
  end;
  DragFinish(msg.Drop);

  if Assigned(OnFileDrop) then
     OnFileDrop(Self);
end;

constructor TPanelDragAndDrop.Create(AOwner: TComponent);
begin
  inherited;
  FFiles := TStringList.Create;
  Self.Parent := TWinControl(AOwner);
  
  OriginalPanelWindowProc := WindowProc;
  WindowProc := PanelWindowProc;
  DragAcceptFiles(Handle, True);
end;

destructor TPanelDragAndDrop.Destroy;
begin
  FFiles.Free;
  inherited;
end;

/// ********** ********** ********** ********** ********** **********
/// TForm1
/// ********** ********** ********** ********** ********** **********

procedure TForm1.FormCreate(Sender: TObject);
var
  i : integer;
  Panel : TPanelDragAndDrop;
begin
  //Creo el panel1
  Panel := TPanelDragAndDrop.Create(Self);
  Panel.Parent := Self;
  Panel.Name := 'autoPanel1';
  Panel.Align := alLeft;
  Panel.Show;

  //Creo el panel2
  Panel := TPanelDragAndDrop.Create(Self);
  Panel.Parent := Self;
  Panel.Name := 'autoPanel2';
  Panel.Align := alRight;
  Panel.Show;

  for i := 0 to ComponentCount-1 do
  begin
    if (Components[i] is TPanelDragAndDrop) then
        (Components[i] as TPanelDragAndDrop).OnFileDrop := PanelFileDrop;
  end;
end;

procedure TForm1.PanelFileDrop(Sender: TObject);
var
   i : integer;
begin
  Memo1.Lines.Clear;
  Memo1.Lines.Add(Format('Entraron %d archivos desde el panel %s', [TPanelDragAndDrop(Sender).Files.Count, TPanelDragAndDrop(Sender).Name]));
  for i := 0 to TPanelDragAndDrop(Sender).Files.Count -1 do
  begin
     Memo1.Lines.Add(TPanelDragAndDrop(Sender).Files[i]);
  end;
  TPanelDragAndDrop(Sender).Files.Clear;
end;

end.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Controlar componentes creados en tiempo de ejecución. damirua OOP 1 13-05-2010 14:03:58
Error TStringList creados en tiempo de ejecución subzero Varios 14 26-01-2008 13:58:05
Destruir Qrlabels creados en tiempo de ejecucion Ade Impresión 6 08-10-2006 19:46:28
Eventos en componentes creados en tiempo de ejecucion joumont OOP 3 27-12-2005 14:48:23
Objetos creados en tiempo de ejecución Scocc OOP 4 13-06-2003 20:55:29


La franja horaria es GMT +2. Ahora son las 01:52:47.


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