• Awesome Blogging Theme!
  • Active Yoga Class

Introduction to Delphi programming

CHAPTER 1 - 32-Bit Console Applications

• Console I/O
• Console Filter Programs
• Console Command-Line Parsers
• Console File I/O
• Using Delphi‘s Object Repository
Now that DOS has been stuffed and hung on the wall of Win32 as
a minor API, how’s a hacker to do command-line text filters?
Well, the POSIX fairy waved her magic wand, and Poof! DOS
became The Console, and it’s deja vu all over again.
Windows, OS/2, the Macintosh, and other graphical user interfaces have
been the darlings of the computer press (both technical and non-technical) for
many years now. With all that attention focused on writing applications for
these GUI environments, it’s sometimes tough to remember that there is
another world out there—a world of command-line tools that perform batch
processing with a minimum of user input. These tools aren’t especially sexy,
but they’re certainly useful. Banks, for example, still process your checks,
deposits, and loan payments in batches every night. Insurance and credit card
companies also perform nightly updates, as do countless other businesses.
(And do they use fancy GUI environments? Ask your bank teller. Or guess.)
Command-line tools aren’t limited to companies running financial programs
on big iron. Windows 95 itself comes with quite a few: ATTRIB, DISKCOPY,
FORMAT, FDISK, SORT, and XCOPY among them. Even Delphi comes
with some command-line tools. A quick peek in Delphi’s BIN directory
reveals (among others) the Resource Compilers (BRC32.EXE and
BRCC32.EXE), the Pascal compiler (DCC32.EXE), and the linker
(TLINK32.EXE).
Console Applications
Windows 95 and Windows NT support console applications—programs that
have no GUI presence but instead run in what is commonly referred to as a
“DOS box.” Although these applications don’t have a window, they do have
access to the Windows API and the full 32-bit Windows address space
(including virtual memory). This is in contrast to Windows 3.1, where GUI
programs had access to Windows’ address space, and DOS programs had
access to the lower 640K.
In the past, DOS applications got around the 640K limitation through the use
of DOS extenders that supported standards like DPMI (DOS Protected Mode
Interface) and VCPI (Virtual Control Program Interface). If you had a 16-bit
extender, you had access to 16 megabytes of memory. The less common 32-bit
extenders gave you access to the full 32-bit address space, and some even
supported virtual memory. The problem with DOS extenders is that they
are—no matter how well presented—hacks. And many users simply couldn’t
get their older machines to reliably run the DOS extenders, and some DOS
extenders couldn’t run in a Windows DOS box.
A console application running under Windows 95, on the other hand, is simply
a Windows program without a window. There’s no special extender software
required, and any computer that can run Windows 95 or Windows NT will
support console applications.
So we’ve got the RAM and we’re free of the GUI. What can we do with it?

Filters
Probably the most common use of command line tools in the PC world is the
broad category of programs called “filters.” A filter can be anything from a
very simple line counter to a complex compiler (like Delphi’s Pascal
compiler), a sorting utility, or a batch update program.
All filters operate basically the same way: They’re invoked from the command
line and passed arguments that specify options, and input and output files. The
filter reads the input, applies some processing (such processing modified by
the options specified on the command line), and writes an output file.
Filters typically don’t access the mouse, and in fact, rarely accept user input. If
they do accept user input, it’s through a very simple text-oriented interface.
Output to the user is normally limited to status reports (“Working, please
wait...”), error notifications, and a final “done” message.
In this chapter, we’re going to build a relatively simple filter program with
Delphi, and construct a filter program “shell” that you can use to quickly build
other filter programs. Along the way, we’ll learn a thing or two about Delphi’s
Object Repository, reusable code, and (shudder) process-oriented
programming.
NOTE:
I find it ironic that three years ago I was explaining Windows programming
to DOS programmers, telling them how to move away from their
process-oriented mindset and move into the wide world of event-driven
Windows programming. With the advent of visual development tools like
Visual Basic and Delphi, many new programmers started with
event-oriented programming and haven’t ever written a process-oriented
command line tool. Now I’m explaining process-oriented programming to
event-oriented programmers. Plus ça change. One good thing, though:
Programmers who understand event-oriented programming have little
trouble understanding process-oriented code. The reverse, sadly, is not true.

Console Applications and Delphi
Although it’s possible to write console applications with Delphi, the
documentation is suspiciously silent on exactly how such a thing is done.
Considering the excellent demo programs that explore so many other facets of
Delphi, I found the lack of an example console application surprising.
Fortunately, creating a console application with Delphi is not very difficult,
although it would have been nice to be informed about a couple of the details.
(Trial-and-error is such an inefficient way to learn!)
The simplest console app is, of course, the “Hello, world” program. It’s not an
exciting program, but it’s usually the first program I ever write with a new tool
because it lets me learn about the tool without having to worry too much about
the program itself. And once we’ve created a simple console app with Delphi,
we can save the code in the Object Repository so it can be used as the starting
point for other console apps. Let’s get started.

Hello, Delphi
Start with a new application (File|New Application). First we need to change
some of the project options to tell Delphi that we’re creating a console app. Select
Project|Options, and on the Linker page of the Project Options dialog box, check
the “Generate console application” check box, and then click on OK to save this
change.
Since console applications don’t have a main form (or any other form for that
matter), we need to remove the Form1 that is automagically created when you
start a new application. Select File|Remove from Project, and when the Remove
From Project dialog box appears, highlight the line that contains Unit1 and
Form1, and click on the OK button. If a message box appears and asks you if you
want to save changes to Unit1, say No. You’ll be left with a Delphi screen that
has only the Object Inspector. No Form or Unit window will be shown. So where
do you write the code?
The one thing that’s left is the project source file. Select View|Project Source, and
Delphi will display a text editor window that contains the source of
PROJECT1.DPR. It’s this file that we’re going to modify in order to create our
first console application. Before you do anything else, select File|Save, and save
the project as HELLO.DPR.
Modify the project source in the editor so that it resembles Listing 1.1, save your
work, and then press F9 to compile and run the program.
Listing 1.1 The “Hello, Delphi” program
{$APPTYPE CONSOLE}
program Hello;
uses Windows;
begin
WriteLn ('Hello, Delphi!');
Write ('Press Enter...');
ReadLn;
end.
The first line in Listing 1.1 is a compiler directive that tells Delphi to create a
console application, and must be included at the top of any console application.
This line should only be included in programs—not units or libraries (DLLs). The
uses statement isn’t necessary for the program (after all, the program isn’t making
any Windows API calls), but for some reason, Delphi doesn’t like to save a
project that doesn’t have a uses statement (see again my comment about
trial-and-error learning). Windows seemed like a fairly innocuous unit to list here,
and listing a unit doesn’t mean that it’s linked in—only that Delphi will search
that unit if it can’t find an identifier.
The rest of the program is real simple. The string “Hello, Delphi!” is output to the
console (that is, the screen), and then you’re prompted to press Enter. I included a
prompt for the Enter key because, without it, Delphi just displays a console
window (“DOS box”) briefly, runs the program and displays the hello message,
and then closes the console window. The prompt lets you see that the program
actually works.

Saving a Program Template
The steps required to build a console app aren’t especially difficult, but there are a
few details to remember. Rather than building from scratch every time (and
forgetting a detail or two), let’s save our little Hello program in the Object
Repository so that we’ll have a starting point for other console apps.
Using the Windows Exploder (what we called File Mangler under Windows NT
3.51), create a subdirectory called ConsoleApp in Delphi’s Objrepos subdirectory.
If you installed Delphi using the standard options, the full path name will be:
C:\Program Files\Borland\Delphi 2.0\Objrepos\ConsoleApp
Then, select Project|Save Project as from Delphi’s main menu, and save the
project as ConsoleApp.dpr (don’t you just love long file names?) in that new
directory.
Once you’ve saved the project, add it to the repository by selecting Project|Add to
Repository, and fill in the Add to Repository dialog box Once you’ve added the project to the Repository, select File|New from Delphi’s main menu, select the Projects page of the New Items dialog box, and double-click on the “Console Application” icon. Delphi will prompt you for a
directory and create a new project that has the options set for the console application.

NOTE:
I haven’t quite decided if it’s a good idea to store your own objects in Delphi’s
Object Repository directory. Whereas it’s a handy place to put things, it’s also
asking for trouble if you ever upgrade your version of Delphi. If you upgrade,
it’s quite likely that Delphi’s Objrepos directory will be deleted—along with all
of your cool objects. You’ll have to back up your objects before you upgrade.
You can, if you’d rather, create your own Repository directory that’s not a child
of Delphi’s main directory. Either way, you’ll have to again add the projects to
Delphi’s repository after you upgrade, but with a separate directory, you won’t
run the risk of inadvertantly deleting your projects’ source code.

