Thursday, October 29, 2009

Vector Masking using Adobe Fireworks.

Wow fireworks make's vector masking a child's play, first of all I have to tell you what is vector mask "vector mask is a gradient mask which used to hide a portion of image with some solid color, this solid color have two transparency points in first point the opacity is 100 % and in second point the opacity level is on O% percent, the revealed area of the image is under 0% opacity”. Vector mask are usually used to merge more than two images in a single image.
Now we start this tutorial.

Step 1:

Select an image


Step 2:

Place a rectangle block using Rectangle Tool (or press U) behind the image, which is equal to the desired banner width.

Step 3:

Toggle image and rectangle block position, by using layer palette or Ctrl + keys

Step 4:

  • Use Marquee tool to select area of the image and crop it, we used ruler to make sure that we select required height.
  • Under properties panel we have all properties of a Marquee, which we can adjust as per our requirement.

After Cropping we have this result.

Step 5

Go to command select creative option then select Auto Vector mask.

After selecting Auto vector mask a panel open with following mask options

Select your desired mask option and press Apply button.
OK below image I have done few steps together but below image help you to find out what all I have done.
These two handles visible on image (we also pointed one of them a circle) are used to control mask position and opacity level.
Under the properties panel we have all vector mask options.
Vector mask layer is also highlighted in Layer Palette.


Step 6:

After final adjustment of Vector mask, we put some text on Banner.
Good Luck, I hope that you will learn Vector mask with this simple Tutorial. Please give your feedback to help me to make things better.





At the end of this tutorial i am thank full to Makeup Forever for their image contribution and Dafont.com for their fonts.





Tuesday, October 20, 2009

Building a Java Desktop Database Application



This tutorial shows how to create a desktop Java application through which you canaccess and update a database. The tutorial takes advantage of support inNetBeans IDE for the following technologies:

  • The Java Persistence API (JPA), which helps you use Java code to interact with databases.

  • Beans Binding (JSR-295), which provides a way for different JavaBeans components
    to have property values that are synchronized with each other. For example, you can use beans
    binding to keep the values of cells in a JTable visual component in
    synch with the values of fields in an entity class. (In turn, the entity class
    represents the database table.)

  • The Swing Application Framework (JSR-296), which provides some useful
    building blocks for quickly creating desktop applications.



We will create a database CRUD (create, read, update, delete)
application with a custom component used for visualizing the data (car design preview).



This tutorial is largely based on a screencast that was based on a development build.
Some of the user interface has changed since that demo
was made, so you might notice some differences between this tutorial and the demo.
You can view the demo (about 9 minutes) now
or download a zip
of the demo
.


Setting Up the Database


Before you begin creating a desktop CRUD (create, read, update, delete) application
in the IDE, you should already have the IDE connected to the database that
your application will use. Having this connection set up in advance will
allow you to take advantage of IDE features that automate the binding of the
database to your application.



In this tutorial, we provide instructions for using a Java DB database, since
there is a convenient interface for starting and stop the Java DB database server from the IDE.
However, you can use a different database server without too much difficulty.


First verify that you have Java DB registered in the IDE.
Java DB is
automatically registered in the IDE in a number of cases, such as when
you have Sun Java System Application Server registered in the IDE
or when you are running on JDK 6. If Java DB is not registered in the IDE,
register it manually.



To verify whether Java DB is registered in NetBeans IDE 6.1:



  1. Open the Services window.

  2. Right-click the Databases > Java DB node and choose Properties.

    If Java DB is registered, the Java DB Installation and Database Location
    fields will be filled in.



    If Java DB is not registered, fill in the following two fields:



    • Java DB Installation. Enter the path to the database server.

    • Database Location. Enter the folder where you want the databases to be stored.


  3. Click OK.


To verify whether Java DB is registered in NetBeans IDE 6.0:



  1. Choose Tools > Java DB Database > Settings.

  2. If Java DB is registered, the Java DB Installation and Database Location
    fields will be filled in.


    If Java DB is not registered, fill in the following two fields:




    • Java DB Installation. Enter the path to the database server.

    • Database Location. Enter the folder where you want the databases to be stored.


  3. Click OK.



Starting the Server and Creating a Database



Once Java DB is registered with the IDE, you can easily start and stop
the database server, as well as create a new database.


