[fpc-pascal] Windows programming tutorials for FPC
giuliano.colla at fastwebnet.it
Sun Nov 4 20:14:29 CET 2018
Il 03/11/2018 23:16, James ha scritto:
> It’s not a snippet, that’s the entire thing. It’s pretty simple,
> just a sequential set of events to fix a file. It would be a great
> help if you could get me an example of how to make this work.
The simplest thing you can do is just to transform your application into
a GUI application.
Try to do the following:
Start your Lazarus, then select Project->New Project -> Application
You get that way an empty form and a skeleton unit.
You'll find that in the var section there's de declaration of Form1, you
may add there your var's.
If you want your user to pick up a file name from the file dialog, do
Click on the Dialogs Tab, on the icon "TOpen Dialog", and then click
anywhere on the Form.
Now you have an OpenDialog icon on your form, which will not be visible
run time. It's there just to let you set its properties in the Object
Inspector. You may set there a default extension, an Initial Dir, a
default file name, or whatever you think can be useful to the user. Or
you may leave the fields empty so that the system defaults are taken.
You may also set the OpenDialog File name from the invocation command
line: in the initialization section (or in the OnCreate event of the
form) you may add OpenDialog1.FileName := ParamStr(1).
Now from the "Standard" Tab click on the TButton Icon and click on the
form. You get a Button on the form. Change in the Object Inspector the
Caption to what you want, sort of "Select Input File".
In the object Inspector select the Events tab and then the OnClick
event. Click on the three periods to the right, and you'll get in the
source editor the skeleton of a new procedure (TForm1.Button1Click).
That's where all of your code goes. Typically:
If OpenDialog1.Execute then begin
TapFileName := OpenDialog1.FileName;
You may add a Tedit (always fron the "Standard" tab) object to show your
messages: your writeln becomes Edit1.Text := 'Whatever'.
Where you need to ask the user for a new filename, you may just call a
second time OpenDialog1.execute, to get it.
If you want to be kind to your user, you may add a "Close" button, to
close the application when the user is done.
Just pick from the "Aditional" tab a TBitBtn, put it in your form, then
in the Object Inspector select the "Kind" as "bkClose".
There's no more than that. You may now save your project, giving the
program and the unit some name you like. Then play a bit with it, and
adjust following your needs.
Hope that it helps.
Do not do to others as you would have them do to you.They might have different tastes.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal