Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 25-10-2011
jumasuro jumasuro is offline
Registrado
 
Registrado: feb 2007
Posts: 7
Poder: 0
jumasuro Va por buen camino
Hola,
ya lo he probado y funciona a la perfección!.
Estoy bastante perdido con las propiedades de los objetos y tengo que mirarlo porque veo que son muy útiles y bastante habituales, así que tendré que dedicar un tiempo a aprender como funcionan.

Ahora me surge otro problema, y es que estoy viendo que no me va a quedar más remedio que cambiar esos paneles por frames, ya que tengo que añadirles una imagen (con un evento al hacer dobleclick sobre ella) y una label con un texto.
Pero al intentar adaptar el código del panel a un frame me he dado cuenta que no se como hacerlo.

En resumen, tengo un frame con un panel (sólo lo estoy usando como contenedor de la imagen y la label, así que a lo mejor se podría prescindir de él), una imagen y una label.
En el formulario iría añadiendo instancias de ese frame en tiempo de ejecución según fuese necesario.
¿Se puede implementar el ejemplo del drag&drop al frame (o al panel o a la imagen que tiene dentro)?, es decir, que al arrastrar los ficheros sobre cualquiera de los frames del formulario funcione el drag&drop como en el ejemplo de los paneles?.

Muchas gracias por todo y perdón por el cambio del panel por el frame, pero es que hasta que he visto la solución al problema que tenía inicialmente no me he dado cuenta de que tenía que haber pensado mejor donde lo tendría que hacer...
Responder Con Cita
  #2  
Antiguo 26-10-2011
jumasuro jumasuro is offline
Registrado
 
Registrado: feb 2007
Posts: 7
Poder: 0
jumasuro Va por buen camino
Hola a todos,
después de unas cuantas pruebas por fin creo haber conseguido implementar el drag&drop en el frame.
Rebuscando un poco por el foro e internet me he dado cuenta que tanto el constructor como el destructor del frame estaban disponibles, simplemente que no me daba cuenta de que podía acceder a ellos, así que siguiendo el ejemplo que me puso duilioisola, modifiqué mi frame y parece que ya hace lo que quiero.
Pongo aquí el código por si alguien se encuentra con un problema similar...

- Código del Frame:
(un frame con una imagen y una label)

Código Delphi [-]
...
type
  TFrameCnt = class(TFrame)
    imgFrame: TImage;
    lblFrame: TLabel;
  private
    { Private declarations }
    FFiles : TStrings;
    OriginalfrmWindowProc : TWndMethod;
    FOnFileDrop : TNotifyEvent;
    procedure frmWindowProc (var Msg : TMessage);
    procedure frmFilesDrop (var Msg : TWMDROPFILES);
  public
    { Public declarations }
    constructor Create(AOwner:TComponent);override;
    destructor Destroy; override;
  published
    property OnFileDrop : TNotifyEvent read FOnFileDrop write FOnFileDrop;
    property Files : TStrings read FFiles write FFiles;
  end;

implementation

{$R *.dfm}

constructor TFrameCnt.Create(AOwner: TComponent);
begin
  inherited;

  FFiles := TStringList.Create;
  Self.Parent := TWinControl(AOwner);

  OriginalfrmWindowProc := WindowProc;
  WindowProc := frmWindowProc;
  DragAcceptFiles(Handle, True);
end;


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


procedure TFrameCnt.frmWindowProc(var Msg: TMessage);
begin
  if Msg.Msg = WM_DROPFILES then
    frmFilesDrop(TWMDROPFILES(Msg))
  else
    OriginalfrmWindowProc(Msg);
end;


procedure TFrameCnt.frmFilesDrop(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;
...

- Código del formulario principal:
(un formulario con un memo y un par de frames creados en tiempo de ejecución)

Código Delphi [-]
...
type
  TwndPrincipal = class(TForm)
    Memo1: TMemo;
    procedure FormShow(Sender: TObject);
...
  private
    { Private declarations }
    //***** Para que funcione el Drag & Drop en los frames *********************
    procedure frmFileDrop(Sender: TObject);
    //**************************************************************************
  public
    { Public declarations }
  end;
...

procedure TwndPrincipal.FormShow(Sender: TObject);
var
  Frame : TFrameCnt;
  cont, i : integer;
begin
  cont := 0;

  //Creamos el frame1
  Frame:= TFrameCnt.Create(Self);
  Frame.Parent := self;
  Frame.Name := '';
  Frame.Top := (cont * Frame.Height) + 1;
  Frame.Left := 1;
  Frame.Width := 49;
  Frame.lblFrame.Caption := 'Frame1';
  Frame.Show;

  inc(cont);

  //Creamos el frame2
  Frame:= TFrameCnt.Create(Self);
  Frame.Parent := self;
  Frame.Name := '';
  Frame.Top := (cont * Frame.Height) + 1;
  Frame.Left := 1;
  Frame.Width := 49;
  Frame.lblFrame.Caption := 'Frame2';
  Frame.Show;

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


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

Muchas gracias y un saludo.
Responder Con Cita
  #3  
Antiguo 26-10-2011
Avatar de alej.villa
alej.villa alej.villa is offline
Miembro
NULL
 
Registrado: may 2011
Ubicación: Caracas, Venezuela
Posts: 76
Poder: 16
alej.villa Va por buen camino
Solo por curiosidad

Cita:
Empezado por jumasuro Ver Mensaje
Memo1.Lines.Add(Format('Entraron %d archivos desde el panel %s', [TFrameCnt(Sender).Files.Count, TFrameCnt(Sender).Name]));
Hola buenos días quisiera saber que significan esos valores que coloqué en negrita y como se deben usar.
Responder Con Cita
  #4  
Antiguo 26-10-2011
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.671
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Por favor, alej.villa, preguntas distintas en temas distintos, crea un nuevo tema haciendo esa pregunta, no mezclemos las cosas, gracias Recuerda leer nuestra guía de estilo.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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 11:20:45.


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