To start the database server in NetBeans IDE 6.1:



  • In the Services window, right-click Databases > Java DB and
    choose Start Server.

    If you do not already have a location set for the database, the Set Database Location
    dialog box appears. Enter a location for the database server to store the databases. You can create
    a new folder there if you wish.





To start the database server in NetBeans IDE 6.0:



  • Choose Tools > Java DB Database > Start Server.

    If you do not already have a location set for the database, the Set Database Location
    dialog box appears. Enter a location for the database server to store the databases. You can create
    a new folder there if you wish.





Once the server is started, Java DB Database Process tab opens in the
Output window and displays a message similar the following:


Apache Derby Network Server - 10.2.2.0 - (485682) started and ready
to accept connections on port 1527 at 2007-09-05 10:26:25.424 GMT




To create the database in NetBeans IDE 6.1:




  1. In the Services window, right-click Databases > Java DB and
    choose Create Database.

  2. For the Database Name text field, type car_database. Also set the User Name and
    Password to nbuser.

  3. Click OK.



To create the database in NetBeans IDE 6.0:



  1. Choose Tools > Java DB Database > Create Database. The
    Create Java DB Database dialog opens.

  2. For the Database Name text field, type car_database. Also set the User Name and
    Password to nbuser.


  3. Click OK.



Connecting to the Database



So far, we have successfully started the the database server and created a database.
However, we still need to connect to the new database before we can
start working with it in the IDE. To connect to the car_database database:




  1. Switch to the Services window (Ctrl+5) and expand the Databases node to see
    your new database.


  2. Right-click the database connection node
    (jdbc:derby://localhost:1527/car_database[nbuser on NBUSER]) and choose
    Connect.

    The connection node icon should now appear whole (connection node icon), which signifies that the connection was successful.






  3. Expand the connection node, right-click its Tables subnode, and choose Execute Command.

  4. Copy the contents of the
    car.sql file
    and paste them into the SQL Command 1 tab of the Source Editor.

    This is the SQL script which will populate the database with data about cars.



  5. Click the Run SQL button (Run SQL button)in
    the toolbar of the Source Editor to run the script.




Creating the Application



  1. Choose File > New Project.

  2. In the first panel of the wizard, expand the Java category and select the Java Desktop Application template. Click Next.

    The Java Desktop Application template provides many basics of a visual application, including basic menu items and commands.



  3. In the Name and Location page of the wizard, do the following things:

    1. In the Project Name field, type CarsApp. The value of this field sets the display name for the project in the Projects window.

    2. Select the Set As Main Project checkbox.

    3. Optionally, edit the Project Location field to change the location of your project metadata.

    4. In the Choose Application Shell field, select Database Application.


    5. Click Next.


  4. In the Master Table page of the wizard, select the database connection for the CAR database.
    The listing for the database should look something like the following: jdbc:derby://localhost:1527/car_database[nbuser on NBUSER]

  5. Fill in the password (nbuser) for the database and select the
    Remember Password During This Session checkbox.

    After the connection to the database is established, the Database Table field
    should display CAR and
    the Columns to Include list should include the names of
    10 columns for the CAR database. For now, we will use only five of them in the application.

  6. Select the bottom five column names (beginning with
    SUN_ROOF and ending with MODERNNESS) and click the < button
    to move them to the left column. Click Next.

  7. In the Detail Options panel, click Finish.

    The wizard then generates the a basic user interface with a table and a
    database connection. This might take a few seconds as the IDE generates the
    project and the code..







Running the Generated Application


At this point, you have a basic running application with a
graphical user interface (GUI) that has the following features:



  • Ability to view and modify values in five columns of the CAR database.

  • Basic menu items.


  • Persistence of its window state between sessions. When you
    close the application, the window position and size are remembered. So
    when you reopen the application, the window opens in the same position as
    it was when you closed it.

  • An About dialog box, which you can easily customize.

  • .properties files containing the labels in the user interface. Using
    .properties files is a good way to keep the logic of your code separate from the
    text that appears in the user interface of your application. Such separation is useful
    for making it easier to localize your program, among other reasons.



To see some of the features that are already built into the application, follow these steps:



  1. Right-click the project's node and choose Run.

    After a few seconds, the application stars and a window called Database Application Example appears.
    This window contains a table and several controls that enable you to edit the CARS database.


  2. Select the first record in the table (for the Acura).

  3. Select the Price text field and replace the existing value with 46999. Then press Enter.

    The value should appear updated in the table. (However, that value will
    not be reflected in the database until you click Save.)



    Similarly, you can update any other values in the table.


  4. Click New to create a new record. Then fill in values for each of the fields (Make, Model, Price, Body Style, Color). For example, you can fill in
    Trabant, Classic, 1000, wagon, and blue. Click Save to
    save the entry in the database.

  5. Click the Database Application Example title bar and drag the application to a different place on your screen.


  6. Click the left border of the Database Application Example window and drag to the left to increase the size of the window.

  7. In the Database Application Example menu bar, choose File > Exit.

  8. In the IDE, right-click the project's node and choose Run Project.

    The Database Application Example window will open in the same size and position it was in when you
    closed the application.





Reviewing the Generated Parts of the Application



The connection between the master table (a JTable component) and the database is
handled with a combination of the following mechanisms, all of which have been
generated by the IDE:




  • The Car.java entity class, which is used to read and write data to
    the CAR database table. Entity classes are a special type of class
    that enable you to interact with databases through Java code.
    Entity classes use Java annotations to map class fields to database columns. .

  • The META-INF/persistence.xml file, which defines a connection between
    the database and the entity class. This file is also known as the persistence unit.


  • Using beans binding to connect the properties of the entity class
    with the properties of the JTable component. Beans binding is a new technology
    based on JSR 295 and which will probably be included in a future Java SE release.

  • The entityManager, query, and list
    objects, which are defined in the CarsAppFrame class and
    which are listed in the Inspector window.


    • The entity manager object is used to retrieve and commit data
      within the defined persistence unit scope.

    • The query object defines how the particular data collection is retrieved from
      the entity manager. (You can change the way that the query object works by selecting the
      query object in the Inspectory window and changing the query property in the property sheet.
      The query property uses JPA query language.

    • The list object is an observable collection that holds the data from the query. An
      observable collection is a special kind of collection on which you can place a listener to
      find out when changes to the collection have been made.






Using the Inspector window and the property sheet, you can follow these steps to see how
the JTable is bound to data:



  1. In the Inspector window, select the
    mainPanel[JPanel] > masterScrollPane [ScrollPane] > masterTable [JTable]
    node.
    Then click the Binding tab in the Properties window.


  2. Look at the elements property to confirm that it is bound to a list.

  3. Click the ellipsis [...] button to open the Bind masterTable.elements customizer, where you can
    further customize the binding between the table and the database. For example, you can see that the
    customizer enables you to specify which table columns are bound.


Besides the Binding category in property sheet you can also use the
Bind menu in context menu.





Adding More Controls



We will now add controls to the form for some of the attributes we initially excluded.
Instead of using a table, we will add JSlider components (for the tire size and
modernness attributes) and JCheckbox components (for the sun roof and the spoiler).

Follow these steps to add the additional components:


  1. Add the first slider by clicking the Slider button in the Palette window and
    then clicking in the form just above the New button. Before clicking in the form
    to insert the slider, make sure that no horizontal slotted guiding lines are shown.
    These lines indicate that the slider will be inserted in the same line as the
    fields or the buttons. See the figure below to see where you should drop the
    slider into the form.

    Note: If you drop the component in a place you do not want and thus
    cause several undesired layout changes, you can use the Undo command
    to reverse the changes. Choose Edit > Undo or press Ctrl-Z.




  2. If necessary, stretch the slider to the left to align it with the left side of the text field components.

  3. Stretch the slider to the
    right to span the whole form width.

  4. Add a label to the left of the slider and set its text to Tire Size.
    (Click the label to make it editable.)

  5. Add another slider below the first slider, and adjust its width and alignment where necessary.

  6. Add another label below the Tire Size label and set its text to Modernness.


  7. Add two checkboxes below the sliders. Set their text to Spoiler and Sun Roof.
    (Make the display text editable by clicking the checkbox once, pausing, and then clicking
    the checkbox again. You can also right-click the checkbox and choose Edit Text.)


The form should look like the screenshot shown below.



A screenshot of the design area with all controls added"

Binding Controls to Values in the Table



We will now use beans binding features to tie the values shown in table cells to
the state of the controls we have added. This will allow you to change the values
of cells in the table by using the sliders and checkboxes.



To bind the sliders to their corresponding table elements:



  1. In the form, right-click the Tire Size slider and choose Bind > value.

  2. In the Binding Source drop-down list of the Binding dialog box, select masterTable.


  3. In the Binding Expression drop-down list, select the selectedElement > tiresize node.



    "

  1. In the form, right-click the Modernness slider and choose Bind > value.

  2. In the Binding Source drop-down list of the Binding dialog box, select masterTable.


  3. In the Binding Expression drop-down list, select selectedElement > modernness.



To bind the checkboxes to their corresponding table elements:



  1. In the form, right-click the Spoiler checkbox and choose Bind > selected.


  2. In the Binding Source drop-down list of the Binding dialog box, select masterTable.

  3. In the Binding Expression drop-down list, select selectedElement > spoiler.

  4. Click OK to exit the Bind dialog box.


  5. In the form, right-click the Sun Roof checkbox and choose Bind > selected.


  6. In the Binding Source drop-down list of the Binding dialog box, select masterTable.

  7. In the Binding Expression drop-down list, select selectedRow > sunRoof.

  8. Click OK.




You should now be able to change database entries using the slider and
checkboxes.



To verify that the sliders and checkboxes work:



  1. Open the Services window.

  2. Make sure the IDE has a connection to the database by right-clicking
    Databases > jdbc:derby;//localhost:1527/car_database and choosing Connect.

  3. Right-click the Databases > jdbc:derby;//localhost:1527/car_database > Tables > node
    and choose View Data.


  4. Look at the SUN_ROOF, SPOILER, TIRE_SIZE, and MODERNNESS values
    for the first record.

  5. Choose Run > Run Main Project to execute the application.

    The running application should look similar to the screenshot shown below.



    "

  6. In the running application, select the first record.

  7. Move the sliders and change the checkbox selections.


  8. Click Save to save the changes into the database.

  9. In the Services window, use the View Data command again.

    The values in the database should reflect changes that you have made.




Sunday, October 4, 2009

Turbo C++ graphics programming Part 2

In first part of the turbo c++ graphics programming series,I explained about the graphics modes & standard library functions,drivers



In short, you need Turbo C++ version 3.0 to run the program explained in this post.



Drawing functions:


There are many functions available to draw the shapes on the screen; it̢۪s not possible for me to cover each & every function used in graphics programming so here i have explained the most widely used & effective functions, the efficient use of them allows you to create smooth graphics.

rectangle (left,top,right,bottom) :


This function draws a rectangle with (left,top) as upper left of the rectangle & (right,bottom) as its lower right of the corner.All you have to do is to put the right co-ordinates.


e.g. rectangle (10,30,500,400);

ellipse (x,y,stangle,endangle,xrad,yrad) :


This function draws an elliptical arc.Here (x,y) are the co-ordinates of center of the ellipse.(stangle,endangle) are the starting and ending angles.If stangle=0 and endangle=360 then this function draws complete ellipse.


e.g.ellipse(100,150,0,360,100,50);


arc (x,y,stangle,endangle,rad) :



This function draws the circular arc of the given color.(x,y) are the center point of the arc & arc travels from stangle to endangle.(rad) defines the radius of the arc.

e.g. arc(120,160,300,90,70)

line (x1,y1,x2,y2) :


Line function draws a line between two specified points (x,y) towards (x2,y2).This function comes handy if you want to draw box like shapes or just plotting the graphs etc.

e.g. line(100,50,100,400);

You can set the line style using setlinestyle functions.This function specifies the type of line,pattern & the thickness that is going to appear on the screen.You have options like solid,dotted,centered,dashed etc.

e.g. setlinestyle(style,0,1);

putpixel(x,y,color) :



This function is used to put apixel at specified points (x,y).It comes handy when we have to plot a point of specified color at desired location.(color) can be defined in function as “white” or “BLUE” or specify the color code.


e.g. putpixel(100,150,WHITE);

bar (left,top,right,bottom):



This function draws the filled-in,rectangular,two-dimmensional bar.It is filled using the fill pattern and fill color.


Color palettes

The graphics.h has declaration about 16 colors.In order to use the color in your program you have to use the functions like setcolor( ) ,setbkcolor( ) & setfillstyle( ).The function setcolor( ) sets the value of current drawing color to color.setfillstyle( ) sets the current fill pattern and fill color.setbkcolor( ) sets the value for background color,which is by default black.
Below is the table that describes the value for each color that are declared in the graphics.h file.











































































Color





Value




Black




0




Blue




1




GREEN




2




Cyan




3




RED




4




MAGENTA




5




BROWN




6




LIGHTGRAY




7




DARKGRAY




8




LIGHTBLUE




9




LIGHTGREEN




10




LIGHTCYAN




11




LIGHTRED




12




LIGHTMAGENTA




13




YELLOW




14




WHITE




15




Here is an example that makes use of all the available functions explained above, so write the code,compile and observe the effects.




#include"graphics.h#include"conio.h"




void main(){ int gd=DETECT, gm;initgraph(&gd, &gm, "c:/tc/bgi ");circle(330,180,100);rectangle (10,30,500,400);ellipse(100,150,0,360,100,50);arc(120,160,300,90,70);line(100,50,100,400);getch(); closegraph();restorecrtmode ();}


By executing the functions in this program you will observe the circle, rectangle, ellipse, arc & line on the screen. I hope I have covered decent amount of information regarding the basics of the graphics programming using Turbo C++. I hope above information helped, again any suggestions are welcome.

Turbo C++ graphics programming Part 1

Intention of this tutorial is to make you comfortable with the basic concepts in graphics.If you want to learn graphics programming then Turbo C++ 3.0 is good choice.

Under this tutorial i will cover some standard library functions,so you can probably figure out the remaining graphics functions on your own.Basically there are two diffrent modes,namely text mode and graphics mode.In text mode it is possibe to display or capture only text in terms of ASCII.But in graphics any type of figure can be displayed,captured and animated.


First Impressions

To start with graphics programming,you have to set out some of the things on your own like compiler or it’s installation & configuration etc.Example in tutorial wil work no matter which compiler you use, of course some of the library functions have minor variations.I recommend using Turbo C++ 3.0,as it will be readily availbale and it is much easier to use.

Requirement

If you want to start graphics programming then you need two files which are GRAPHICS.H and GRAPHICS.LIB. These files are provided as part of TURBO C++. Check these files. The graphic mode functions require a graphics monitor and adapter card such as CGA,EGA and VGA. I assume you have complete working compiler so here’s how to create circle on the screen.


/* Simple example to draw circle */

#include"graphics.h"


#include"conio.h"



void main()



{



int gd=DETECT,gm;



initgraph(&gd, &gm, "c:/tc/bgi ");



circle(330,180,100);



getch();



closegraph();



restorecrtmode();



}




Code explaination


The first line to look at is: GRAPHICS.H ,this file contains definitions and explaination of all the graphic functions and constants.While GRAPHICS.LIB file contains standard graphic functions.


Turbo C++ graphic functions have two categaries :Text mode graphic functions and graphic mode functions.Here we are dealing with graphic mode function.so just forget about text mode function right now.To switch from text mode to graphic mode,we have function called as ” initgraph ” .


initgraph :

This function initialises the graphic mode.It selects the best resolution and direct that value to mode in variable gm.The two int variables gd, gm are graphic driver and graphic mode respectively.The gm handles value that tells us which resolution and monitor we are using. The gd specifies the graphic driver to be used.In our program we have gd=DETECT means we have passed the highest possible value available for the detected driver.If you don’t want that value then you have to assign the constant value for gd,gm.The ” &” symbol is used for initgraph to pass address of the constants.



Path ( ” C:\\tc\\bgi”) :

It specifies the directory path where initgraph looks for graphics drivers (*.BGI) first. If files are not there then initgraph will look for the current directory of your program.If it unable to find wihtin current working directory then it will parse an error.You can leave it blank ( ” ” ) if the *.BGI files are within the working directory.



Circle( ) :

Circle function takes X and Y values with respect to top left corner of the screen and third co-ordinate is nothing but radius of circle.In our example we have passed X=330,Y=180 and radius equal to 100 in terms of pixels as arguments.



Closegraph( ) :

The closegraph() swithces back the screen from grpahics mode to text mode. If you don’t use this function then you may have undesirable effects.Here this function is called afer the getch() function as screen shouldn’t switch to text mode till user hits any key.

Restorcrtmode( ) :

This mode will restore the original video mode detected by initgraph function.


getch( ) :

getch( ) function gets a character from console but does not echo it on screen.This is used to pause the screen till user hits any key.


Note:

1)

Make sure you have entered the correct path for the include & library directories.You can change the path by pointing your mouse to :

Options > Directories


.Enter the valid path for the include directory and libraries,and output directories.

2)

After installation of Turbo C,you have to adjust the settings of linker.Go to

Options>Linker > Libraries>


and then check the ”

Graphics Library

“.This will help to solve the linker errors for the graphics programs.Please do not uncheck any other option already selected by compiler.

3)

Graphic initialisation depends on the path mentioned in initgraph path.Be sure to enter slash between c,tc,bgi.The path C & TC depends on user if he installed TC in d: drive then it will be d,tc.Read the above code’s path carefully.


4)

If you want help on specific function then point your mouse to “


Help> Contents

“,and then browse the content for the function you want.If you want fast-help then put the cursor on the first letter of the function or term and press

CTRL+F1

,it will point you to the help file of that term/function.

Creating standalone graphics programs for Turbo C++

In this article will cover it up as creating stand alone for the programs we have written in previous articles.



Update to this article will tell you how to achieve this within the software.So allow some time for the post update,till then you can read the rest.Creating standalone programs that will run on any machines is easy.There are three steps:




  • First you insert it into source file certain functions to register the drivers and fonts you use.


  • Second you convert any BGI or CHR files your programs needs to .OBJ files.


    And third you need to link these .OBJ files to your programs using the Turbo C++ project facility.




Register Fonts & Drivers



In order to let your program run on any machine requires registering graphic driver.


Two functions are used for this purpose.The registerbgidriver() function registers drivers


like CGA.BGI and EGAVGA.BGI.



Here is the example of to register the BGI driver.



registerbgidriver(EGAVGA_driver); // register GRAPHICS driver



int driver,mode;


driver=EGA;


mode=EGAHI;


initgraph(&driver,&mode,” “);// inittialize graphics systems


Here initgraph() function doesn’t require pathname once graphics driver is registered.



Simmilarly you can even use function


registerbgifont(arial_font); //register BGI font


Now once you have written your .BGI file,you need to convert it into the .CHR file to be linked into application.Go into the DOS shell and then type “bgiobj”


e.g.



c:>bgiobj egavga



Here egavga is the object file you created (EGAVGA.BGI].Now you are ready to build your project.After building the project,linking and loading will be carried out and then you can see the exe of your project.You can run the executable on any windows machine.



Turbo C++ Build/link procedures will be added later in the article.



Hope this helps.If you have any questions,post them.

Learning Turbo C++

Turbo C ++ 3.0 is the most famous and easy to use IDE for learning C++. It has all you need for C++ development. It is still used in many institutes, colleges & universities even if it is out of date. There are very few articles documented on internet for Turbo C++ IDE.


I’m is trying to make this post be the definitive guide for helping beginners and amateurs out. A lot of the things covered requested by the many readers of onecore.net. I’ll update this post if I found some worthy to post for this IDE, so do check this page once in month. If you’re curious in exploring more resources in TC++ then scroll down for resources section.



