Tuesday, 29 January 2013

How to Open, Close, Read and Delete a File in Delphi XE2?

How to Open, Close, Read and Delete a File in Delphi XE2?

File Handling is very simple in delphi programming language. Here is a simple delphi program example for file handling. Following delphi program opens, writes and reads a file. After that the file is closed and finally deleted. Opening a file, reading / writing a file and deleting files are very common functionalities used in any delphi application. Following delphi program example for file handling does the same in very simple way.

procedure MyForm.HowToOpenCloseAndDeleteFile;
var
  fileName : string;
  myFile   : TextFile;
  data     : string;
begin

  // Try to open a text file for writing to
  fileName := 'Test.txt';
  AssignFile(myFile, fileName);
  ReWrite(myFile);
 
  // Write to the file
  Write(myFile, 'Hello World');

  // Close the file
  CloseFile(myFile);

  // Reopen the file in read mode
  Reset(myFile);

  // Display the file contents
  while not Eof(myFile) do
  begin
    ReadLn(myFile, data);
    ShowMessage(data);
  end;

  // Close the file for the last time
  CloseFile(myFile);

  // Now delete the file
  if DeleteFile(fileName) then ShowMessage(fileName+' deleted')
  else ShowMessage(fileName+' not deleted');
end;

Friday, 25 January 2013

jQuery Tutorials: Tips and Tricks for Web Developers

jQuery Tutorials: Tips and Tricks for Web Developers

jQuery has made web designing and development very easy. In this jQuery tutorial, some basic points about jQuery are listed like shorthand for jQuery and importance of CDN (Content Delivery Network). We have also covered some cool jQuery tips and tricks which are commonly used while web designing and development like how to disable right click on web browser in a single line of jQuery script, how to get mouse position using jQuery script, how to find which mouse button was clicked and how to efficiently use jQuery selectors? Every web designer and developer should know these basic tips and tricks of jQuery. These are very easy to learn and grasp and also time saving which reduces human efforts.

1. Use shorthand for $(document).ready()

We can write jQuery code like this:

$(document).ready(function()
{
  //Your jQuery code goes here.
})

But there is a shorthand available for above code. This can be rewritten as

$(function ()
{
   //Your jQuery code goes here.
});

2. Always load jQuery framework from Google, Microsoft or jQuery CDN(Content Delivery Network).

CDN provides several advantages:

1. You always use the latest jQuery framework.
2. It reduces the load from your server.
3. It saves bandwidth. jQuery framework will load faster from these CDN.
4. The most important benefit is, it will be cached if the user has visited any site which is using jQuery framework from any of these CDN.

Code to load jQuery Framework from Google CDN

<script  type="text/javascript"
    src="
http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>

Code to load jQuery Framework from Microsoft CDN

<script  type="text/javascript"
    src="
http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js">
</script>

Code to load jQuery Framework from jQuery Site(EdgeCast CDN)<script  type="text/javascript"
    src="
http://code.jquery.com/jquery-1.4.2.min.js">
</script>

3. How to disable right click using jQuery?

You can find many java script code snippets to disable right click. But jQuery makes our life easy. Below jQuery code disables the right click of mouse.

Method 1:

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});

Method 2:

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        e.preventDefault();
    });
});

4. How to get mouse cursor position using jQuery?

$(document).ready(function(){
  $(document).mousemove(function(e){
     $('#spnCursor').html("X Axis : " + e.pageX + " Y Axis : " + e.pageY);
  });
});

When the DOM is ready, we listen for mousemove event. Whenever user moves the mouse then this event gets called and we bind the pageX and pageY property to the span element.

5. How to find which mouse button is clicked using jQuery?

If you need to determine which mouse button (Left, Middle or Right) was clicked. jQuery provides mousedown() event, using which we can check which mouse button is clicked. For key or button events, event attribute indicates the specific button or key that was pressed. event.which will give 1, 2 or 3 for left, middle and right mouse buttons respectively. The advantage of using event.which is that it eliminates cross browser compatibility.

