Discussion:
How to use a TGauge?
(too old to reply)
Geir Baardsen
2004-08-17 06:27:24 UTC
Permalink
Hi! I have a form where the user can copy a file. I'm trying to
understand the gauge, writing the text and so on. Could anybody tell
me how to update a gauge, and how to manipulate the caption of the
Gauge in the following procedure?

procedure TfrmCopyCat.CopyFileClick(Sender: TObject);
var
OpStruct : TSHFileOpStruct;
FromBuf, ToBuf : Array[0..255] of Char;
LocFrom,LocTo,f : string;
RetVal : integer;
begin
f := 'D:\Autoexec.bat';
LocFrom := 'C:\Autoexec.bat';
LocTo := 'D:\';
RetVal := MessageDlg(
'You are about to copy' +#13+
'from: ' + '[' + LocFrom + ']' +#13+
'to: ' + '[' + LocTo + ']' +#13+
'All similar files will be deleted in-> ' + '[' + LocTo + ']' +#13+
'U sure?',mtInformation,[mbNo,mbYes],0);
case RetVal of
idNo:begin
Abort;
end;
idYes:begin
{I want the gauge to start here, but what value should I use to update
the progress of the gauge?}
DelDir(LocTo);
try
FillChar(OpStruct,SizeOf(OpStruct),0);
FillChar(FromBuf,SizeOf(FromBuf),0);
FillChar(ToBuf,SizeOf(ToBuf),0);
StrPCopy(FromBuf,LocFrom);
StrPCopy(ToBuf,LocTo);
except
FillChar(OpStruct,SizeOf(nil),0);
end;
with OpStruct do
begin
try
Wnd := 0;
wFunc := FO_COPY;
pFrom := @FromBuf;
pTo := @ToBuf;
fFlags := FOF_NOCONFIRMMKDIR;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
except
;
end;
end;
ShFileOperation(OpStruct);
if FileExists(f) then
begin
ShowMessage('Copied ' + #13+
f + '!');
end
else
ShowMessage('Did not find ' + ' ' + f);
end;
end;
end;
end;
Bruce Roberts
2004-08-17 16:11:59 UTC
Permalink
Post by Geir Baardsen
Hi! I have a form where the user can copy a file. I'm trying to
understand the gauge, writing the text and so on. Could anybody tell
me how to update a gauge, and how to manipulate the caption of the
Gauge in the following procedure?
If you don't use good indentation in sample code fewer people are going to
take the time to sort through it, myself included.

I'm not familiar with a Gauge component. Usually progress is tracked using a
tProgressBar which has StepIt and StepBy methods as well as several
properties that control stepping behavior including Step.
Ed
2004-08-17 21:53:50 UTC
Permalink
What kind of progress feedback were you hoping for? The
ShFileOperation will provide progress feedback but only in the form of
the normal windows 'flying pages' + gauge dialog box. You can get
this for free by changing the line indicated below. I reckon it looks
pretty professional and handles collisions etc for you.

In order to use the TGauge you would have needed to be able to pass a
callback routine to the procedure doing the work in order for you to
update the TGauge. This particular API does not allow for it.

In 6 years of working with Delphi I have never seem a TGauge used in
anger. Seems to be a pretty unused (and pretty ugly) control so I
would steer clear of it and use progress bars for this kind of thing.
Post by Geir Baardsen
with OpStruct do
begin
try
Wnd := Handle;
^^^^^^
Post by Geir Baardsen
wFunc := FO_COPY;
fFlags := FOF_NOCONFIRMMKDIR;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
except
HTH,

Ed
Geir Baardsen
2004-08-18 14:06:51 UTC
Permalink
OK. I'll try the TProgressbar and...I shall try to do a better
indentation when I post code. Have a nice day! : - )

Loading...