History


It’s quite interesting to know the history of the most famous IDE. The history of this famous IDE began in February 28, 1991.The version 1.0 of TC++ runs on DOS only,with support for AT&T 2.0 release of C++. This version is still available as free of cost in the Borland museum. If you’re interested in this old release, go and download it. TC++ 3.0 released in 1991,an updated version with the latest release of AT&T C++, it was targeted for windows 3.0 and support for both dos and protected mode executables. After the version 3.0 Borland started to distinguish between TC and BC as low end and high end compiler, with inclusion of more features in BC++. The version 3.0 was quickly become famous for its high compilation & linkage speed. Many DOS based games were written on Turbo C++ and still it is used for the same purpose.






Recently Borland resurrected the Turbo C++ series with brand name “Turbo Explorer”. With this IDE you can almost do anything that you can do with their commercial IDE’s with few minor restrictions. Under Turbo Explorer you’ve flavors such as Delphi, C++ etc.


Installation


The installation of this IDE is the easiest part. All you’ve to do is run the command line installer and set the path for the directories then it will install on its own. If everything sets up properly you don’t even need to reconfigure it. The version 3.0 also gives you command line access so that you run program from command line or do other operations within the IDE. With this IDE you also get assembler, profiler and debugger. These features are helpful when you dig yourself deeply in the C++.


Setting up directories



If your program gives error for cout and cin operators while programming then it means that compiler is unable to find the include directories. In this case you’ve to manually set the directories. To set up directories manually, follow the steps: In the IDE menu bar >

Options > Directories

. You have to enter the path of the include directory & library directory. The output directory can be any directory of your choice. The source directory path is optional; you don’t need to set it up in order to run your programs.



Working with Turbo C++