$(document).ready(function() {
$('#btnClick').mousedown(function(event){
    switch (event.which) {
        case 1:
            alert('Left mouse button pressed');
            break;
        case 2:
            alert('Middle mouse button pressed');
            break;
        case 3:
            alert('Right mouse button pressed');
            break;
        default:
           break;
    }
});
});

6. How to use jQuery selectors efficiently?

It is pretty important to understand how to write efficient element selection statement. One has to be very careful while jquery selector statement. Below are some tips on how to use your jQuery selectors efficiently.

A. Always try to use ID as selector

You can use ID as selector in jQuery. See below jQuery code.

$("#elmID");

When IDs are used as selector then jQuery internally makes a call to getElementById() method of Java script which directly maps to the element.

When Classes are used as selector then jQuery has to do DOM traversal.So when DOM traversal is performed via jQuery takes more time to select elements. In terms of speed and performance, it is best practice to use IDs as selector.

B. Use class selector with tags

You can use CSS classes as selector. For example, to select elements with "myCSSClass" following jQuery code can be used.

$(".myCSSClass");

As said earlier, when classes are used DOM traversal happens. But there could be a situation where you need to use classes as selector. For better performance, you can use tag name with the class name. See below

$("div.myCSSClass");

Above jQuery code, restricts the search element specific to DIV elements only.

C. Keep your selector simple, don't make it complex

Avoid complex selectors. You should use make your selectors simple, unless required.
$("body .main p#myID em");

Instead of using such a complex selector, we can simplify it. See below:

$("p#myID em");

D. Don't use your selector repeatedly

See below jQuery code. The selectors are used thrice for 3 different operation.

$("#myID").css("color", "red");
$("#myID").css("font", "Arial");
$("#myID").text("Error occurred!");

The problem with above code is, jQuery has to traverse 3 times as there are 3 different statements.But this can be combined into a single statement.

$("p").css({ "color": "red", "font": "Arial"}).text("Error occurred!");
 
E. Know how your selectors are executed

Do you know how the selectors are executed? Your last selectors is always executed first. For example, in below jQuery code, jQuery will first find all the elements with class ".myCssClass" and after that it will reject all the other elements which are not in "p#elmID".

$("p#elmID .myCssClass");

Thursday, 17 January 2013

Best Free XML Editors and Viewers

Best Free XML Editors and Viewers

Here is the list of best free XML Editors and Viewers which will make it easy for you to understand XML. Professional XML editors will help you to write error-free XML documents, validate your XML against a DTD or a schema, and force you to stick to a valid XML structure.
An XML editor should be able to:

1. Add closing tags to your opening tags automatically
2. Force you to write valid XML
3. Verify your XML against a DTD
4. Verify your XML against a Schema
5. Color code your XML syntax

Need of an XML Editor

Today XML is an important technology, and development projects use XML-based technologies like:

1. XML Schema to define XML structures and data types
2. XSLT to transform XML data
3. SOAP to exchange XML data between applications
4. WSDL to describe web services
5. RDF to describe web resources
6. XPath and XQuery to access XML data
7. SMIL to define graphics
8. To be able to write error-free XML documents, you will need an intelligent XML editor!

List of Best Free XML Editors and Viewers

1. XML Notepad

XML Notepad is Microsoft’s contribution to the XML editor forum. Based in class on the popular text editor dispensed with Windows operating systems, Notepad, the XML module offers a semi WYSIWYG design. The tree view and text view are color coded and use bold shapes to identify the elements and their family relationships for XPath navigation. Overall, Microsoft’s XML Notepad is not a terrible choice for those with a basic understanding of XML. Additionally, the program helps design and produce XSL style sheets to accompany the XML information and create an output stream.

2. FOXE XML Editor

First Objective Software Inc. produces a free editor that works as an advanced text editor . FOXE offers some basic tools for authoring code but does not delve too far into styling. The program does provide some inherent code that allows you to navigate files, define XPath information and split documents. This is a decent choice for those learning to take baby steps in XML production. The tree view and embedded scripts make FOXE a better choice than a standard text editor, but the program still makes you work to learn  to write effective XML.

3. Serna Free – Open Source XML Editor

Serna is a WYSIWYG editor produced by Syntext that goes beyond the norm. Like most XML editors, Serna begins with the classic split screen and works exclusively in a WYSIWYG style. It will take some practice to get used to the interface, but once you understand the basic tools, creating your document is straightforward. This is an editor for someone who has a clear understanding of XML technology and looking for a shortcut. Newcomers need to understand the basics of valid XML before attempting to work within the Serna environment..

What is an XML File or XML Document? Why to use XML?

What is an XML File or XML Document? Why to use XML?

This article covers basics of XML. We will discuss some benefits and advantages of XML.

What is XML?

XML is Extensible Markup Language. XML is a specification developed by W3C. XML is a standard, simple, self-describing way of encoding both text and data so that content can be processed with relatively little human intervention and exchanged across diverse hardware, operating systems, and applications.

In brief, XML offers a widely adopted standard way of representing text and data in a format that can be processed without much human or machine intelligence. Information formated in XML can be exchanged across platforms, languages, and applications, and can be used with a wide range of development tools and utilities.

Example of XML Document

<bag label="Glenns Food" storage-date="October, 2001">
  <item>Candy Bar</item>
  <bag label="Vegetables" storage-date="Oct 11 2001">
 <item>Carrot</item>
 <item>Lettuce</item>
  </bag>
  <bag label="Fruits" storage-date="Oct 13 2001">
 <item>Pear</item>
  </bag>
</bag>

Difference between HTML and XML

XML is similar enough to HTML in its actual format. But there are two fundamental differences:

1. Separation of form and content -- HTML mostly consists of tags defining the appearance of text; in XML, the tags generally define the structure and content of the data, with actual appearance specified by a specific application or an associated stylesheet.

2. XML is extensible -- tags can be defined by individuals or organizations for some specific application, whereas the HTML standard tagset is defined by the World Wide Web Consortium (W3C).  

Advantages of XML

1. Simplicity

Information coded in XML is easy to read and understand, plus it can be processed easily by computers.

2. Openness

XML is a W3C standard, endorsed by software industry market leaders.

3. Extensibility

There is no fixed set of tags. New tags can be created as they are needed.

4. Self-description

In traditional databases, data records require schemas set up by the database administrator. XML documents can be stored without such definitions, because they contain meta data in the form of tags and attributes.

XML provides a basis for author identification and versioning at the element level. Any XML tag can possess an unlimited number of attributes such as author or version.

5. Contains machine-readable context information

Tags, attributes and element structure provide context information that can be used to interpret the meaning of content, opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc.

This is a major advantage over HTML or plain text, where context information is difficult or impossible to evaluate.

6. Separates content from presentation

XML tags describe meaning not presentation. The look and feel of an XML document can be controlled by XSL style sheets, allowing the look of a document (or of a complete Web site) to be changed without touching the content of the document. Multiple views or presentations of the same content are easily rendered.

7. Supports multilingual documents and unicode

This is important for the internationalization of applications.

8. Facilitates the comparison and aggregation of data

The tree structure of XML documents allows documents to be compared and aggregated efficiently element by element.

9. Can embed multiple data types

XML documents can contain any possible data type - from multimedia data (image, sound, video) to active components (Java applets, ActiveX).

10. Can embed existing data

Mapping existing data structures like file systems or relational databases to XML is simple. XML supports multiple data formats and can cover all existing data structures and

11. Provides a 'one-server view' for distributed data

XML documents can consist of nested elements that are distributed over multiple remote servers. XML is currently the most sophisticated format for distributed data - the World Wide Web can be seen as one huge XML database.

Key Features of a Professional Web Design and Development Company

Key Features of a Professional Web Design and Development Company

Today, if you have a business, you must have a website for it. Your website sells your products and services to the whole world. In today's fast-paced, technology-driven business world, it is simply a fact of life that if your business doesn't have an online presence, you're going to have a much harder time succeeding.