Console Input and Output
When a console application is started, the Input and Output standard text files
are automatically associated with the console window. As a result, the
ReadLn and WriteLn procedures work as expected, as do Eof, Eoln, Read,
Write, and the other Text file I/O functions.
There are a number of console-specific I/O functions that can come in handy
from time to time. Unfortunately, these console-specific functions are defined
in the Windows console interface and there’s no convenient Delphi component
wrapper to insulate us from the gory details. (Now there’s a good shareware
project for an enterprising programmer: a Delphi class that encapsulates the
Windows console interface.) The Windows console interface is a chapter in
itself, so I’m going to conveniently ignore it here. If you’re interested in
learning more about PeekConsoleInput, WriteConsole, and the rest of the
console API functions, check out the “Console Functions” entry in Delphi’s
online help.
Because we don’t have space here to discuss the Console API, we’re going to
limit our console input and output to the standard Text file I/O routines. Don’t
take this the wrong way. The Console API functions are useful for some
applications—just not for the kinds of applications that you’ll typically write
as console apps. Yeah, I know, it’s confusing. It turns out that the Console API
is much more useful for GUI programs that want to control a console window
than it is for straight console applications controlling themselves.
Console apps aren’t limited to a boring old text mode interface. Since you’ve
got access to the full Windows API, you can display message and dialog
boxes, control other windows, and even create another console from within
your application.

Filter Programs in Delphi
Now that we know how to create a console application, let’s put that
knowledge to use. The rest of this chapter is concerned with writing filter
programs as console apps. After an overview of how filter programs work,
we’re going to discuss processing the command line and efficient file
operations. We’ll be cutting a wide swath through Delphi’s standard run-time
library, and won’t have time to discuss every function in detail. Remember that
online help is your friend—use it early and often.
Your Basic Filter Program
As I mentioned at the beginning of this chapter, filter programs typically
accept a command line that specifies options and input/output filenames,
crunch the input as specified by the options, and produce the output file.
Given that general description, there’s lots of room for improvisation. A line
counter program, for example, could accept multiple input file names
(including wildcards), and could have options that tell it to report not only the
number of text lines in a file, but also the number of words and characters, and
possibly a frequency distribution of words and characters. In a more involved
program, the output can be a simple transformation of a single input file, a
single file that combines multiple input files, or many different files created
from a single input file.
Despite the differences in complexity, filters share a large amount of common
functionality. They all process the command line, read input files, and write
output files. Only the intermediate processing step changes significantly from
one program to another. Because of this commonality, it’s possible to build a
group of functions that provide the common functionality and allows you to
quickly build a custom filter program by simply defining how the command
line is to be parsed and writing the code for the “processing” step. The input,
output, and command line parsing portions are all there. Kind of a dehydrated
filter program—just add processing.
Processing the Command Line
Command line processing sounds so simple. Given a text string that represents the
command line, we want to parse out the file names and options, and set the
program’s variables accordingly. I’m continually amazed at how difficult such a
simple-sounding thing can be. Fortunately, Object Pascal has two standard
functions, ParamCount and ParamStr, that make things a bit easier.
ParamCount simply returns a count of the parameters on the command line. So if
your command line is “MyFilter file1.txt file2.txt”, ParamCount will return 2.
The program name itself isn’t counted as a parameter by this function.
ParamStr accepts an integer and returns a string that contains the command line
argument that corresponds to that integer. For example, given the above command
line, this statement
WriteLn (ParamStr (1));
will output ‘file1.txt’ (without the quotes).
If you pass 0 to ParamStr, the returned string will contain the full path and file
name of the program that’s currently being executed.
The Params program shown in Listing 1.2 illustrates the use of ParamCount and
ParamStr. To create this program, select File|New from Delphi’s main menu,
select the Console Application item from the Projects page of the New Items
dialog box, and then tell Delphi where to put your new application. Be sure to
save the project as Params.dpr before you modify it.
Listing 1.2 The Params program
{$APPTYPE CONSOLE}
{
Params -- a simple exploration of the ParamCount and
ParamStr functions.
}
program params;
uses Windows;
Var
i : Integer;
begin
WriteLn ('Program: ', ParamStr (0));
WriteLn ('ParamCount = ', ParamCount);
WriteLn ('Parameters');
WriteLn ('----------');
for i := 1 to ParamCount do
begin
WriteLn (ParamStr (i));
end;
Write ('Press Enter...');
ReadLn;
end.

If you want to test the program from within Delphi, you need to select
Run|Parameters from Delphi’s main menu and enter the command line that you
want to have passed to the program. For the above example, you’d enter the string
“file1.txt file2.txt” (without the quotes) in the Run parameters dialog box.
Simple, no? Unfortunately, not so simple. Back in the days of DOS and Windows
3.1, things really were simple. But then along came long file names with
embedded spaces. Now we have a problem. You see, ParamCount and
ParamStr assume that command line arguments are separated by spaces. This
works fine as long as your files don’t have embedded spaces, but try this
command line:
params c:\program files\borland\delphi 2.0\readme.txt
ParamCount returns 3, and the individual parameters it reports are
c:\program
files\borland\delphi
2.0\readme.txt
which is clearly not what we intended! (Okay, so maybe long file names aren’t all
peaches and cream—beer and skittles if you’re British. Warm beer.)
I won’t go into all the possible solutions to this problem. If you want a full
discussion of this problem and the possible solutions (none of which are
satisfactory, by the way—thank you Microsoft), get a copy of Lou Grinzo’s Zen
of Windows 95 Programming, also published by Coriolis Group Books. The book
is ostensibly about C and C++ programming for Windows 95, but there’s a wealth
of good information in there for all programmers, especially in the way of writing
bug-free programs. This book is among the top three programming books I’ve
ever read, along with Writing Solid Code and Debugging the Development
Process, both written by Steve Maguire and published by Microsoft Press.
The only workable (although not satisfactory) solution to the embedded spaces
problem is to require that file names containing embedded spaces be surrounded
by quotation marks. So our sample command line becomes:
params "c:\program files\borland\delphi 2.0\readme.txt"
I guess you could require that your users always pass the short version of the file
name, but I suspect they’d be more upset having to enter this
params c:\progra<1\borland\delphi<1.0\readme.txt
than they would be about the quotation marks.

Command Line Options
Most (definitely not all) command line programs get their parameters via the
command line. Sometimes you’ll see programs that receive their parameters from
environment variables or configuration files, and some are hybrids that can accept
parameters from the command line or from a configuration file whose name is
specified on the command line. Since we don’t want to get too bogged down in
parameter processing, we’re going to ignore the configuration files and
environment variables, and concentrate solely on command line parameters.
You’ve probably used a command line tool (like DIR) that accepts options
prefaced by a slash (/). For example, if you want a listing of files in the current
directory and all of its subdirectories, you’d enter the command: DIR /S. Many
programs also accept command line parameters prefaced by the dash (or minus
sign, -). Both are common, and many programs will accept either.
File names, on the other hand, are specified in many different ways, depending on
the tool. COPY, for example, lets you specify the name of the input and output
files without prefacing them with option characters. So COPY FILE1 FILE2
copies FILE1 to FILE2. Borland’s MAKE program, on the other hand, requires
that you preface the input file name with the -f parameter. So, to process
BUILD.MAK, you’d enter this command: MAKE -fbuild.mak.
The way MAKE processes command lines is easier, because everything is an
option. Every option is separated from the others by at lease one space, and file
names are handled just like other options—there aren’t any special cases. This is
the model we’re going to use for our filter programs.
In general, there are four kinds of command line options: switches, numbers,
strings, and file names. Switches simply turn an option on or off. A text filter, for
example, might have a switch option to convert all lower-case characters to
upper-case. Numbers can be integers or floating point, and can be specified in any
number of ways: decimal and hexadecimal being the most common. Strings and
file names are similar, although file names are often validated to ensure that
they’re properly formed.

A Reusable Command Line Parser
If there’s anything I dislike about programming, it’s slogging through dozens (or hundreds) of lines of code
to do something for the tenth (or hundredth) time. Command line parsing is like that: Every filter program
has to process the command line, and command line parsing is boring code after you’ve written it once or
twice. So I keep trying to come up with a generalized command line parser that will, with a minimum of
effort on my part, parse a command line and fill in my program’s options structure. That way, I’ll have more
time to spend on the filter (the real problem, after all) rather than on the command line parser.
A generalized command line parser is not an easy piece of code to write, and even a minimal one can be a bit
involved. The one we’ll develop here is minimal, but functional for many applications.
The basic idea is to define the valid option characters, the type of each option, and the default value for each
option. The structure that contains this information is passed to the command line parser, which chews up the
command line and fills in the values for the individual options that it finds. If it finds an error (an invalid
option or a number where it expected a switch), it spits out an error message, stops processing, and returns an
error status to the calling function. Simple, right? Ahhh...but not so easy.
An individual options record takes the format of the OptionsRec structure shown in Listing 1.3. This listing
contains the full source of the CmdLine unit. You should create a new file in your editor, and enter and save
this code as CMDLINE.PAS.
Listing 1.3 The CmdLine unit
{
CMDLINE.PAS -- Command line parameters parsing
}
unit cmdline;
interface
type
OptionType = (otBool, otInt, otString, otFilename);
pOptionRec = ^OptionRec;
OptionRec = record
OptionChar : char;
case Option : OptionType of
otBool : (OnOff : Boolean);
otInt : (Value : Integer);
otString : (Param : ShortString);
otFilename : (Filename : ShortString);
end;
pOptionsArray = ^OptionsArray;
OptionsArray = Array [1..1] of OptionRec;
{
GetOptionRec -- return a pointer to the options record in the
passed Options array that corresponds to the specified option
character. Returns Nil if the option character is not in
the passed Options array.
}
function GetOptionRec
(
Options : pOptionsArray;
nOptions : Integer;
OptionChar : char
) : pOptionRec;
{
ProcessCommandLine -- process the command line according to the
parameters list passed in the Options array. Returns True if
successful, or False if an error occurred in processing.
}
function ProcessCommandLine
(
Options : pOptionsArray;
nOptions : Integer
) : Boolean;
implementation
uses SysUtils;
{
GetOptionRec -- return a pointer to the options record in the
passed Options array that corresponds to the specified option
character. Returns Nil if the option character is not in
the passed Options array.
}
function GetOptionRec
(
Options : pOptionsArray;
nOptions : Integer;
OptionChar : char
) : pOptionRec;
var
i : Integer;
begin
Result := Nil;
for i := 1 to nOptions do begin
if (Options^[i].OptionChar = OptionChar) then begin
Result := @Options^[i].OptionChar;
Break;
end;
end;
end;
{
ProcessBool
Extract the on/off state for a parameter. If the passed Param
is a blank string, it is assumed to be On (+). Otherwise the
routine expects the string to start with + or -, and sets the
OnOff variable accordingly.
}
function ProcessBool
(
Param : String;
var OnOff : Boolean
) : Boolean;
begin
Result := True;
if (Length (Param) = 0) then begin
OnOff := True;
Exit;
end;
case Param[1] of
'+' : OnOff := True;
'-' : OnOff := False;
else begin
WriteLn ('Error: + or - expected');
Result := False;
end;
end;
end;
{
ProcessInt
Extract an integer from the passed command line parameter.
}
function ProcessInt
(
Param : String;
var Value : Integer
) : Boolean;
begin
if (Length (Param) = 0) then begin
Result := False;
WriteLn ('Error: integer expected');
Exit;
end;
Result := True;
try
Value := StrToInt (Param);
except
WriteLn ('Error: integer expected');
Result := False;
end;
end;
{
ProcessString
Copy the passed string to the Option variable. No error checking
is performed, and a blank string is considered a valid parameter.
}
function ProcessString
(
Param : String;
var Option : ShortString
) : Boolean;
begin
Option := Param;
Result := True;
end;
{
ProcessFilename
Extract a file name from the passed command line parameter.
Currently, this function just calls ProcessString to copy the
string parameter to the Filename. It could, in the future,
check to see if the string represents a valid file name, or it
could be used to expand a short filename to a full path/file.
}
function ProcessFilename
(
Param : String;
var Filename : ShortString
) : Boolean;
begin
Result := ProcessString (Param, Filename);
end;
{
CheckParam
Check the passed Param, representing one command-line argument, against
the list of options. If the option character is valid, then process
the option based on its type (Boolean, Integer, String, or Filename).
Returns True if option processed and stored correctly, False otherwise.
}
function CheckParam
(
Param : String;
Options : pOptionsArray;
nOptions : Integer
) : Boolean;
var
Rec : pOptionRec;
Option : String;
begin
Result := False;
if (Param[1] in ['-', '/']) then begin
if (Length (Param) < 2) then begin
WriteLn ('Invalid option');
end
else begin
Rec := GetOptionRec (Options, nOptions, Param[2]);
if (Rec <> Nil) then begin
Option := Copy (Param, 3, Length (Param) - 2);
case Rec^.Option of
otBool :
Result := ProcessBool (Option, Rec.OnOff);
otInt :
Result := ProcessInt (Option, Rec^.Value);
otString :
Result := ProcessString (Option, Rec^.Param);
otFilename :
Result := ProcessFilename (Option, Rec^.Filename);
else
WriteLn ('Invalid option specification: ', Param[2]);
end;
end
else begin
WriteLn ('Invalid option character: ', Param[2]);
end;
end;
end
else begin
WriteLn ('Error: options must start with - or /');
end;
end;
{
ProcessCommandLine
Given a list of option characters and parameter types, check each
command line argument against the list and set the values in the
options structure accordingly.
Returns True if all parameters processed and stored successfully.
}
function ProcessCommandLine
(
Options : pOptionsArray;
nOptions : Integer
) : Boolean;
var
ParamNo : Integer;
begin
Result := True;
for ParamNo := 1 to ParamCount do begin
if (Not CheckParam (ParamStr (ParamNo),
Options, nOptions)) then begin
Result := False;
Exit;
end;
end;
end;
end.



You like this article ? Stay tuned and visit us often because there will be more !
read more →

Game development - Beginners guide to game creation using Scirra Construct

Table of Contents
Chapter 1, Our First Look at Construct, covers the basics of the Construct Classic editor.
Chapter 2, Hello World! Construct Style, covers the making our first game, a classic platformer.
Chapter 3, Adding the Challenge, covers creating enemies and a goal for our platform game.
Chapter 4, Making Noise, covers playing music and sound files in Construct Classic.
Chapter 5, Practical Physics, covers making our second game with the built-in physics engine.
Chapter 6, Custom Levels, covers making a level editor to save and load external level files.
Chapter 7, Platformer Revisited, a 2D Shooter, covers learning to make a platform shooter.
Chapter 8, I'm Throwing a Grenade, involves learning to use pixel shader effects in our games.
Chapter 9, Our Final Moments, covers a summary of what we've learned and some extra tips.
 
   What you need for this ? 
   With screenshots and step-by-step instructions, this beginner's guide requires only an interest in making video games, and basic experience with the Windows operating system.

   Our First Look at Construct
   In this book, we will be learning to use Construct Classic, a free open source 2D
game creator. However, before we start making games, we'll need to know how
to use the tool itself.
In this chapter, we shall:
‹‹ Download and install the latest version of Construct Classic
‹‹ Create a new game project
‹‹ Learn to navigate around the interface of Construct Classic
‹‹ Learn to work with objects
So let's get on with it.
   The first step: downloading and installing
Construct Classic
Before we start using Construct, we need to get it running. In this part of the chapter, we'll
be visiting the Scirra website to download a copy of Construct Classic, and then we'll go
through the steps for installing it. If you already have Construct Classic installed, you can
skip this step.
Time for action – getting Construct Classic up and running
Following these steps will lead to an installation of Construct Classic ready to go. To do this,
you'll need access to the Internet and the Microsoft Windows operating system on the
computer you're installing Construct on.
1. First, navigate your web browser to www.scirra.com. This is the home page of
Construct Classic and Construct 2.
2. Click on the Make Games tab, and choose the subtab Construct Classic.
3. Next, scroll down and click on Download Construct Classic R1.2. This may change to
newer versions of Construct Classic in future, but the link position will be the same.
Click on the link to start your download.
4. After downloading the installer, double-click to start the installation process.
5. Click through the installer pages until finally presented with the option to begin
installation.
6. After the installation, the Visual Studio runtime will be installed along with the latest
version of DirectX (downloaded automatically).
7. The installation should now be complete, and Construct Classic is ready to load!
   Step two: creating a game project
Now that Construct is installed, we will learn how to make a game (Direct-X) project after
we first launch it.
Creating a project is the first step in making any game in Construct, but for now, we will
create one to set us up for learning to navigate the interface.
Time for action – starting a game project
We are going to make a blank game project to allow us to navigate all areas of Construct.
1. Open up Construct and click File | New | New Direct-X game.
2. We now have a project. Click on the Application 1 node in the Project window.
3. For this chapter, we're just going to change the Creator and the Name boxes. Go
ahead and type your name into the Creator box and My Game into the Name box.
4. Now, we're going to test if the project works. Click on the Project ribbon button, and then click on the Run All button underneath it to start your game.
5. We now have the pop-up window, which looks similar to the following screenshot.
It doesn't look like much, but this is the starting point we will use to find our way
around the interface of Construct Classic. Click the x button to close the window.

   What just happened?
We've just learned how to create a blank game project file in Construct, give it a name, and
run our entire game. These steps will be used again each time we start a blank game project.
   Creating the project
While we were creating the project from the menu, you may have noticed the other two
types of projects. We won't be requiring them to make our games, but it is worth knowing a
little about them.
The first option is New Application, which creates a program that does not rely on Direct-X,
and rather uses the built-in rendering used by Windows. This project type greatly restricts
the plugins that can be used, and is not intended for creating games. As such, we will not use
this application project type in this book.
The third option, New Template/Example, is a collection of starter projects and tutorials that
can make creating games of certain genres easier. The most playable template included is the
Ghost Shooter tutorial, which includes a fully-working top-down shooter to start with. In our
case, however, we will be creating all of our games from scratch, so we can make all kinds of
games from the ground up.
   Changing the project details
Although our interaction in this step was basic, we caught a glance of all the options
available for defining the project. For now, all we needed to know was how to change the
name and the creator of the game, but later on, we'll be revisiting many of the properties
shown in that list.
   Running the project
In this final step, we learned how to start our game up. This step is fairly straightforward, but
it is worth noting that another way to click on Run All is to click the small monitor icon next
to the save icon.
   Have a go hero – try again from memory
Now that we've learned how to create blank projects, try it again to see if you can remember
how to do it.

   Step three: navigating the interface of Construct Classic
   Now that we have Construct Classic and a game project set up, we can explore all the areas
of the Construct editor that we need to learn, to make games. For now, we are going to have
a glance around the editor.
   Time for action – clicking our way around Construct Classic
Using the game project from the previous exercise, we are now going to click through and
look at various windows we'll be revisiting many times throughout the book.
1. Start a new blank game project as we learned earlier. We start the project in the
Layout editor tab. By clicking the pin button on the Properties and Project boxes,
they will minimize to the sides of the screen to provide more viewing area. It is
also possible to resize these panels by holding the cursor over the edges of the
boxes and clicking to drag their width. The following screenshot shows these
buttons with arrows.
2. Now click on the Event Sheet Editor tab to reach the view shown in the following
screenshot. Notice that the ribbon bar automatically switches to the Events tab to
provide some quick options.
3. Now that we've visited both the event editor and layout editor, we can look
at the boxes on the right side of the editor. We've already met the Properties
box on the left-hand side, so now if the right box is minimized, click on the pin button again to display it.
4. Clicking on the Animator tab will show the animation box. It will be blank, as shown
in the following screenshot, as we do not have an animated object to select yet.
5. Finally, we can take a look at the Layers tab to see the different layers of our layout.
Once again, there isn't much to see as we only have a blank game project right now.

   What just happened?
We've now learned to switch between the different views of the editor. Now, we can look
more closely at what options are available for them.
   The layout editor
This is the area that is used to create and modify the objects that make our games. Most
changes made here are directly visible when the game is run.
   The properties box
This box is used to modify the settings and values for most selectable items in Construct
Classic. We will be using it frequently to make games throughout the book.
   The event editor
In this area, we can create the rules for our games through conditions that trigger actions.
An example of a condition is when a player touches a harmful substance (such as lava), we
can make an event that checks for this condition and then triggers an action that removes
a life from the player's lives variable.
   The animator box
This box is used to create graphics and animations for our game objects the player will be
interacting with.
   The layers box
The layers box allows the organization of objects into different layers. This is useful for
creating objects that scroll at different speeds to create a parallax effect, as well as a
separate foreground and background objects. Layers can be hidden by clicking the eye icon,
and locked by clicking the lock icon, as shown in the following screenshot. They can also be
named in the Properties box.

   The final step: an introduction to objects
   To finish the chapter, we are going to look at what objects are and what some of them do.
Objects are the most important part of making a game in Construct as they usually interact
directly with the player.
Time for action – creating some objects
We are now going to place some objects in the layout and modify their properties.
1. Open your blank game project from last time, or if you feel like getting some more
practice, create a new one.
2. Right-click inside the layout editor, and click the Insert an object option. This can also be done by double-clicking on a blank space of the layout.
3. We now have the following object creation box where we can see all the types of
objects we can insert into the layout. These are pre-programmed objects created
in C++. Select the Sprite object and click on Insert. This can also be performed by
double-clicking the Sprite object. Now, we can click inside the layout to place the
sprite object.
4. We are then shown an image editor for our sprite. For now, we will make a simple
square graphic. To do this, click the paint bucket, choose a color, and then click an empty space in the graphic space.
5. Now, click the x button to return to the layout editor. Click on Yes when asked to save, and we will now have a sprite in our layout.
6. We can use the white box in the middle to change the angle of our sprite
and the boxes on the edge of the sprite to change its size. Try matching the
following shape.
7. Now, open the Properties box on the left side, and scroll down to the option Make
1:1 in the Properties group. Clicking on this will make our sprite return to normal
size again.
8. We now know how to resize and rotate the sprite object. We can also do this by
modifying the values in the Common group. Open this group and try changing the
X, Y, Width, Height, Angle, and Opacity fields to see what they change. It is worth
noting that a lower opacity value makes the sprite object more transparent, and
recently changed values will be shown in bold.
9. We can also give our sprite object a name just by changing the Name box.
This is useful, as later we will be using many different sprite objects to create
our games. For now, scroll down in the Properties box to view another group
called Appearance; toying around with the values Skew X and Skew Y produces
distortions. Notice that the selection box for the sprite does not skew with the sprite itself.
10. We can also tick the Invisible on start checkbox. This lets the graphic be shown in
the editor, but hidden when the game is run. This is good for making invisible walls
and other such objects.


   What just happened?
We have now just learned to create objects such as sprites, move them around, and
modify their appearance using the editor. Let's look at the different subtasks we went
through to do this.
   Creating an object
We learned how to bring up the object creation box and then insert a sprite into our layout.
Every object we put into a layout is available in this dialog box.
   Drawing the sprite
Although we only had a quick interaction with the graphic editor, we saw where our graphic
files are drawn and modified. If we wanted, we could even copy-and-paste graphics from
other drawing programs into the editor. It's worth noting that some painting programs may
copy images differently than Construct Classic expects. Should this happen, pasting into
Microsoft Paint first and then transferring that image to Construct will avoid these problems,
but will not keep alpha levels.
Each drawing tool that we can use in Construct Classic has a brief informative message in the
bottom-left corner of the graphic editor to explain its purpose. However, let's take a look at
some of the other controls used to draw graphics in Construct:

‹‹ The Rectangle select tool, is used to drag-and-select rectangular chunks of our graphics to move, rotate, scale, cut/delete, copy, paste, change the color of, and flip.
‹‹ The Wand tooll, is used to automatically select parts of the graphic that touch and have similar colors. Holding Shift and clicking will select all parts of the graphic with similar colors regardless of whether or not they are touching.
‹‹ The Pen Tool, lets us draw on our graphic as if we were using a pencil.
‹‹ The Brush tool, is similar to the Pen tool, except it has a much larger amount of options that can be changed using the sliders.
‹‹ The Erasor Tool, is used to erase and has the same options as the Brush Tool.
‹‹ The Mirror tool, found at the top of the window, as shown in the previous
screenshot, is used to flip an image or selection horizontally.
‹‹ The Flip tool is used to vertically flip the image or selection.
‹‹ The Rotate tool, provides a choice of angles for the image or selection to be rotated.
‹‹ The Crop tool is used to shrink the editable region of the graphic (the canvas) to fit
the graphic. Use this if you draw something smaller than the boundaries.
‹‹ The Resize Canvas tool, is used to increase or decrease the size of the canvas by showing a pop-up box that lets you input a new height and width for the canvas. The drawing itself is not resized, however.
   Changing the appearance of the sprite
We then learned how to modify our sprite using stretches, skews, and rotations. Changes we
made here are shown when we run the game.
Have a go hero – make a picture of sprites
Now that we have gone through the process to create a sprite, try adding some more to
form a picture from them. If you are stuck thinking of ideas, then try some of these:
‹‹ A house made up of separate sprites for the roof, base, windows, and door
‹‹ A magician with additional sprites for a staff and a wizard hat
‹‹ A car with sprites for the tires and a body sprite
If you wish to draw the images using another paint program that does not
support transparent backgrounds, use the RGB color (255,0,255) as your
background color. In Microsoft Paint, this color is the brightest shade of
pink in the default palette.
   Summary
This chapter taught us a lot about navigating around Construct Classic as well as creating
objects that we'll be using to make games.
Specifically, we went through the steps to install a fresh copy of Construct Classic on our
computer that we retrieved from the Scirra website. We then went on to create a new game
project and looked around the various interface views of the editor. After that, we learned
how to make, position, angle, and size Sprites, a key object in any games we make. To finish
the chapter, we took a quick look at some of the tools we will be coming across in making
our game.
We also discussed the different tools we'll be using to create images for sprites using
Construct's graphic editor.
Now that we've learned about the basics of navigating and using Construct Classic, we're
ready to move on to starting our first game!

