Solved

How to Copy a file from ShellListView1 to ShellListView2?

Posted on 2010-09-10
3
623 Views
Last Modified: 2012-05-10
Hi, how do I move/copy a file from ShellListView1 to ShellListView2 and also a function of the from and to location?
0
Comment
Question by:eNarc
3 Comments
 
LVL 9

Accepted Solution

by:
Tom earned 250 total points
ID: 33650586
Maybe this question/answere will lead you in the right direction?
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21085300.html
0
 
LVL 5

Author Comment

by:eNarc
ID: 33650621
Meant to say Drag a file from ShellListView1 to ShellListView2?
0
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 250 total points
ID: 33651465
Here is the code to do that, remember to set DragMode for ShellListView1 to dmAutomatic


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ShellListView1: TShellListView;
    ShellListView2: TShellListView;
    ShellComboBox1: TShellComboBox;
    ShellComboBox2: TShellComboBox;
    procedure ShellListView2DragOver(Sender, Source: TObject; X,
      Y: Integer; State: TDragState; var Accept: Boolean);
    procedure ShellListView2DragDrop(Sender, Source: TObject; X,
      Y: Integer);
  private
    procedure CopySelectedFile(const AFileName, ADestinationFolder: string);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ShellListView2DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  Accept := True;
end;

procedure TForm1.ShellListView2DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  CopyTo: string;
  DestinationItem, SourceItem: TListItem;
  WorkFolder: TShellFolder;
begin
  DestinationItem := (Sender as TShellListView).GetItemAt(X, Y);
  if Assigned(DestinationItem) then
  begin
    WorkFolder := (Sender as TShellListView).Folders[DestinationItem.Index];
    if WorkFolder.IsFolder then
      CopyTo := WorkFolder.PathName
    else
      CopyTo := ExtractFileDir(WorkFolder.PathName);

    SourceItem := (Source as TShellListView).Selected;
    WorkFolder := (Source as TShellListView).Folders[SourceItem.Index];

    if not WorkFolder.IsFolder then //unless you wan't to copy all files in the folder
      CopySelectedFile(WorkFolder.PathName, CopyTo);
  end;
end;

procedure TForm1.CopySelectedFile(const AFileName, ADestinationFolder: string);
var
  DestinationFile: string;
begin
  DestinationFile := IncludeTrailingPathDelimiter(ADestinationFolder) + ExtractFileName(AFileName);
  Windows.CopyFile(PChar(AFileName), PChar(DestinationFile), True);

  //if you want to move the file
  //Windows.MoveFile(PChar(AFileName), PChar(DestinationFile));
end;

end.

//Form
object Form1: TForm1
  Left = 363
  Top = 130
  Width = 927
  Height = 582
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ShellListView1: TShellListView
    Left = 32
    Top = 40
    Width = 873
    Height = 161
    ObjectTypes = [otFolders, otNonFolders]
    Root = 'rfDesktop'
    ShellComboBox = ShellComboBox2
    Sorted = True
    DragMode = dmAutomatic
    ReadOnly = False
    HideSelection = False
    TabOrder = 0
    ViewStyle = vsReport
  end
  object ShellListView2: TShellListView
    Left = 32
    Top = 240
    Width = 873
    Height = 193
    ObjectTypes = [otFolders, otNonFolders]
    Root = 'rfDesktop'
    ShellComboBox = ShellComboBox2
    Sorted = True
    ReadOnly = False
    HideSelection = False
    OnDragDrop = ShellListView2DragDrop
    OnDragOver = ShellListView2DragOver
    TabOrder = 1
    ViewStyle = vsReport
  end
  object ShellComboBox1: TShellComboBox
    Left = 32
    Top = 8
    Width = 865
    Height = 22
    Root = 'rfDesktop'
    ShellListView = ShellListView1
    UseShellImages = True
    DropDownCount = 8
    TabOrder = 2
  end
  object ShellComboBox2: TShellComboBox
    Left = 32
    Top = 216
    Width = 865
    Height = 22
    Root = 'rfDesktop'
    ShellListView = ShellListView2
    UseShellImages = True
    DropDownCount = 8
    TabOrder = 3
  end
end
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I load a text file into a TVirtualStringTree? 17 105
Delphi component that can load a DLL in design time? 8 53
Delphi inherited method 6 60
Base1 Encode/Decode 3 67
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now