Next thing, you don't need only a website but a quality and good looking attractive website. These days your website is your storefront. Just as a run-down storefront can send customers to your competitor across the street, a poorly-designed website can send them to the next Google search result. In other words, you don't just need a website. You need a high-quality website. You need an attractive design with an intuitive layout and well-written content.

So, for having your own business website, you should consult a good website designing and development company. Before giving contract of your business website to any web designing and development company, you must ensure following points:

1. Web Design and Development company must have a recognized name in the web design and development industry.

2. Web Design and Development company must have good experience and knowledge in web design domain. Ask for the previous project samples on which they have worked upon.

3. Always get to know about their clients and customers with which they are dealing. Go through the testimonials their clients have written for them. Always check the track record of the company.

4. Not only web design, also ask for different kind of facilities your web designing and development company should provide you like content management, blog posting, email services, web hosting, social media (twitter, facebook, linkedin) connection tools etc.

5. While giving contract to any web designing and development company, must ensure that you require not only web version of your website but also the mobile version.Today, internet is accessible from mobile also. Don't let your website look obsolete and unstructured on mobile. So, while designing your website, you must ensure that your website should look nice both in web browser and mobile browsers. Also check you website design on various browsers like Firefox, Chrome, IE, Opera, Safari etc.

6. If your website involves some money transaction features, you must get ensured from your web design and development company that they use security certificates and third party certified tools for transactions like amazon and ebay. Instead of http, https should be used in the url of your website.

7. You must have knowledge about SEO (Search Engine Optimization). Always ask your web design and development company that what measure they are taking for Search Engine Optimization. SEO is very important for any website. Always get ensured that the content of your website is targeting the keywords which are searched on search engines like google, yahoo, msn, ask etc.  People these days don't go to their telephone directory to look for local businesses anymore. They go to their computers and search for them. And if your business doesn't come up in your search results, they don't even consider looking for you anywhere else.

8. Internet Marketing is a key concept today in web designing and development market. Your web design and development company should take responsibility for that. Social media marketing on facebook and twitter is very vital for your website.

9. Logo design, PDF creation, Brand promotion, Brochure designing are the plus points of a web designing and development company.

10. Always ask for post maintenance charges of the website from your web designing company.

11. Free online and customer care support should be provided by your web design and development company.

Basic Tips for Professional Webpage Designers

Basic Tips for Professional Webpage Designers

Are you a professional webpage designer? or
Are you new to webpage design and going to learn it?

Does not matter!!

Following are some basic tips which each webpage designer must follow. Webpage designing is very easy and interesting. You can learn webpage designing in no time if you take interest in it. You don't have to learn any complex algorithm or diagrams for this. Learning web design online is very easy. There are a lot of websites which will teach you web design from the scratch.

You will have to learn HTML, CSS and Javascript for web design. Flash, Photoshop will be a plus. Today, HTML5 has eliminated the need of Flash. CSS3 has now lot of advanced features which are provided by Photoshop like gradient effects, animations, rounding the corners of images etc.

You can get a lot of web design templates online. There are a lot of free editors available for HTML, CSS and Javascript which will help you in learning web designing.

For now, I have listed some basic points which each web designer must have in mind before designing any webpage.

1. Include Doctype in your webpages

The DOCTYPE defines which version of HTML you are using, and gives important information to your browser so it can render your page faster and more consistently.

The DOCTYPE declaration also allows validating software to check the syntax of your page.
<!DOCTYPE html>

2. Include Title in your webpages

The <title> element is one of the most important HTML elements. Its main function is to describe the content of a web page. It is important to the quality of your web site because it will be visible in search engine lists, the browser's title bar and user's bookmark.

The title should be as short and descriptive as possible.
 
When a user searches for a web site, most search engines will display the title of your web site in the search result. Make sure the title matches the content the user is looking for. Then it is more likely the user will click on the link to visit your web site.

3. Use Headers in your webpages

The <h1> element is used to describe the main heading of a web page. You can use <h2>, <h3>, <h4> etc to arrange your content in your webpage. This will be great approach for search engine optimization.