You like this article ? Stay tuned and visit us often because there will be more !
read more →

Liquid Cristals - Materials Design and Self-Assembly

Liquid Crystals 
CONTENT:

Fluorinated Liquid Crystals: Design of Soft Nanostructures and
Increased Complexity of Self-Assembly by Perfluorinated Segments 
Carsten Tschierske

Liquid Crystalline Crown Ethers 
Martin Kaller and Sabine Laschat

Star-Shaped Mesogens – Hekates: The Most Basic Star Structure
with Three Branches
 
Matthias Lehmann

DNA-Based Soft Phases
Tommaso Bellini, Roberto Cerbino, and Giuliano Zanchetta

Polar and Apolar Columnar Phases Made of Bent-Core Mesogens 
N. Vaupoticˇ, D. Pociecha, and E. Gorecka

Spontaneous Achiral Symmetry Breaking in Liquid
Crystalline Phases 
H. Takezoe

Nanoparticles in Liquid Crystals and Liquid Crystalline
Nanoparticles
Oana Stamatoiu, Javad Mirzaei, Xiang Feng, and Torsten Hegmann

Stimuli-Responsive Photoluminescent Liquid Crystals
Shogo Yamane, Kana Tanabe, Yoshimitsu Sagara, and Takashi Kato


Fluorinated Liquid Crystals: Design of SoftNanostructures and Increased Complexity of Self-Assembly by Perfluorinated Segments
Carsten Tschierske

    Abstract The effects of perfluorinated and semiperfluorinated hydrocarbon units
on the self-assembly of rod-like, disc-like, polycatenar, taper- and star-shaped,
dendritic, and bent-core liquid crystalline (LC) materials is reviewed. The influence
of fluorinated segments is analyzed on the basis of their contributions to
the cohesive energy density, molecular shape, conformational flexibility, microsegregation,
space filling, and interface curvature. Though the focus is on recent
progress in the last decade, previous main contributions, general aspects of
perfluorinated organic molecules, and the basics of LC self-assembly are also briefly
discussed to provide a complete overall picture. The main focus is on structureproperty-
relations and the use ofmicro-segregation to tailor mesophasemorphologies.
Especially polyphilic molecules with perfluorinated segments provide new modes
of LC self-assembly, leading to ordered fluids with periodic multi-compartment
structures and enhanced complexity compared to previously known systems.
Keywords Columnar mesophase Cubic mesophase Dendrimer Liquid crystal
Metallomesogen Micro-segregation Organic semiconductor Perfluorinated
molecule Polyphilic molecule Self-assembly

Abbreviations
1D/2D/3D One- two-, three-dimensional
ahex Hexagonal lattice parameter
CED Cohesive energy density
Col Columnar phase
Colhex Hexagonal columnar phase
Colob Oblique columnar phase
Colortho Orthorhombic “columnar” phase
Colrec Rectangular columnar Phase
Colsqu Square columnar phase
Cr Crystalline solid
CubI Spheroidic (micellar) cubic phase
CubV Bicontinuous cubic phase
d Layer periodicity
E Crystalline E phase
G Glassy state
HT High temperature phase
Iso Isotropic liquid
Isore Re-entrant isotropic phase
l Molecular length
LamN Laminated nematic phase
LamSm/cor Correlated laminated smectic phase
LamSm/dis Non-correlated laminated smectic phase
LC Liquid crystal/Liquid crystalline
LT Low temperature phase
M Unknown mesophase
N/N* Nematic phase/Chiral nematic Phase
RF Perfluoroalkyl chain
RH Alkyl chain
RSi Carbosilane chain
SmA Smectic A phase (nontilted smectic phase)
SmAd/SmCd Double layer SmA/SmC phase
SmB Smectic B phase
SmC Smectic C phase (synclinic tilted smectic C phase)
SmC* Chiral (synclinic tilted) smectic C phase
SmCA* Chiral anticlinic tilted (antiferroelectric switching) SmC phase
SmCPA Antiferroelectric switching polar smectic C phase
SmCPF Ferroelectric switching polar smectic C phase
SmCa* Chiral smectic C alpha phase
SmIA* Chiral antiferroelectric switching smectic I phase
SmX Smectic phase with unknown structure
UCST Upper critical solution temperature
XRD X-ray diffraction

1 Introduction
1.1 Liquid Crystal Self-Assembly

Liquid crystals (LC) represent truly fascinating materials in terms of their
properties, their importance for the fundamental understanding of molecular selfassembly,
and their tremendous success in commercial applications [1, 2]. Liquid
crystals can be considered as a state of matter which in a unique way combines
order and mobility. The constituent molecules of LC phases are sufficiently
Fig. 1 Organization of rod-like molecules (top) and disc-like molecules (bottom) in LC phases
(for clarity the alkyl chains are not shown in the models of the phase structures). Abbreviations: Iso
isotropic liquid state; N nematic LC phase; SmA smectic A phase, SmC smectic C phase (tilted),
Col columnar phase

