Showing posts with label free pascal. Show all posts
Showing posts with label free pascal. Show all posts

Monday, March 10, 2014

MaskEdit Tutorial

For this tutorial we need MaskEdit component(Additional Tab)
click in editmask proporty(object inspector)

input mask editor window show up

Create your mask in the first editor. We create a serial key mask.
We want the first three digits to be only numbers , the next five digits to be both letters and numbers and the last two only  numbers.


We want the first three digits to be only numbers , the next five digits to be both letters and numbers and the last two only  numbers.

Lets test our program

If we try to type letters in the first three dashes or in last two we cant make it our program seems to work fine.if we want we can create in our favorite text editor a text like this:




and save it with .dem ending and use it anytime we want by clicking Masks button in input mask editor window.



Thats all for now..

Tuesday, March 4, 2014

TCalendarDialog tutorial

For this tutorial we need:
4 labels(Standard Tab) ,
2 buttons (Standard Tab),
1 calendardialog(Dialogs Tab),
1 edit(Standard Tab),
1 statictext(Additional Tab).


The top button opens a calendar that let us choose a date.





When we press ok button in the main form,  we can see the result in green label.

Here is the code for ok button

procedure TForm1.Button2Click(Sender: TObject);
begin
  label4.Caption:='Your name is '+edit1.Text+' and your birthday is '+statictext1.Caption;
end;    




And the code for calendar button

procedure tForm1.Button1Click(Sender: TObject);
begin
  if calendardialog1.Execute then
     statictext1.Caption:=datetostr(calendardialog1.Date);
end;


We use datetostr function to convert our date to string.

Thats all for now...

Monday, March 3, 2014

TSavePictureDialog

For this tutorial we need a button(standard tab), an image(additional tab) and a savepicturedialog(Dialogs).


we select image1 from object insepctor and we click picture property

Then we open a picture of our choice.



we click button1 and we write the following

procedure TForm1.Button1Click(Sender: TObject);
begin
  if SavepictureDialog1.Execute then
    image1.Picture.SaveToFile( SavepictureDialog1.Filename );
end;



We are ready to execute and test our program. By default we save our image in .jpg format we can change this and other options in object inspector window(savepicturedialog1).

Thats all for now..


TOpenPictureDialog tutorial

For this tutorial we need a button(standard tab), an image(additional tab) and a openpicturedialog(Dialogs).




double click button1 and write the following

procedure TForm1.Button1Click(Sender: TObject);
begin
  if openpicturedialog1.Execute then
     image1.Picture.LoadFromFile(openpicturedialog1.FileName);

end;




 




if the openpicturedialog executed the picture we just select opens in image1.

We execute our program we click the button and we open a picture.

Thats all for now..

TFontDialog tutorial

For this tutorial we need a memo from standard tab, a button from standard tab and a tfontdialog from Dialogs tab






double click the button and write the following code

procedure TForm1.Button1Click(Sender: TObject);
begin
  if fontdialog1.Execute then
   memo1.Font:=fontdialog1.Font;
end;





now execute the program and click font options button. The following dialog appears



change the options and press ok.





thats all.




TColorDialog example

For this tutorial add a button from standard tab and a TColorDialog from Dialogs tab  in the form.
Change the caption of button1 to "form1 color"

double click the button and write the following code

Procedure TForm1.Button1Click( Sender: TObject );
 begin
   if colordialog1.Execute then
    form1.Color:=(colordialog1.Color);
 end;


This code executes the colordialog1 if we run the program and press the button.



 If we select for example blue color form1 became blue.

Thats all..



Load Dialog


 1.For this tutorial add a memo, a button and a TOpenDialog in the form.

2.Change the caption of  button1 to "load".
3.Double click on load button and write onclick event: 

procedure TForm1.Button1Click(Sender: TObject);
var
  filename: string;
begin


if OpenDialog1.Execute then
   begin
        filename := OpenDialog1.Filename;
        memo1.Lines.LoadFromFile(opendialog1.FileName);
   end;
end;  



the selected file opens in memo1


4.The Execute method displays the file open dialog.  It returns true when user has selected a file, false when user has aborted.

The Filename property returns the full filename. 

 

5.Look at the object inspector for further options

we can also set the default extension for our file and

add a filter which allow only .txt types to be saved.


so we add the follow lines in form create event 


openDialog1.DefaultExt := 'txt';
openDialog1.Filter := 'Text file|*.txt';

 

Thats all.

Thursday, April 25, 2013

Save dialog



1.For this tutorial add a memo, a button and a tsavedialog in the form


2.Change the caption of  button1 to "save". if you want you can change the line property of  tmemo1. for example "The most important thing is to decide the most important thing".

 

3.Double click on save button and write onclick event: 

 procedure TForm1.Button1Click( Sender: TObject );
 begin
   if SaveDialog1.Execute then
    Memo1.Lines.SaveToFile( SaveDialog1.Filename );
 end;
 
 
 

4.The Execute method displays the file save dialog.  It returns true when user has selected a file, false when user has aborted.

The Filename property returns the full filename.
 
5.if we want we can make some changes for example let's add 
a different dialog title. At formcreate event add the following code:
procedure TForm1.FormCreate(Sender: TObject); begin saveDialog1.Title := 'Save your love letter as: '; end;
6. we can also set the default extension for our file and
 add a filter which allow only .txt types to be saved.
so we add the follow lines in form create event 
saveDialog1.DefaultExt := 'txt'; //default extension saveDialog1.Filter := 'Text file|*.txt'; 
 
 
 
 
 
 
 don't forget to check the object inspector for further options
 
 
 
Thats all for now! 

Wednesday, April 24, 2013

Main Menu

1. Place the TMainMenu widget on your form





2.Double click on the widget.

3.Click on NewItem1.

4.The object inspector will display the properties of the MenuItem1.]



5. Change the caption property to "New caption" or anything you like.

6.Right click on it and select "insert new item (after)" to create a second item after our first item.
and right click again and select "create submenu".

7.Select one of the button that you create and double click on it. Write the code you want for example:

8.You can add a shortcut for your menu, by changing the "shortcut" property for a specific button in the object inspector

9.If we want to add an image in our menu we add an image list in our form and we change "images" property of mainmenu1 to "imagelist1".

10.Then we double click on imagelist1 and imagelist editor show up.

11.Click on add and select your image..

12.Press ok and close imagelist editor. Then select your menu item and change the image index property.

13.And voila!!