4. Follow CSS standards

With CSS, you can store all style information for your web site in one single document. Using Cascading Style Sheets (CSS) is the preferred way of separating content from style in quality web pages.

Using CSS will improve the quality of your web site and increases the readability for many different browsers. It will also greatly reduce your web site development costs.

5. Use Web Validators

A validator is a software program that can check your web pages against the web standards.
When using a validator to check HTML, XHTML or CSS documents, the validator returns a list of errors found, according to your chosen standard.

6. Do not use fixed sizes

Never use fixed size values. Always use relative size values.

The most important reason for this advice is that fixed sizes can not be resized by the browser.
Your visitors will have different monitors, different viewing conditions (light), and possible disabilities (poor eyesight).

Setting your default text size to 100% (or medium), your main headers to 140% (or x-large), your sub headers to 120% (or large), as an example, will make it possible for your reader to resize your pages to their best fit.

7. Take care of different date formats

Don't use dates like "04-03-02". This is confusing.

The date above could mean the 2nd of March, 2004. It could also mean the 4th of March, 2002. Or even the 3rd of April, 2002.

The International Standard Organization (ISO) has defined an international format for dates as "yyyy-mm-dd", where yyyy is the year, mm is the month, and dd is the day.

When you use this ISO format, you can expect most visitors to understand your dates.

8. Always take care of font-family, line spacing, letter spacing, color contrasts, foreground and background colors.

Wednesday, 16 January 2013

Alcohol and Drug Addiction Programs and Rehab Centers Worldwide

Alcohol and Drug Addiction Programs and Rehab Centers Worldwide

Are you addicted to alcohol and drugs? Do you want to free yourself from this addiction?

If yes, this webpage might help you out.

Human life is full of ups and downs. It is easy to get trapped in alcohol and drug in your low time. You start from very low amount of this poison (alcohol and drugs) to shed away your stress, but you will not realize when you get addicted to these drugs. Once you get addicted to alcohol or drugs, its not easy to leave them.

Alcohol and Drug Addiction Programs

You will come to know here that how you get addicted to the alcohol and drugs and what bad effects these have put on your health and wealth. During your rehab, you will probably receive individual counseling with a trained addictions counselor and you will possibly participate daily in group therapy meetings with others at the facility.

These sessions are designed to begin to teach you the skills that you will need to live life without drugs and alcohol. You will learn how to recognize situations in which you are most likely to drink or use drugs and how to avoid these circumstances if possible. You will learn new coping skills.

Many successful drug and alcohol rehab programs will include members of your family in your treatment program. Research has shown that including family and friends in the educational process significantly improves rehab outcomes. Some programs include family members and friends throughout the entire rehab process, from the initial assessment through continued follow-up aftercare.

In the family meetings, your family members will learn about the dynamics of addiction, learn to identify strengths and resources to help encourage you in your recovery, discuss how they have been affected by your substance abuse and learn how they also can begin to heal their own wounds.
 
The typical residential drug and alcohol rehab program will last about 28 days, sometimes longer, during which you are in a structured environment where no drugs are alcohol are available. Then what? What happens when you have to leave the relative safety of the facility and go back into the real world?

Successful rehab programs have a strong aftercare program plan designed to meet your individual needs. By now your counselor probably knows you well and will suggest the next steps to take based on where you are on your recovery journey.

Alcohol and Drug Rehab Centers Worldwide

We found some useful information on About.com about alcohol and drug rehab centers. Here is the list of more than 10,000 alcohol and drug rehab centers. Most of them are free. Some rehab centers charge minimum fees which is affordable to all. You don't have to go to any expensive alcohol and drug rehab center as the quality of treatment provided in the above listed free or cheap rehab centers is comparable to the expensive ones.

Most states and even some cities and counties offer outpatient and inpatient alcohol and drug treatment facilities that are completely tax supported and charge no fees. These programs can range from short-term detoxification centers, long-term residential treatment facilities to individual outpatient counseling at local clinics.