disordered to generate softness and even flow properties, yet comprising varying
degrees of ordering depending on the actual type of liquid crystal phase (Fig. 1).
Hence, depending on the rheological properties, liquid crystals can be considered as
anisotropic soft matter or anisotropic fluids with interesting application properties.
Liquid crystalline phases usually occur in a distinct temperature range between the
crystalline solid state (Cr) and the isotropic liquid state (Iso). Therefore, such
phases are also called mesophases, and the compounds that exhibit such behavior
are called mesogens or liquid crystals.
The nematic phase (N) is the least ordered, and hence the most fluid liquid
crystal phase. The order in this type of LC phases is based on a rigid and
anisometric (in most cases rod-shaped or disc-shaped) molecular architecture.
Such molecules tend to minimize the excluded volume between them, and this
leads to long range orientational order. For rod-like molecules the ratio between
molecular length and its broadness determines the stability of the nematic phase
with respect to the isotropic liquid state and the stability rises with increase of this
ratio. In most cases the rigid cores are combined with flexible chains, typically alkyl
chains, which hinder crystallization and in this way retain fluidity despite of the
onset of order.
The combination of rigid and flexible segments in one molecule can lead to
amphiphilicity if these chains are sufficiently long. This gives rise to nano-scale
segregation of the rigid cores and flexible chains which is an important route
to positional long range order, providing layer-like LC structures for rod-like
molecules and columnar aggregates for disc-like molecules; see Fig. 1 [3, 4, 9, 10].
Layer structures (smectic phases, Sm) have a periodicity in only one direction
(the distance d between the layers) and these phases can be further classified
according to the order in the layers. If there is no order or rod-like anisometric
units which adopt an orientation with the director n on average perpendicular to the
layer planes, then the phase is assigned as SmA (Fig. 1). If anisometric units adopt
a uniformly tilted configuration, the phase is assigned as SmC. With increasing
order in the layers additional types of higher ordered smectic phases can arise (e.g.,
SmB, E, G. . .) [11]. Columnar aggregates assemble on a periodic 2D lattice,
leading to columnar phases (Col) [12, 13].
Amphiphilicity is a very general driving force for molecular self-assembly
and, besides the rigid-flexible amphiphiles [14] mentioned above, any other type
of incompatibility can generate long range positional order. The most important are
the polar/apolar incompatibility, leading to polar amphiphilic LC [15–18], and the
incompatibility between hydrocarbons and fluorocarbons (“apolar” amphiphiles),
but the combination of segments with a distinct shape, for example rod-like and
disc-like can also lead to an amphiphilic structure (shape amphiphiles [19, 20]).
Due to the very different kinds of amphiphilicity occurring in LC systems, which
are often combined, it is difficult to describe them theoretically and to make precise
quantitative predictions such as, for example, developed for lyotropic systems [21,
22] and block copolymers [23].
The concept of micro-segregation, (nano-segregation is used synonymously)
developed for these thermotropic LC systems, is based on the approximation that
micro-segregation of the two incompatible components of a binary amphiphile into
two distinct nano-spaces can be related to the ability of macroscopic segregation
(demixing) of two immiscible liquids with molecular structures similar to the two
segments forming the amphiphile [6, 9, 10, 24, 25]. The Gibbs free energy of
mixing of two liquids (DGmix) must be positive (endergonic) for demixing. The free
energy term can be split into an enthalpic and an entropic contribution according to
DGmix ¼ DHmix–TDSmix. The mixing enthalpy (DHmix) is related to the difference
in cohesive energy density (CED, c) of the two components (A, B), i.e., DHmix ~
(cA-cB). The CED can be calculated from the vaporization enthalpy (DHV) and the
molar volume (Vm) according to c ¼ (DHV RT)/Vm or, alternatively, from the
surface tension (g) and the molar volume by c ¼ g/Vm
1/3. The Hildebrand solubility
parameter (d) [26] is the square root of the cohesive energy density d ¼ c1/2 and
hence these parameters, which are tabulated [27, 28], can be used to estimate
whether two molecules would mix or not. If these two molecules are interconnected
in an amphiphile the degree of incompatibility of the two segments decides whether
nano-scale segregation could takes place. The larger the difference dA dB the
larger the incompatibility and the higher the mesophase stability.1 Segregation
works against the entropy of mixing and hence segregation is favored for larger
molecules because there are less molecules per volume unit and therefore in this
case the influence of the mixing entropy to the entropy term (–TDSmix) is smaller
than for small molecules. As DSmix is positive and coupled with temperature (–T) it
becomes more important at higher temperature. This reduces DGmix and, as soon as
it approaches zero and becomes negative, segregation is lost at the order–disorder
transition temperature, also assigned as clearing temperature in LCs. It should be
pointed out that the mesophase stability is independent from the total value of the
cohesive energy density of the components; this only influences the transition from
the liquid to the gaseous state, i.e., the complete isolation of the molecules (vaporization).
Segregation is the reverse of mixing which is the separation of molecules
by other molecules and this is driven by the difference in cohesive energy density
between the two types of molecules (macroscopic demixing) or the distinct
segments forming an amphiphilic mesogens (micro-segregation). Therefore, the
stability of a positional ordered mesophase increases with growing difference
of solubility parameters (Dd) of the two components which is equivalent to the
difference in CED (Dc). Because it is the difference between the CEDs of the
distinct segments of an amphiphilic mesogens which determines the mesophase
stability and not their absolute values, an increase of mesophase stability can also
be achieved by reducing the CED of one of the incompatible segments of an
amphiphile. This is important for understanding mesophase stabilization by the
fluorophobic effect, as the CED of fluorinated alkyl chain is usually the lowest of all
possible LC building blocks (see Sect. 1.3). Despite the total CED being reduced
(i.e., the attractive forces between the molecules are reduced!) by perfluorination
of the alkyl chains of the mesogens, the difference of the cohesive energy densities
between the segments is increased. Therefore, fluorination usually leads to
mesophase stabilization, as shown in Table 1 for a representative example. Though
these considerations are simplified, they provide a fundamental understanding
of the structure-property relations in nano-segregated LC systems and allow
a comparison of related molecules and the effect of structural variations on the
mesophase stability.
Segregation of the incompatible molecular segments takes place with formation
of distinct nano-compartments organized on a one-dimensional (1D), twodimensional
(2D), or three-dimensional (3D) periodic lattice, separated by interfaces.
These interfaces tend to be minimal in order to reduce the interfacial energy
stored in the system. For amphiphilic molecules without anisometric segments
(flexible amphiphiles) the mesophase type is mainly determined by the relative
volume of the two incompatible segments, as shown in Fig. 2.
Lamellar phases (¼ smectic phases, Sm), composed of stacks of alternating
layers, have flat interfaces between the micro-segregated regions (layers) and these
structures are formed by molecules for which the incompatible segments have
comparable sizes and hence require comparable cross section areas at the interfaces.
If the size of one segment is increased the layers become unstable and a
curvature of the interfaces arises. In this case the layers are replaced by columns,
followed by spheroidic aggregates with increasing interface curvature (Fig. 2) [21].
Self-assembly of circular columns takes place on a hexagonal lattice, leading to
hexagonal columnar phases (Colhex) providing minimized interfaces compared to
non-circular columns forming square (Colsqu), rectangular (Colrec), or oblique
(Colob) 2D lattices [29]. Formation of these non-hexagonal columnar phases
requires additional contribution from the molecular shape.
Self assembly of spheroidic aggregates leads in most cases to micellar cubic
phases (CubI) [30–35], where closed spheroidic aggregates are organized on a cubic
3D lattice (Fig. 2d,e).
There is a second kind of cubic phases, assigned as bicontinuous cubic phases
(abbreviated as CubV) which can occur at the transition between lamellar and
columnar organization [35, 36]. In these cubic phases the layers develop saddle
splay curvature (see Fig. 2) and adopt the shape of infinite minimal surfaces. Alternatively,
these bicontinuous cubic phases could be considered as resulting from
a branching of columns; these branched columns are interconnected at distinct
nodes to give rise to two interwoven continuous networks (Fig. 2b) [32, 37, 38].
Both descriptions can be regarded as equivalent, one considering the regions of the
alkyl chains and the other the segregated mesogenic cores. Depending on the shape
of the infinite minimal surfaces and on the number of columns interconnected at
each branching point, respectively, quite distinct structures could result which
are again classified according to space group symmetry [29].2 Although there is
3D-long range order in density fluctuations, cubic and other 3D mesophases are still
regarded as liquid crystalline as long as there is no preferred position for individual
molecules, i.e., as long as there is a diffuse wide-angle X-ray scattering.
Whereas formation of nematic phases usually requires a specific rod-like or disclike
molecular shape, this is not the case for mesophases based on nano-segregation
[9, 10]. Any amphiphilic molecule can adopt the mesophase morphologies shown in
Fig. 2a–e, depending on the size ratio of the incompatible units. However, a specific
molecular shape can lead to a preference for a distinct type of self assembly.
Generally, rod-like molecules prefer to be organized in layers as they tend to
avoid the splay occurring in curved aggregates. Disc-like molecules provide curvature
in their molecular structure and therefore preferably form columnar LC phases.
Taper-shaped or cone-like molecules tend to form columnar and micellar cubic
phases with strong interface curvature [31, 35, 39]. However, it is not always the
case that self-assembly of anisometric units and amphiphilic self-assembly enhance
each other. These two modes of self assembly can also be in competition and this
can modify the mesophase morphology. For example, disc-like molecules can,
under certain conditions, organize in layers (lamello-columnar phases) and rodlike
molecules can form ribbons organized on a 2D lattice (assigned as modulated
smectic phases or ribbon phases). Similarly, taper shaped molecules can arrange
antiparallel and form layers (Fig. 2). If this competition provides significantly
strong frustration, it can either lead to disorder (occurrence of isotropic or nematic
phases) [40, 41] or, alternatively, to completely new LC structures [8]. Hence,
competition is a way to new LC phases. Another alternative way to increased
mesophase complexity consists in the combination of more than two incompatible
units, leading to polyphilic LC (see Sect. 7) [8, 10, 42].
Depending on temperature, transitions between distinct types of LC phases can
occur.3 All transitions between various liquid crystal phases with 0D, 1D, or 2D
periodicity (nematic, smectic, and columnar phases) and between these liquid
crystal phases and the isotropic liquid state are reversible with nearly no hysteresis.
However, due to the kinetic nature of crystallization, strong hysteresis can occur for
the transition to solid crystalline phases (overcooling), which allows liquid crystal
phases to be observed below the melting point, and these phases are termed
monotropic (monotropic phases are shown in parenthesis). Some overcooling
could also be found for mesophases with 3D order, namely cubic phases. The
order–disorder transition from the liquid crystalline phases to the isotropic liquid
state (assigned as clearing temperature) is used as a measure of the stability of the
LC phase considered.
Besides molecular shapes and amphiphilicity, chirality also has a large influence
on LC self assembly, leading to series of LC phases with helical superstructures,
reduced symmetry, and chirality induced frustration [43–46].
Also mesogens with more complex shapes, such as, for example, those with
bent aromatic cores (bent-core mesogens [47]), star mesogens [48], or cone-like
molecules are of contemporary interest, together with LC states formed by
biomolecules [49–51], polymers, dendrimers, or network structures (gels,
elastomers) [52–54]. The huge number of possible molecular and supramolecular
structures and the complex relations between molecular shape, nano-scale segregation,
and symmetry of molecular packing leads to a large number of self assembled
LC structures, which is continuously growing.
Due to inherent fluidity these self-organized LC structures have the ability to
change their configuration under the influence of external stimuli (surfaces, electric,
magnetic, and mechanical fields) and to eliminate defects by self-healing. Therefore,
this special state of matter is not only of interest for displays, adaptive optics,
information storage, and nano-patterning – it provides a very general way to
assemble functional molecules/materials into well defined superstructures. This
can be used in technology, and it is an important concept of molecular self assembly
in biosystems [55].

You like this article ? Stay tuned and visit us often because there will be more ! 


read more →

Tutorial on pointers and arrays in C/C++

A TUTORIAL ON POINTERS AND ARRAYS IN C
 