In order to see how your program works you need to compile the file first.You can compile the file using steps : in the IDE menu

> Compile > Compile

( ALT+F9) or you can use the shortcut ALT+F9.If it shows no warning and errors then you’re ready to run the program using instructions : in the IDE menu

>Run>Run

( Ctrl+F9).


Similarly to link the file you can do the following step: in the IDE menu > Compile > Link. Then the object file will link with the one or more library file, and you can get the exe file. You can build all the sources if you want to before creating exe file of your program.



If you want to access to any DOS function then you can use listing, copying or deleting files without exiting from the TC, just go the File> Dos Shell.




Help



Turbo C++ has excellent documentation for all the standard functions, header files, routines and I/O operations. If you’ve any background in programming then you can proceed on your own to get most of this IDE. You can read help file: In the IDE menu bar >

Help > Contents

or Index. If you want fast-help then put the cursor on the first letter of the function or term and press CTRL+F1,it will point you to the help file of that term/function.



There are lot of non-standard i.e. Borland’s own functions & libraries available which will make your life easier in this IDE. But don’t get addicted to it as it’ll have trouble while learning other IDE’s. I’ve received comments about why i can’t use conio.h in xxx IDE. Etc. So try to learn which header files & functions are standard.

Resources


There are very few resources available but I’ve tried to cover the most useful feature sets in the IDE like graphics, sound etc. Here is the list of other articles on onecore for Turbo C++.


If you’re looking for official Borland resources then here is the list of resources.

Borland Developer network -museum

I hope the information above helped. If you have any questions or comments, please don’t hesitate to post them.

Wednesday, September 23, 2009

"Header already sent" error and other use of Header function in PHP


Using the Header() function you can do the following things


1) Redirect your user to some other page.

2) Tell the browser not to cache your files

3) Content Disposition.


"Header already sent" error


Most of the PHP learner (including me) has spent hours in debugging this problem. This problem happens while using session variables. While using session variables you must initialize the session using the function session_start(), and the problem occurs here.

This problem has got an unbelievably simple solution, just start the PHP block (where you have written the session_start() at the very first line of the page.


To illustrate this

<?php
session_start();
?>

is OK. But

<HTML>
<?php
session_start();
?>

is wrong.

Again , you can not even leave a blank line above the PHP code as it is considered as HTML code


<?php
session_start();
?>
As you can see there is a blank line above the PHP block , this will raise error.


Another example ,

<?php
echo 'Hello';
session_start();
?>

will give error as the statement "echo 'Hello' output an HTML on the page before "session_start();" is executed .


So , the bottom line is do not output anything before the session_start() is executed.

1) Redirect your user to some other page.

You can redirect you user to some other page using the code "Location" parameter of header() function.


<?php
header ( "Location: http://www.koderguru.com/" ); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>

This code will redirect your user to the page http://www.example.com.

Warning : The statement
"header ( "Location: http://www.example.com/" );"

does not generate 302 response, that mean the page will be redirected but it will not be counted as a hit to "www.koderguru.com", so the target page looses a hit count. To avoid this use the following code.

<?php
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://www.koderguru.com');
?>

This code generates a 301 status and hit count of "www.koderguru.com" will increase.

Also , you can redirect after some interval , using the code


// Redirects the browser after $sec seconds
header("Refresh: $sec; http://www.koderguru.com" );
should be:
header("Refresh: $sec; url= http://www.koderguru.com" );


2) Force the browser not to cache the pages.

You can do this with the code

<?php
// Date in the past , tels your browser the cache has already expired
header ( "Expires: Wed, 06 Jul 2006 05:00:00 GMT" );
// Here the line tells the browser that the last modification date of this page is right now
//So it must reload the page
header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" );
// HTTP/1.1
header ( "Cache-Control: no-store, no-cache, must-revalidate" ); // do not cache/store this page
header ( "Cache-Control: post-check=0, pre-check=0" , false );
// HTTP/1.0
header ( "Pragma: no-cache" );
?>


3) Content Disposition.
You can also generate different type of content other than html , using Header() function

<?php
// We'll be outputting a PDF
header ( 'Content-type: application/pdf' );
// It will be called downloaded.pdf
header ( 'Content-Disposition: attachment; filename="downloaded.pdf"' );
// The PDF source is in original.pdf
readfile ( 'original.pdf' );
?>


The above code tells the browser the type of document is PDF.


So , that's all for now. I hope you find this tutorial useful. Thank You.