[Lazarus] Newbie questions

Paul Ishenin ip at kmiac.ru
Tue May 6 03:39:53 CEST 2008


Bill de Carle wrote:

> fos.wFunc:=FO_COPY;
...

> 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?

1. since fos is a pointer to a record you should aceess its member with 
^. in objfpc mode. So just write it so:
fos^.pFunc := FO_COPY;

And I see another problem in your code. Since fos is a pointer you need 
to allocate it with GetMem, and deallocated later with FreeMem.


Or even better if you will use record instead of pointer to a record 
(LPSHFileopstructa) as fos and pass @fos to the shfileoperationa. I have 
not seen where LPSHFileopstructa is declared but it should be declared as

LPSHFileopstructa = ^SomeRecord; Use SomeRecord instead of 
LPSHFileopstructa as type for fos and use @fos as an argument to the 
shfileoperationa.

Another problem is that you are using windows API - this is not cross 
platform way - you will not be able to compile the same code on linux or 
mac. If you want to copy one file from path_a to path_b then I can 
suggest you to use streams.

For example (I am writing it here without any check):

procedure MyCopyFile(FileNameFrom, FileNameTo: String);
var
   SFrom, STo: TStream;
   P: PAnsiChar;
begin
   SFrom := TFileStream.Create(FileNameFrom, fmOpenRead);
   STo := TFileStream.Create(FileNameTo, fmCreate);
   P := GetMem(SFrom.Size);
   SFrom.Read(P^, SFrom.Size);
   STo.Write(P^, SFFrom.Size);
   FreeMem(P);
   SFrom.Free;
   STo.Free;
end;

> 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?

You can turn KeyPreview of your Form to True and add OnKeyPress handler. 
In your OnKeyPress handler make a check for space key and focus control 
you like.

For example:

TForm1.Form1KeyPress(Sender: TObject; var Key: Char);
begin
   if Key = 32 then
     PerformTab(True);
end;
> 
> 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.

Turn on "Default" property of your "Submit" button. It will catch ENTER 
itself.

Best regards,
Paul Ishenin.




More information about the Lazarus mailing list