TABLE OF CONTENTS
INTRODUCTION
CHAPTER 1: What is a pointer? 
CHAPTER 2: Pointer types and Arrays 
CHAPTER 3: Pointers and Strings 
CHAPTER 4: More on Strings 
CHAPTER 5: Pointers and Structures 
CHAPTER 6: Some more on Strings, and Arrays of Strings 
CHAPTER 7: More on Multi-Dimensional Arrays 
CHAPTER 8: Pointers to Arrays 
CHAPTER 9: Pointers and Dynamic Allocation of Memory 
CHAPTER 10: Pointers to Functions 


INTRODUCTION
If you want to be proficient in the writing of code in the C programming language, you
must have a thorough working knowledge of how to use pointers. Unfortunately, C
pointers appear to represent a stumbling block to newcomers, particularly those coming
from other computer languages such as Fortran, Pascal or Basic.
To aid those newcomers in the understanding of pointers I have written the following
material. To get the maximum benefit from this material, I feel it is important that the
user be able to run the code in the various listings contained in the article. I have
attempted, therefore, to keep all code ANSI compliant so that it will work with any ANSI
compliant compiler. I have also tried to carefully block the code within the text. That
way, with the help of an ASCII text editor, you can copy a given block of code to a new
file and compile it on your system. I recommend that readers do this as it will help in
understanding the material.


CHAPTER 1: What is a pointer?
One of those things beginners in C find difficult is the concept of pointers. The purpose
of this tutorial is to provide an introduction to pointers and their use to these beginners.
I have found that often the main reason beginners have a problem with pointers is that
they have a weak or minimal feeling for variables, (as they are used in C). Thus we start
with a discussion of C variables in general.
A variable in a program is something with a name, the value of which can vary. The way
the compiler and linker handles this is that it assigns a specific block of memory within
the computer to hold the value of that variable. The size of that block depends on the
range over which the variable is allowed to vary. For example, on PC's the size of an
integer variable is 2 bytes, and that of a long integer is 4 bytes. In C the size of a variable
type such as an integer need not be the same on all types of machines.
When we declare a variable we inform the compiler of two things, the name of the
variable and the type of the variable. For example, we declare a variable of type integer
with the name k by writing:
int k;
On seeing the "int" part of this statement the compiler sets aside 2 bytes of memory (on a
PC) to hold the value of the integer. It also sets up a symbol table. In that table it adds the
symbol k and the relative address in memory where those 2 bytes were set aside.
Thus, later if we write:
k = 2;
we expect that, at run time when this statement is executed, the value 2 will be placed in
that memory location reserved for the storage of the value of k. In C we refer to a
variable such as the integer k as an "object".
In a sense there are two "values" associated with the object k. One is the value of the
integer stored there (2 in the above example) and the other the "value" of the memory
location, i.e., the address of k. Some texts refer to these two values with the nomenclature
rvalue (right value, pronounced "are value") and lvalue (left value, pronounced "el
value") respectively.
In some languages, the lvalue is the value permitted on the left side of the assignment
operator '=' (i.e. the address where the result of evaluation of the right side ends up). The
rvalue is that which is on the right side of the assignment statement, the 2 above. Rvalues
cannot be used on the left side of the assignment statement. Thus: 2 = k; is illegal.
Actually, the above definition of "lvalue" is somewhat modified for C. According to
K&R II (page 197): [1]
"An object is a named region of storage; an lvalue is an expression
referring to an object."
However, at this point, the definition originally cited above is sufficient. As we become
more familiar with pointers we will go into more detail on this.
Okay, now consider:
int j, k;
k = 2;
j = 7; <-- line 1
k = j; <-- line 2
In the above, the compiler interprets the j in line 1 as the address of the variable j (its
lvalue) and creates code to copy the value 7 to that address. In line 2, however, the j is
interpreted as its rvalue (since it is on the right hand side of the assignment operator '=').
That is, here the j refers to the value stored at the memory location set aside for j, in this
case 7. So, the 7 is copied to the address designated by the lvalue of k.
In all of these examples, we are using 2 byte integers so all copying of rvalues from one
storage location to the other is done by copying 2 bytes. Had we been using long integers,
we would be copying 4 bytes.
Now, let's say that we have a reason for wanting a variable designed to hold an lvalue (an
address). The size required to hold such a value depends on the system. On older desk top
computers with 64K of memory total, the address of any point in memory can be
contained in 2 bytes. Computers with more memory would require more bytes to hold an
address. Some computers, such as the IBM PC might require special handling to hold a
segment and offset under certain circumstances. The actual size required is not too
important so long as we have a way of informing the compiler that what we want to store
is an address.
Such a variable is called a pointer variable (for reasons which hopefully will become
clearer a little later). In C when we define a pointer variable we do so by preceding its
name with an asterisk. In C we also give our pointer a type which, in this case, refers to
the type of data stored at the address we will be storing in our pointer. For example,
consider the variable declaration:
int *ptr;

ptr is the name of our variable (just as k was the name of our integer variable). The '*'
informs the compiler that we want a pointer variable, i.e. to set aside however many bytes
is required to store an address in memory. The int says that we intend to use our pointer
variable to store the address of an integer. Such a pointer is said to "point to" an integer.
However, note that when we wrote int k; we did not give k a value. If this definition is
made outside of any function ANSI compliant compilers will initialize it to zero.
Similarly, ptr has no value, that is we haven't stored an address in it in the above
declaration. In this case, again if the declaration is outside of any function, it is initialized
to a value guaranteed in such a way that it is guaranteed to not point to any C object or
function. A pointer initialized in this manner is called a "null" pointer.
The actual bit pattern used for a null pointer may or may not evaluate to zero since it
depends on the specific system on which the code is developed. To make the source code
compatible between various compilers on various systems, a macro is used to represent a
null pointer. That macro goes under the name NULL. Thus, setting the value of a pointer
using the NULL macro, as with an assignment statement such as ptr = NULL, guarantees
that the pointer has become a null pointer. Similarly, just as one can test for an integer
value of zero, as in if(k == 0), we can test for a null pointer using if (ptr == NULL).
But, back to using our new variable ptr. Suppose now that we want to store in ptr the
address of our integer variable k. To do this we use the unary & operator and write:
ptr = &k;
What the & operator does is retrieve the lvalue (address) of k, even though k is on the
right hand side of the assignment operator '=', and copies that to the contents of our
pointer ptr. Now, ptr is said to "point to" k. Bear with us now, there is only one more
operator we need to discuss.
The "dereferencing operator" is the asterisk and it is used as follows:
*ptr = 7;
will copy 7 to the address pointed to by ptr. Thus if ptr "points to" (contains the address
of) k, the above statement will set the value of k to 7. That is, when we use the '*' this
way we are referring to the value of that which ptr is pointing to, not the value of the
pointer itself.
Similarly, we could write:
printf("%d\n",*ptr);
to print to the screen the integer value stored at the address pointed to by ptr;.
One way to see how all this stuff fits together would be to run the following program and
then review the code and the output carefully.

------------ Program 1.1 ---------------------------------
/* Program 1.1 from PTRTUT10.TXT 6/10/97 */

#include <stdio.h>
int j, k;
int *ptr;
int main(void)
{
j = 1;
k = 2;
ptr = &k;
printf("\n");
printf("j has the value %d and is stored at %p\n", j, (void *)&j);
printf("k has the value %d and is stored at %p\n", k, (void *)&k);
printf("ptr has the value %p and is stored at %p\n", ptr, (void
*)&ptr);
printf("The value of the integer pointed to by ptr is %d\n", *ptr);
return 0;
}
Note: We have yet to discuss those aspects of C which require the use of the (void *)
expression used here. For now, include it in your test code. We'll explain the reason
behind this expression later.
To review:
· A variable is declared by giving it a type and a name (e.g. int k;)
· A pointer variable is declared by giving it a type and a name (e.g. int *ptr) where
the asterisk tells the compiler that the variable named ptr is a pointer variable and
the type tells the compiler what type the pointer is to point to (integer in this
case).
· Once a variable is declared, we can get its address by preceding its name with the
unary & operator, as in &k.
· We can "dereference" a pointer, i.e. refer to the value of that which it points to, by
using the unary '*' operator as in *ptr.
· An "lvalue" of a variable is the value of its address, i.e. where it is stored in
memory. The "rvalue" of a variable is the value stored in that variable (at that
address).


You like this article ? Stay tuned and visit us often because there will be more !
read more →

11 Steps to create a successful website

