Solved

Passing a progressbar to a procedure

Posted on 2001-08-04
4
387 Views
Last Modified: 2011-05-16
I made a function to copy files from hdd to floppy and want to use a progressbar.

procedure CopyFile(Source, Destionation : string; Progressbar);

But I dunno how to pass the progressbar.. Anyone?
0
Comment
Question by:DerkEimers
4 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6352153
hi,
use shfileoperation  from shellapi:

this is the api that windows/explorer uses and automatically shows the progressbar.

uses ShellAPI;

function CopyAllFiles(sFrom, sTo: string; Protect: boolean): boolean;
var
  F: TShFileOpStruct;
  ResultVal: integer;
  tmp1, tmp2: string;
begin
  FillChar(F, SizeOf(F), #0);
  Screen.Cursor := crHourGlass;
  try
    F.Wnd   := 0;
    F.wFunc := FO_COPY;
    tmp1    := sFrom + #0;
    tmp2    := sTo + #0;
    F.pFrom := PChar(tmp1);
    F.pTo   := PChar(tmp2);
    if Protect then
      F.fFlags := FOF_RENAMEONCOLLISION or FOF_SIMPLEPROGRESS
    else
      F.fFlags := FOF_SIMPLEPROGRESS;
    F.fAnyOperationsAborted := False;
    F.hNameMappings := nil;
    Resultval := ShFileOperation(F);
    Result := (ResultVal = 0);
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
CopyAllFiles('a:\','c:\temp\',true);
end;
0
 
LVL 4

Accepted Solution

by:
jsweby earned 10 total points
ID: 6364346
To answer the question, you're almost there:

procedure CopyFile(Source, Destionation : string; Progressbar);

should be

procedure CopyFile(Source, Destionation : string; Progressbar: TProgressBar);

In your CopyFile procedure, referencing Progressbar will affect the progress bar passed into the procedure.

J.



0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8735435
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept jsweby's comment as answer

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

26 Experts available now in Live!

Get 1:1 Help Now