Hello everyone. I recently discovered free pascal and Lazarus and I want to thank everyone who went to all that trouble to make life easier for us folks who need a fast way to write a simple Windows program. I have some questions I haven't been able to find answers for. Perhaps someone on this mailing list can help or at least tell me where to look?
Question 1:
Thanks to Lazarus I have a basic application running nicely on Windows XP and Win95. I added another button on the form - so when the user clicks on it the program will quickly back up all the data files by copying them from a folder on a networked computer to a folder on the current computer. I don't know all the filenames, but I can select them by using wildcards in a filespec. The old console COPY command would work perfectly for this, but I can't shut down the running Windows GUI application so I have to find a way to copy the files from within the Lazarus UNIT1 module when the backup button is clicked.
I Googled and found out there is a function in shellAPI that should do this: shfileoperation(). I'm trying to figure out how to use it from a Lazarus application. The shellAPI function passes a parameter of type LPSHFileopstruct. So I made a procedure which defines a variable of that type and fills in the parameters (pointers to From and To filepaths etc), then invokes the shfileoperation function to actually do the copying. My code looks something like this...
unit Unit1;
{$mode objfpc}{$H+}
interfaceuses
Classes, SysUtils, LResources, Forms, Controls, Graphics,
Dialogs, ExtCtrls, StdCtrls, CheckLst, DbCtrls, shellAPI;[..]
implementation
procedure filecopy;
var
fos:LPSHFileopstructa;
p1,p2:pchar;
result:boolean;
begin
;
;
fos.wFunc:=FO_COPY;
fos.pFROM:=p1;
fos.pTO:=p2;
fos.fflags:=FOF_SILENT or FOF_NOCONFIRMATION;
result:=shfileoperationa(fos)=0;
end;When I try to compile it from Lazarus the FPC tells me I have an illegal qualifier on
line: fos.pFunc:=FO_COPY - but I'm pretty sure pFunc is the correct qualifier. I don't know where to look to find the source code for that shfileoperation function
or the LPSHFileopstructa struct as implemented by Lazarus. Has anyone done this
already and made it work? I've tried the fileopstructw and fileopstruct versions but
they all have one problem or another. I presume fileopstructw is for "wide" filenames?
Question 2:
In my lazarus-generated data input window the user can hit the tab key to move to the
next edit window or combobox while filling out the form. That works fine. How can I
make it move the cursor from one box to the next by hitting the space bar instead of
the tab key, and how can I "place" the cursor in the appropriate box to start the next
data entry from within the Lazarus unit1 module so the user doesn't have to use the
mouse?
Question 3:
After the last box is filled in, it would be convenient to just hit the ENTER key instead
of using the mouse to click the "Submit" button. I have no idea at all how to ask Lazarus
to do this.
Sorry for all the questions. I have never used Delphi or tried any Windows API programming
until a few days ago, so I don't know where to find this information on the web.
Thanks for any tips,
Bill