Step 1: Plan Your Web Presence
Defining your Customers and Mission
Choosing and Buying your Domain Name
Text, Images and other Graphic Elements
Budgets, and Who Does What
Step 2: Choose DIY or Go with a Pro
DIY Web Site Packages
Choosing a Web Design Professional
SEO and Red Flags
Step 3: Select the Tools for Making Your HomeWeb
Web Hosting
FTP: File Transfer Protocol
Merchant Accounts
Managing your Web Images
Step 4: Make Key Design Decisions
General Design Principles
Getting Around on Your Web Site
‘Seniors’ and Special Needs
Step 5: Learn the Code
What is Hypertext Markup Language?
How Does It Work?
Understanding HTML Tools
Step 6: Identify the Best Software for Words & Images
WYSIWYG vs. HTML Software
Best Values
Some Tips on ‘Deals’ to Avoid
Top-of-the-Line Design Software
For More Information
Step 7: Take Control Over the Look, Feel and Function
Storefront Software Packages
Shopping Cart 101
Amazon.com: The Gold Standard
When to Hire a Pro
Step 8: Optimize Your Site for Search Engines
What is SEO?
Some Cautions
How SEO Works
How Search Engines Rank Web Sites
SEO Best Practices
Who and What to Avoid
SEO Maintenance
Step 9: Put All the Parts Together
Testing Your Site
Staff and Customer Site Reviews
Testing on Different Platforms and Browsers
Tracking Bugs, Confirming Fixes and Testing Links (Again)
Resources
Step 10: Take your Web site Live!
Register with Search Engines
Buy Ads for Better Placement
Sign Up with "What’s New" Directories
Launch a PR Campaign
Try Pay-Per-Click
Start a Blog
Step 11: Constantly Tend to Your Web Site
Keep Things Secure
Manage Existing Content
Tend Your Analytics and SEO
Add New Content and Links
Constantly Promote Your Web Site
Reconsider Ads
Last Words
About StartupNation
Additional Podcasts Shows
Links to Additional Small Business Advice

Step 1: Plan Your Web Presence


Now that you’ve made the decision to put a shiny new business Web site among the tens of millions of others on the internet, you’re no doubt in a hurry to see the face of your company looking back from the screen – slick, professional, inviting, with eye-catching graphics and exciting text that just begs new customers to check you out.
But right now it’s important to take a breath, clear your mind and plan, plan, plan. A well thought-out blueprint will guide all the other decisions you’ll make in the next ten steps.
In this step we’ll cover:
Defining your Customers and Mission
Choosing and Buying your Domain Name
Text, Images and other Graphic Elements
Budgets, and Who Does What

It can also help you avoid spending more than you need. Skimp on planning, and you’ll have problems down the road.
Now let’s get going.
Defining your Customers and Mission
You may think this goes against common sense, but the essence of your Web site isn’t really about you. What? It’s true. Sure, it presents your business face to the world and you’ll carefully make choices later on to put that together.
But your Web site is a specialized tool, one that enables you to reach countless new customers and, if it’s a retail site, sell to them and process their purchases.
Here, your primary purpose is to know your customers so well that you answer any questions they might have before they ask, then make it easy for them to buy what you’re selling. This bedrock principle applies whether you’re creating a one- or two-page site that simply tells who you are and where you can be reached by e-mail, snail mail and phone; or a fully functioning retail site with hundreds, even thousands, of pages and a “shopping cart” that let’s your buyers collect products and pay for them, comfortable that their financial and other personal data are secure.
Exactly who are they and what do you know about them, what they want, what they need, what they don’t know they need, what gives them the willies on the Web?
•How old are they? Are they men, women, kids?
•What do they expect when they come to a company like yours?
•How smart are they and what specific talents or skills do they have?
•Where do they live? What are those places like?
•Are they Web savvy or are they just beginning to use it? In either case, what are their concerns about doing business on the Web – what scares them off?

Answer those questions, and any others that suit the specific customer you’ve now identified, and you’ll know how to go forward in writing your raison d’être, your reason for being – your mission.
You’ll tell them why you’re qualified to do what you do, and why your company is unique and better than the competition. You’ll tell them exactly how you’ll serve their needs right here, right now, on your Web site. You’ll sell your company as one that knows they, too are unique, and that you’ve tailored your goods, services and shopping experience to these special people.
Now, draw a simple diagram of your Web site, starting with the home page and proceeding – as your customer would – from page to page to page. Keep it simple – more detail comes later.

Choosing and Buying your Domain Name
To be the master of your domain, your first have to give it a name.
Tip
Choosing a great domain name takes careful consideration
Internet marketing pro Ralph Wilson suggests brainstorming sessions with friends as a way to come up with creative options for your unique domain name. You’ll want plenty of choices on the chance that your first, second, third, even fourth picks have already been registered by someone else.
Wilson also recommends the following when selecting a domain name:
1.Keep it short.
2.Put two words together (combinations of short words often work well).
3.Make it easy to say and spell.
4.Use the .com or .net extensions.
5.Think about relevant keywords and incorporate them into the domain name.

This is simple – if your company name is Passionate Pigfeet, you’d likely choose passionatepigfeet.com. But there could be a snag.
However unlikely, someone might already own the domain name www.passionatepigfeet.com. It doesn’t necessarily mean there’s a Web site by that name; some people buy up endless variations on domain names hoping to cash in later when somebody wants to use one of them.
But your domain provider’s Web site will have a simple method to check almost instantly. Web hosts – those with the computing power to “host” your site and all its inner working on the Web – commonly offer domain names as part of their basic package.
To find one that meets your needs and budget, search online for “domain hosts.” Or start with one of these:
•Microsoft Office Live Small Business
•HostingReview.com
•NetworkSolutions.com
•GoDaddy.com
•5Hosts.com
•TopHosts.com
•HostingChecker.com

Text, Images and other Graphic Elements
You might as well get going now on writing copy – the text – for your Web site, and how you intend to use images.
If your writing skills are sharp, follow your diagram of Web pages and decide what you want to say on each. This is a rough draft, so don’t sweat over it too long.
Writing effective Web copy is a special skill, and you need to edit and rewrite your draft along some specific guidelines. The broader ones:
•Don’t make your Web site look or read like an ad. You may be planning to attract and sell online space to advertisers, and you’ll confuse visitors dismissed if your content looks like ad material.
•Keep your copy concise and use bullets
•If you refer to your company as “we” in your copy, be sure to address your customer as “you.” Engage them in this personal experience.
•Keep it simple and kill jargon. The point here isn’t to show your mastery of insiders’ language, but to make your customers feel welcome, at home and included.
•Write like you’re talking face-to-face, using contractions if it sounds natural.
•Be succinct. Don’t write: “If you happen to encounter anything that raises questions, we are prepared to address them.” Do write: “Questions? We’re here to answer them.”
As a start, look to these resources for more detailed guidance:
•Power Words and Phrases
•UseIt.com
•e-Gineer.com
•WebDesign.com
•About.com

You’re not done until you spell-check your copy, then print it out and proofread, proofread again, and do it a few more times. Bad grammar, misspellings – especially proper names – and other basic errors will make you look like an amateur, not the world-beating pro you really are.
Invite others to read over your text and point out errors, or hire a freelance copy editor. You’ll find them all over the Web, but check their references. It won’t cost much and will be money well spent.
If you don’t think you can handle the copywriting yourself, you’re probably right. Hire a professional with Web experience. There are thousands of freelance writers online offering to do the job at a wide range of prices.
Graphics Content: Your only task now is to decide what photos, charts and graphs, illustrations and other visuals you need to help tell your message and show who you are.
Note what they are on each of your Web page diagrams, but not necessarily where they’ll go. We’ll get to that later. And keep these rules in mind:
•Use only as many images or other graphics as you need to bolster your text and make your pages attractive. Here, as in nearly anything on the Web, less is more. Don’t visually assault your visitors.
•Good pictures can speak a thousand words. If a photo or other image will save a lot of explaining, use it instead of text.
•If your purpose is just to put candid snapshots on the Web, your visitors will understand why they’re not slick, crisp and professionally done. For everything else, be sure your photos and graphics are all three.

Budgets, and Who Does What
Setting smart budgets saves money – period. Get your planning done now, and you won’t waste precious cash on things you don’t and won’t need. Set your Web site budget so you can comfortably handle the costs with available resources.
One of the great things about Web sites is their changeability. You can add bells, whistles, services and other enhancements later, as you need them and have more cash to spend.
It’s impossible to tell you exactly how to divide the pot in building a Web site. There are many factors in endless combinations, and countless ways to handle them. But think about these things and you’ll be in great shape to work out the details:
•How many products or services are you selling?
•If you’re a retail operation, how will you securely process orders?
•Do you need professionals for writing, editing, photography, Web design, even budgeting?
•How many marketing functions do you want? Newsletters? Surveys? Blogs?
•How much can you spend on hosting, your domain name, your Web design package?
•Does a free, all-in-one Web site service like Microsoft Office Live Small Business cover you, or do you need more flexibility, an e-tail “shopping cart,” an original look, detailed analytics?
•How will you drive traffic to your Web site after it’s built?

When it comes time to shop for these things, let your budget dictate your choices. As revenue starts coming in the door, your business Web site can grow, too, in scope, sophistication and ambition.

You like this article ? Stay tuned and visit us often because there will be more !

read more →