Collections are a more powerful form of arrays. In this lesson, we demonstrate an "old style" collection (pointing out its limitations), along with several of the newer, strongly typed generic collections (List<T> and Dictionary<T1, T2>) utilizing the generics syntax.
Before
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkingWithCollections
{
class Program
{
static void Main(string[] args)
{
Car car1 = new Car();
car1.Make = "Oldsmobile";
car1.Model = "Cutlas Supreme";
Car car2 = new Car();
car2.Make = "Geo";
car2.Model = "Prism";
Book b1 = new Book();
b1.Author = "Robert Tabor";
b1.Author = "Microsoft .NET XML Web Services";
b1.ISBN = "0-000-00000-0";
Console.ReadLine();
}
}
class Car
{
public string Make { get; set; }
public string Model { get; set; }
}
class Book
{
public string Title { get; set; }
public string Author { get; set; }
public string ISBN { get; set; }
}
}
After
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkingWithCollections
{
class Program
{
static void Main(string[] args)
{
/*
Car car1 = new Car();
car1.Make = "Oldsmobile";
car1.Model = "Cutlas Supreme";
Car car2 = new Car();
car2.Make = "Geo";
car2.Model = "Prism";
Book b1 = new Book();
b1.Author = "Robert Tabor";
b1.Author = "Microsoft .NET XML Web Services";
b1.ISBN = "0-000-00000-0";
*/
// ArrayLists are dynamically sized, and support other
// cool features like sorting, removing items, etc.
/*
System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
myArrayList.Add(car1);
myArrayList.Add(car2);
myArrayList.Add(b1);
myArrayList.Remove(b1);
foreach (object o in myArrayList)
{
Console.WriteLine(((Car)o).Make);
}
*/
// Dictionaries allow you to save a key along with
// the value, and also support cool features.
// There are different dictionaries to choose from ...
/*
System.Collections.Specialized.ListDictionary myDictionary
= new System.Collections.Specialized.ListDictionary();
myDictionary.Add(car1.Make, car1);
myDictionary.Add(car2.Make, car2);
myDictionary.Add(b1.Author, b1);
// Easy access to an element using its key
Console.WriteLine(((Car)myDictionary["Geo"]).Model);
// But since its not strongly typed, we can easily break it
// by adding a different type to the dictionary ...
// Obviously, I'm trying to retrieve a book here, and then get its ... model?
Console.WriteLine(((Car)myDictionary["Robert Tabor"]).Model);
*/
/*
List<Car> myList = new List<Car>();
myList.Add(car1);
myList.Add(car2);
//myList.Add(b1);
foreach (Car car in myList)
{
// No casting!
Console.WriteLine(car.Model);
}
*/
/*
Dictionary<string, Car> myDictionary = new Dictionary<string, Car>();
myDictionary.Add(car1.Make, car1);
myDictionary.Add(car2.Make, car2);
Console.WriteLine(myDictionary["Geo"].Model);
*/
//string[] names = { "Bob", "Steve", "Brian", "Chuck" };
Car car1 = new Car() { Make = "Oldsmobile", Model = "Cutlas Supreme" };
Car car2 = new Car() { Make = "Geo", Model = "Prism" };
Car car3 = new Car() { Make = "Nissan", Model = "Altima" };
List<Car> myList = new List<Car>() {
new Car { Make = "Oldsmobile", Model = "Cutlas Supreme"},
new Car { Make = "Geo", Model="Prism"},
new Car { Make = "Nissan", Model = "Altima"}
};
Console.ReadLine();
}
}
class Car
{
public string Make { get; set; }
public string Model { get; set; }
}
class Book
{
public string Title { get; set; }
public string Author { get; set; }
public string ISBN { get; set; }
}
}
Source : MS Virtual Academy
22 December 2011
21 December 2011
C# Lesson 21 : Gracefully Handling Exceptions
Exceptions occur when an application experiences some unexpected problem at run time. This lesson discusses how to use the try catch finally block to anticipate potential problems and to attempt to shield the end user from those problems as much as possible. We also explore best practices when checking for exceptions.
Before
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReadTextFileWhile
{
class Program
{
static void Main(string[] args)
{
StreamReader myReader = new StreamReader("Values.txt");
string line = "";
while (line != null)
{
line = myReader.ReadLine();
if (line != null)
Console.WriteLine(line);
}
myReader.Close();
Console.ReadLine();
}
}
}
After
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReadTextFileWhile
{
class Program
{
static void Main(string[] args)
{
try
{
StreamReader myReader = new StreamReader("Values.txt");
string line = "";
while (line != null)
{
line = myReader.ReadLine();
if (line != null)
Console.WriteLine(line);
}
myReader.Close();
}
catch (DirectoryNotFoundException e)
{
Console.WriteLine("Couldn't fine the file. Are you sure the DIRECTORY exists?");
}
catch (FileNotFoundException e)
{
Console.WriteLine("Couldn't find the file. Are you sure you're looking for the correct file?");
}
catch (Exception e)
{
Console.WriteLine("Something didn't quite work correctly: {0}", e.Message);
}
finally
{
// Perform any cleanup to roll back the data or close connections
// to files, database, network, etc.
}
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
Before
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReadTextFileWhile
{
class Program
{
static void Main(string[] args)
{
StreamReader myReader = new StreamReader("Values.txt");
string line = "";
while (line != null)
{
line = myReader.ReadLine();
if (line != null)
Console.WriteLine(line);
}
myReader.Close();
Console.ReadLine();
}
}
}
After
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReadTextFileWhile
{
class Program
{
static void Main(string[] args)
{
try
{
StreamReader myReader = new StreamReader("Values.txt");
string line = "";
while (line != null)
{
line = myReader.ReadLine();
if (line != null)
Console.WriteLine(line);
}
myReader.Close();
}
catch (DirectoryNotFoundException e)
{
Console.WriteLine("Couldn't fine the file. Are you sure the DIRECTORY exists?");
}
catch (FileNotFoundException e)
{
Console.WriteLine("Couldn't find the file. Are you sure you're looking for the correct file?");
}
catch (Exception e)
{
Console.WriteLine("Something didn't quite work correctly: {0}", e.Message);
}
finally
{
// Perform any cleanup to roll back the data or close connections
// to files, database, network, etc.
}
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
20 December 2011
C# Lesson 20 : Enumerations and the switch Decision Statement
Here, we demonstrate the use of Enumerations because, in the .NET Framework Class Library, properties can often be set only to a predetermined subset of possible values. To illustrate this point, we create our own custom enumeration and then utilize it in a simple application that demonstrates a third Decision statement, the switch.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UsingSwitch
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Type in a super hero's name to see his nickname:");
string userValue = Console.ReadLine();
switch(userValue.ToUpper())
{
case "BATMAN":
Console.WriteLine("Caped Crusader");
break;
case "SUPERMAN":
Console.WriteLine("Man of Steel");
break;
case "GREENLANTERN":
Console.WriteLine("Emerald Knight");
break;
default:
Console.WriteLine("Does not compute");
break;
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnderstandingEnumerations
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine("Hello world!");
Console.WriteLine("Type in a superhero's name to see his nickname: ");
string userValue = Console.ReadLine();
SuperHero myValue;
if (Enum.TryParse<SuperHero>(userValue, true, out myValue))
{
switch (myValue)
{
case SuperHero.Batman:
Console.WriteLine("Caped crusader");
break;
case SuperHero.Superman:
Console.WriteLine("Man of Steel");
break;
case SuperHero.GreenLantern:
Console.WriteLine("Emerald Knight");
break;
default:
break;
}
}
else
{
Console.WriteLine("Does not compute");
}
Console.ReadLine();
}
}
enum SuperHero
{
Batman,
Superman,
GreenLantern
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComplexIfStatement
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Pick a number between 1 and 100:");
string userValue = Console.ReadLine();
int compareValue = int.Parse(userValue);
if ((compareValue < 1) || (compareValue > 100))
Console.WriteLine("The number you chose was out of bounds.");
else if ((compareValue == 42) || (compareValue > 90))
Console.WriteLine("You found one of the special numbers!");
else
Console.WriteLine("You didn't find one of the special numbers");
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UsingSwitch
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Type in a super hero's name to see his nickname:");
string userValue = Console.ReadLine();
switch(userValue.ToUpper())
{
case "BATMAN":
Console.WriteLine("Caped Crusader");
break;
case "SUPERMAN":
Console.WriteLine("Man of Steel");
break;
case "GREENLANTERN":
Console.WriteLine("Emerald Knight");
break;
default:
Console.WriteLine("Does not compute");
break;
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnderstandingEnumerations
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine("Hello world!");
Console.WriteLine("Type in a superhero's name to see his nickname: ");
string userValue = Console.ReadLine();
SuperHero myValue;
if (Enum.TryParse<SuperHero>(userValue, true, out myValue))
{
switch (myValue)
{
case SuperHero.Batman:
Console.WriteLine("Caped crusader");
break;
case SuperHero.Superman:
Console.WriteLine("Man of Steel");
break;
case SuperHero.GreenLantern:
Console.WriteLine("Emerald Knight");
break;
default:
break;
}
}
else
{
Console.WriteLine("Does not compute");
}
Console.ReadLine();
}
}
enum SuperHero
{
Batman,
Superman,
GreenLantern
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComplexIfStatement
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Pick a number between 1 and 100:");
string userValue = Console.ReadLine();
int compareValue = int.Parse(userValue);
if ((compareValue < 1) || (compareValue > 100))
Console.WriteLine("The number you chose was out of bounds.");
else if ((compareValue == 42) || (compareValue > 90))
Console.WriteLine("You found one of the special numbers!");
else
Console.WriteLine("You didn't find one of the special numbers");
Console.ReadLine();
}
}
}
19 December 2011
C# Lesson 19 : Understanding Scope and Utilizing Accessibility Modifiers
Explore the scope of variables within code blocks and how accessibility modifiers, such as Public, Private, and Protected, are used by the .NET Framework Class Library to expose or hide implementation of their given services to consumers of that given class. This is sometimes referred to as "encapsulation."
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnderstandingScope
{
class Program
{
// private static string k = "";
static void Main(string[] args)
{
/*
string j = "";
for (int i = 0; i < 10; i++)
{
j = i.ToString();
k = i.ToString();
Console.WriteLine(i);
if (i == 9)
{
string l = i.ToString();
}
//Console.WriteLine("l: " + l);
}
//Console.WriteLine(i);
Console.WriteLine("Outsite of the for: " + j);
//Console.WriteLine("k: " + k);
helperMethod();
*/
Car car = new Car();
car.DoSomething();
Console.ReadLine();
}
/*
static void helperMethod()
{
Console.WriteLine("k from the helperMethod: " + k);
}
*/
}
class Car
{
public void DoSomething()
{
Console.WriteLine(helperMethod());
}
private string helperMethod()
{
return "Hello world!";
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnderstandingScope
{
class Program
{
// private static string k = "";
static void Main(string[] args)
{
/*
string j = "";
for (int i = 0; i < 10; i++)
{
j = i.ToString();
k = i.ToString();
Console.WriteLine(i);
if (i == 9)
{
string l = i.ToString();
}
//Console.WriteLine("l: " + l);
}
//Console.WriteLine(i);
Console.WriteLine("Outsite of the for: " + j);
//Console.WriteLine("k: " + k);
helperMethod();
*/
Car car = new Car();
car.DoSomething();
Console.ReadLine();
}
/*
static void helperMethod()
{
Console.WriteLine("k from the helperMethod: " + k);
}
*/
}
class Car
{
public void DoSomething()
{
Console.WriteLine(helperMethod());
}
private string helperMethod()
{
return "Hello world!";
}
}
}
Source : MS Virtual Academy
18 December 2011
C# Lesson 18 : Understanding Namespaces and Adding References to Assemblies
In this lesson, we explain how Namespaces allow us to disambiguate classes that may share the same name. And we explain how the .NET Framework Class Library is so large that including all its classes in every application you write is a waste of system resources. Certain project templates include references to the typical assemblies required by a given type of application, and we demonstrate this by referencing a custom assembly of Bob's own design.
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tabor;
namespace NamespacesAndReferencingAssemblies
{
class Program
{
static void Main(string[] args)
{
//System.IO.StreamReader myStreamReader = new System.IO.StreamReader();
//StreamReader myStreamReader = new StreamReader();
Bob bob = new Bob();
string html = bob.Lookup("http://www.learnvisualstudio.net");
Console.WriteLine(html);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tabor;
namespace NamespacesAndReferencingAssemblies
{
class Program
{
static void Main(string[] args)
{
//System.IO.StreamReader myStreamReader = new System.IO.StreamReader();
//StreamReader myStreamReader = new StreamReader();
Bob bob = new Bob();
string html = bob.Lookup("http://www.learnvisualstudio.net");
Console.WriteLine(html);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
17 December 2011
C# Lesson 17 : Working with Classes and Inheritances in the .NET Framework Class Library
This lesson continues to teach concepts about classes (specifically, in this case, inheritance) by showing you how to utilize inheritance in your own custom classes. Learn about overriding virtual functionality, abstract base classes, and sealed classes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnderstandingInheritance
{
class Program
{
static void Main(string[] args)
{
Car myCar = new Car();
myCar.Make = "BMW";
myCar.Model = "745li";
myCar.Color = "Black";
myCar.Year = 2005;
//myCar.TowingCapacity = 1200;
printVehicleDetails(myCar);
Truck myTruck = new Truck();
myTruck.Make = "Ford";
myTruck.Model = "F950";
myTruck.Year = 2006;
myTruck.Color = "Black";
myTruck.TowingCapacity = 1200;
printVehicleDetails(myTruck);
Console.ReadLine();
}
private static void printVehicleDetails(Vehicle vehicle)
{
Console.WriteLine("Here are the vehcile's details: {0}",
vehicle.FormatMe());
}
}
abstract class Vehicle
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public abstract string FormatMe();
}
class Car : Vehicle
{
public override string FormatMe()
{
return String.Format("{0} - {1} - {2} - {3}",
this.Make,
this.Model,
this.Color,
this.Year);
}
}
sealed class Truck : Vehicle
{
public int TowingCapacity { get; set; }
public override string FormatMe()
{
return String.Format("{0} - {1} - {2} Towing units",
this.Make,
this.Model,
this.TowingCapacity);
}
}
/*
class Semi : Truck
{
}
*/
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnderstandingInheritance
{
class Program
{
static void Main(string[] args)
{
Car myCar = new Car();
myCar.Make = "BMW";
myCar.Model = "745li";
myCar.Color = "Black";
myCar.Year = 2005;
//myCar.TowingCapacity = 1200;
printVehicleDetails(myCar);
Truck myTruck = new Truck();
myTruck.Make = "Ford";
myTruck.Model = "F950";
myTruck.Year = 2006;
myTruck.Color = "Black";
myTruck.TowingCapacity = 1200;
printVehicleDetails(myTruck);
Console.ReadLine();
}
private static void printVehicleDetails(Vehicle vehicle)
{
Console.WriteLine("Here are the vehcile's details: {0}",
vehicle.FormatMe());
}
}
abstract class Vehicle
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public abstract string FormatMe();
}
class Car : Vehicle
{
public override string FormatMe()
{
return String.Format("{0} - {1} - {2} - {3}",
this.Make,
this.Model,
this.Color,
this.Year);
}
}
sealed class Truck : Vehicle
{
public int TowingCapacity { get; set; }
public override string FormatMe()
{
return String.Format("{0} - {1} - {2} Towing units",
this.Make,
this.Model,
this.TowingCapacity);
}
}
/*
class Semi : Truck
{
}
*/
}
Source : MS Virtual Academy
16 December 2011
C# Lesson 16 : More About Classes and Methods
This lesson digs into more details about classes—what exactly happens when you create a new instance of a class? What is a reference to an instance of a class? How does passing the reference to a method affect a class? We also review overloaded methods, static versus instance methods, and constructors.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ObjectLifetime
{
class Program
{
static void Main(string[] args)
{
Car myCar = new Car();
// set properties
Car myOtherCar = myCar;
Car myThirdCar = new Car("Ford", "Escape", 2005, "White");
myOtherCar = null;
myCar = null;
}
}
class Car
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public double OriginalPrice { get; set; }
public Car()
{
// You could this from a configuration file, a database, etc.
// I'll just hardcode in this instance.
this.Make = "Nissan";
}
public Car(string make, string model, int year, string color)
{
Make = make;
Model = model;
Year = year;
Color = color;
}
/*
public Car(string someOtherInputParameter, string model, int year, string color)
{
Make = someOtherInputParameter;
Model = model;
Year = year;
Color = color;
}
* */
public static void MyMethod()
{
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ObjectLifetime
{
class Program
{
static void Main(string[] args)
{
Car myCar = new Car();
// set properties
Car myOtherCar = myCar;
Car myThirdCar = new Car("Ford", "Escape", 2005, "White");
myOtherCar = null;
myCar = null;
}
}
class Car
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public double OriginalPrice { get; set; }
public Car()
{
// You could this from a configuration file, a database, etc.
// I'll just hardcode in this instance.
this.Make = "Nissan";
}
public Car(string make, string model, int year, string color)
{
Make = make;
Model = model;
Year = year;
Color = color;
}
/*
public Car(string someOtherInputParameter, string model, int year, string color)
{
Make = someOtherInputParameter;
Model = model;
Year = year;
Color = color;
}
* */
public static void MyMethod()
{
}
}
}
Source : MS Virtual Academy
15 December 2011
C# Lesson 15 : Understanding and Creating Classes
Classes are integral to the .NET Framework, particularly the .NET Framework Class Library. Learn how classes are defined and new instances are created, how to define Properties, and how to both set values and get values for a given instance of the class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleClasses
{
class Program
{
static void Main(string[] args)
{
Car myNewCar = new Car();
myNewCar.Make = "Oldsmobile";
myNewCar.Model = "Cutlas Supreme";
myNewCar.Year = 1986;
myNewCar.Color = "Silver";
Console.WriteLine("{0} - {1} - {2}",
myNewCar.Make,
myNewCar.Model,
myNewCar.Color);
//double marketValueOfCar = determineMarketValue(myNewCar);
Console.WriteLine("Car's value: {0:C}", myNewCar.DetermineMarketValue());
Console.ReadLine();
}
private static double determineMarketValue(Car _car)
{
double carValue = 100.0;
// Somedat white come to go online and look up the car's value
// and trieve its value into the carValue variable
return carValue;
}
}
class Car
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public double DetermineMarketValue()
{
double carValue = 100.0;
if (this.Year > 1990)
carValue = 10000.0;
else
carValue = 2000.0;
return carValue;
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleClasses
{
class Program
{
static void Main(string[] args)
{
Car myNewCar = new Car();
myNewCar.Make = "Oldsmobile";
myNewCar.Model = "Cutlas Supreme";
myNewCar.Year = 1986;
myNewCar.Color = "Silver";
Console.WriteLine("{0} - {1} - {2}",
myNewCar.Make,
myNewCar.Model,
myNewCar.Color);
//double marketValueOfCar = determineMarketValue(myNewCar);
Console.WriteLine("Car's value: {0:C}", myNewCar.DetermineMarketValue());
Console.ReadLine();
}
private static double determineMarketValue(Car _car)
{
double carValue = 100.0;
// Somedat white come to go online and look up the car's value
// and trieve its value into the carValue variable
return carValue;
}
}
class Car
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public double DetermineMarketValue()
{
double carValue = 100.0;
if (this.Year > 1990)
carValue = 10000.0;
else
carValue = 2000.0;
return carValue;
}
}
}
Source : MS Virtual Academy
14 December 2011
C# Lesson 14 : Working with DateTime
Like strings, dates and times are represented using special types and so deserve some attention. In this lesson, we learn how to work with Date and Time data, how to create new instances of DateTime, how to add time, and how to format the data for display. We also discuss the TimeSpan class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatesAndTimes
{
class Program
{
static void Main(string[] args)
{
DateTime myValue = DateTime.Now;
//Console.WriteLine(myValue.ToString());
//Console.WriteLine(myValue.ToShortDateString());
//Console.WriteLine(myValue.ToShortTimeString());
//Console.WriteLine(myValue.ToLongDateString());
//Console.WriteLine(myValue.ToLongTimeString());
//Console.WriteLine(myValue.AddDays(3).ToLongDateString());
//Console.WriteLine(myValue.AddHours(3).ToShortTimeString());
//Console.WriteLine(myValue.AddDays(-3).ToShortDateString());
//Console.WriteLine(myValue.Month.ToString());
//DateTime myBirthday = new DateTime(1969, 12, 7);
//Console.WriteLine(myBirthday.ToShortDateString());
DateTime myBirthday = DateTime.Parse("12/7/1969");
TimeSpan myAge = DateTime.Now.Subtract(myBirthday);
Console.WriteLine(myAge.TotalDays);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatesAndTimes
{
class Program
{
static void Main(string[] args)
{
DateTime myValue = DateTime.Now;
//Console.WriteLine(myValue.ToString());
//Console.WriteLine(myValue.ToShortDateString());
//Console.WriteLine(myValue.ToShortTimeString());
//Console.WriteLine(myValue.ToLongDateString());
//Console.WriteLine(myValue.ToLongTimeString());
//Console.WriteLine(myValue.AddDays(3).ToLongDateString());
//Console.WriteLine(myValue.AddHours(3).ToShortTimeString());
//Console.WriteLine(myValue.AddDays(-3).ToShortDateString());
//Console.WriteLine(myValue.Month.ToString());
//DateTime myBirthday = new DateTime(1969, 12, 7);
//Console.WriteLine(myBirthday.ToShortDateString());
DateTime myBirthday = DateTime.Parse("12/7/1969");
TimeSpan myAge = DateTime.Now.Subtract(myBirthday);
Console.WriteLine(myAge.TotalDays);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
13 December 2011
C# Lesson 13 : Working with Strings
Since oftentimes in our applications we'll want to work with string data, this lesson approaches a number of different string manipulations. We look at built-in String methods to manipulate the content inside of a literal string and at the StringBuilder class for concatenating many strings together in a memory and resource-friendly manner.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Strings
{
class Program
{
static void Main(string[] args)
{
//string myString = "Go to your c:\\ drive";
//string myString = "My \"so called\" life";
//string myString = "What if I need \n a new line?";
//string myString = string.Format("{0}!", "Bonzai");
//string myString = string.Format("Make: {0} (Model: {1})", "BMW", "760li");
//string myString = string.Format("{0:C}", 123.45);
//string myString = string.Format("{0:N}", 123456789);
//string myString = string.Format("{0:P}", .123);
//string myString = string.Format("Phone number: {0:(###) ###-####}", 1234567890);
/*
string myString = "";
for (int i = 0; i < 100; i++)
{
//myString = myString + "--" + i.ToString();
myString += "--" + i.ToString();
}
* */
/*
StringBuilder myString = new StringBuilder();
for (int i = 0; i < 100; i++)
{
myString.Append("--");
myString.Append(i);
}
*/
string myString = " That summer we took threes across the board ";
//myString = myString.Substring(5, 14);
//myString = myString.ToUpper();
//myString = myString.Replace(" ", "--");
myString = String.Format("Length before: {0} -- After: {1}",
myString.Length, myString.Trim().Length);
Console.WriteLine(myString);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Strings
{
class Program
{
static void Main(string[] args)
{
//string myString = "Go to your c:\\ drive";
//string myString = "My \"so called\" life";
//string myString = "What if I need \n a new line?";
//string myString = string.Format("{0}!", "Bonzai");
//string myString = string.Format("Make: {0} (Model: {1})", "BMW", "760li");
//string myString = string.Format("{0:C}", 123.45);
//string myString = string.Format("{0:N}", 123456789);
//string myString = string.Format("{0:P}", .123);
//string myString = string.Format("Phone number: {0:(###) ###-####}", 1234567890);
/*
string myString = "";
for (int i = 0; i < 100; i++)
{
//myString = myString + "--" + i.ToString();
myString += "--" + i.ToString();
}
* */
/*
StringBuilder myString = new StringBuilder();
for (int i = 0; i < 100; i++)
{
myString.Append("--");
myString.Append(i);
}
*/
string myString = " That summer we took threes across the board ";
//myString = myString.Substring(5, 14);
//myString = myString.ToUpper();
//myString = myString.Replace(" ", "--");
myString = String.Format("Length before: {0} -- After: {1}",
myString.Length, myString.Trim().Length);
Console.WriteLine(myString);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
12 December 2011
C# Lesson 12 : While Iterations and Reading Data from a Text File
Learn a new type of iteration statement (while) and how to utilize the StreamReader class to stream data from a file to the Console window. Additionally, we learn how to add new files to our project, how to set properties of our file using the Properties window, and how to add a using statement as a means of resolving a class name referenced in our code to the namespace in which it is defined.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReadTextFileWhile
{
class Program
{
static void Main(string[] args)
{
StreamReader myReader = new StreamReader("Values.txt");
string line = "";
while (line != null)
{
line = myReader.ReadLine();
if (line != null)
Console.WriteLine(line);
}
myReader.Close();
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReadTextFileWhile
{
class Program
{
static void Main(string[] args)
{
StreamReader myReader = new StreamReader("Values.txt");
string line = "";
while (line != null)
{
line = myReader.ReadLine();
if (line != null)
Console.WriteLine(line);
}
myReader.Close();
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
11 December 2011
C# Lesson 11 : Creating and Calling Simple Overloaded Helper Methods
Now, we begin wading into the topic of methods by creating a helper method to break out code we may need to use in multiple places within our code. We create and call our methods to retrieve a value, create and use input parameters, learn about string formatting, and create overloaded versions of our method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelperMethods
{
class Program
{
static void Main(string[] args)
{
//string myValue = superSecretFormula("world");
string myValue = superSecretFormula("sunshine");
Console.WriteLine(myValue);
Console.ReadLine();
}
private static string superSecretFormula()
{
// some cool stuff here
return "Hello World!";
}
private static string superSecretFormula(string name)
{
return String.Format("Hello, {0}!", name);
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelperMethods
{
class Program
{
static void Main(string[] args)
{
//string myValue = superSecretFormula("world");
string myValue = superSecretFormula("sunshine");
Console.WriteLine(myValue);
Console.ReadLine();
}
private static string superSecretFormula()
{
// some cool stuff here
return "Hello World!";
}
private static string superSecretFormula(string name)
{
return String.Format("Hello, {0}!", name);
}
}
}
Source : MS Virtual Academy
10 December 2011
C# Lesson 10 : Creating Arrays of Values
In this lesson, we talk about arrays, which are multi-part variables—a "bucket" containing other "buckets," if you will. We demonstrate how to declare and utilize arrays, and we demonstrate a couple of powerful built-in methods that give arrays added features.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnderstandingArrays
{
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[5];
numbers[0] = 4;
numbers[1] = 8;
numbers[2] = 15;
numbers[3] = 16;
numbers[4] = 23;
//numbers[5] = 42;
Console.WriteLine(numbers.Length);
/*
int[] numbers = new int[] { 4, 8, 15, 16, 23, 42 };
Console.WriteLine(numbers[1].ToString());
Console.ReadLine();
*/
/*
string[] names = new string[] { "Eddie", "Alex", "Michael", "David Lee" };
foreach (string name in names)
{
Console.WriteLine(name);
}
Console.ReadLine();
*/
/*
string zig = "You can get what you want out of life " +
"if you help enough other people get what they want.";
char[] charArray = zig.ToCharArray();
Array.Reverse(charArray);
foreach (char zigChar in charArray)
Console.Write(zigChar);
*/
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnderstandingArrays
{
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[5];
numbers[0] = 4;
numbers[1] = 8;
numbers[2] = 15;
numbers[3] = 16;
numbers[4] = 23;
//numbers[5] = 42;
Console.WriteLine(numbers.Length);
/*
int[] numbers = new int[] { 4, 8, 15, 16, 23, 42 };
Console.WriteLine(numbers[1].ToString());
Console.ReadLine();
*/
/*
string[] names = new string[] { "Eddie", "Alex", "Michael", "David Lee" };
foreach (string name in names)
{
Console.WriteLine(name);
}
Console.ReadLine();
*/
/*
string zig = "You can get what you want out of life " +
"if you help enough other people get what they want.";
char[] charArray = zig.ToCharArray();
Array.Reverse(charArray);
foreach (char zigChar in charArray)
Console.Write(zigChar);
*/
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
09 December 2011
C# Lesson 9 : For Iterations
Iterations allow our applications to loop through a block of code until a condition is satisfied. We cover several different types of iteration statements throughout this series, how to utilize "code snippets" to help remind you of the syntax for this complex statement, and debugging in action.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ForIterations
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
//Console.WriteLine(i.ToString());
if (i == 7)
{
Console.WriteLine("Found seven!");
break;
}
}
for (int myValue = 0; myValue < 12; myValue++)
{
Console.WriteLine(myValue);
}
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ForIterations
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
//Console.WriteLine(i.ToString());
if (i == 7)
{
Console.WriteLine("Found seven!");
break;
}
}
for (int myValue = 0; myValue < 12; myValue++)
{
Console.WriteLine(myValue);
}
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
08 December 2011
C# Lesson 8 : Operators, Expressions, and Statements Duration
In this lesson, we discuss how to create a properly formed C# statement. We discuss how statements are made up of expressions and how expressions are made up of operators (think: verbs) and operands (think: nouns). Finally, we talk about compilation errors that occur when the syntax rules of C# are ignored.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OperatorsExpressionsStatements
{
class Program
{
static void Main(string[] args)
{
int x, y, a, b;
// Assignment operator
x = 3;
y = 2;
a = 1;
b = 0;
// There are many mathematical operators ...
// Addition operator
x = 3 + 4;
// Subtraction operator
x = 4 - 3;
// Multiplication operator
x = 10 * 5;
// Division operator
x = 10 / 5;
// There are many operators used to evaluate values ...
// Equality operator
if (x == y)
{
}
// Greater than operator
if (x > y)
{
}
// Less than operator
if (x < y)
{
}
// Greater or equal to operator
if (x >= y)
{
}
// Less than or equal to operator
if (x <= y)
{
}
// There are two "conditional" operators as well that can be used to expand / enhance an evaluation ...
// ... and they can be combined together multiple times.
// Conditional AND operator …
if ((x > y) && (a > b))
{
}
// Conditional OR operator …
if ((x > y) || (a > b))
{
}
// Also, here's the in-line conditional operator we learned about in the previous lesson ...
string message = (x == 1) ? "Car" : "Boat";
// Member access and Method invocation
Console.WriteLine("Hi");
x + y;
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OperatorsExpressionsStatements
{
class Program
{
static void Main(string[] args)
{
int x, y, a, b;
// Assignment operator
x = 3;
y = 2;
a = 1;
b = 0;
// There are many mathematical operators ...
// Addition operator
x = 3 + 4;
// Subtraction operator
x = 4 - 3;
// Multiplication operator
x = 10 * 5;
// Division operator
x = 10 / 5;
// There are many operators used to evaluate values ...
// Equality operator
if (x == y)
{
}
// Greater than operator
if (x > y)
{
}
// Less than operator
if (x < y)
{
}
// Greater or equal to operator
if (x >= y)
{
}
// Less than or equal to operator
if (x <= y)
{
}
// There are two "conditional" operators as well that can be used to expand / enhance an evaluation ...
// ... and they can be combined together multiple times.
// Conditional AND operator …
if ((x > y) && (a > b))
{
}
// Conditional OR operator …
if ((x > y) || (a > b))
{
}
// Also, here's the in-line conditional operator we learned about in the previous lesson ...
string message = (x == 1) ? "Car" : "Boat";
// Member access and Method invocation
Console.WriteLine("Hi");
x + y;
}
}
}
Source : MS Virtual Academy
07 December 2011
C# Lesson 7 : Branching with the if Decision Statement and the Conditional Operator
Branching allows us to add logic to our applications. This lesson introduces the ‘if Decision’ statement (in its various forms), along with the conditional operator. We also discuss how to refactor our code to make it more compact and less likely to produce errors, by eliminating duplicate code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decisions
{
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Please type something and press the Enter key.");
//string userValue;
//userValue = Console.ReadLine();
//Console.WriteLine("You typed: " + userValue);
Console.WriteLine("Would you prefer what is behind door number 1, 2, or 3?");
string userValue = Console.ReadLine();
//string message = "";
//if (userValue == "1")
//{
// message = "You won a new car!";
//}
//else if (userValue == "2")
// message = "You won a new boat!";
//else if (userValue == "3")
// message = "You won a new cat!";
//else
// message = "Sorry, we didn't understand. You lose!";
//Console.WriteLine(message);
string message = (userValue == "1") ? "boat" : "strand of lint";
Console.WriteLine("You won a {0}", message);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decisions
{
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Please type something and press the Enter key.");
//string userValue;
//userValue = Console.ReadLine();
//Console.WriteLine("You typed: " + userValue);
Console.WriteLine("Would you prefer what is behind door number 1, 2, or 3?");
string userValue = Console.ReadLine();
//string message = "";
//if (userValue == "1")
//{
// message = "You won a new car!";
//}
//else if (userValue == "2")
// message = "You won a new boat!";
//else if (userValue == "3")
// message = "You won a new cat!";
//else
// message = "Sorry, we didn't understand. You lose!";
//Console.WriteLine(message);
string message = (userValue == "1") ? "boat" : "strand of lint";
Console.WriteLine("You won a {0}", message);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
06 December 2011
C# Lesson 6 : Declaring Variables and Assigning Values Duration
Here, we start adding C# syntax to your vocabulary by talking about fundamental building blocks: data types and variables. We also discuss basic topics, such as naming conventions and data type conversions.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Variables
{
class Program
{
static void Main(string[] args)
{
/*
int x;
int y;
x = 7;
y = x + 3;
Console.WriteLine(y);
*/
//string myFirstName;
//myFirstName = "Bob";
//string myFirstNane = "Bob";
//var myFirstName = "Bob";
//var myFirstName = "";
//string myfirstname;
//Console.WriteLine(myFirstName);
int x = 7;
//string y = "Bob";
string y = "5";
string myFirstTry = x.ToString() + y;
//int mySecondTry = x + y;
int mySecondTry = x + int.Parse(y);
Console.WriteLine(myFirstTry);
//Console.WriteLine(mySecondTry);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Variables
{
class Program
{
static void Main(string[] args)
{
/*
int x;
int y;
x = 7;
y = x + 3;
Console.WriteLine(y);
*/
//string myFirstName;
//myFirstName = "Bob";
//string myFirstNane = "Bob";
//var myFirstName = "Bob";
//var myFirstName = "";
//string myfirstname;
//Console.WriteLine(myFirstName);
int x = 7;
//string y = "Bob";
string y = "5";
string myFirstTry = x.ToString() + y;
//int mySecondTry = x + y;
int mySecondTry = x + int.Parse(y);
Console.WriteLine(myFirstTry);
//Console.WriteLine(mySecondTry);
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
03 December 2011
C# Lesson 3 : Creating Your First C# Program
This lesson teaches you how to create a simple application—first using Windows Notepad and the C# Command Line Compiler, and then by using Visual Studio or Visual C# Express Edition. The video concludes with an explanation of common solutions to the many different problems you might encounter as you first begin writing and compiling code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// This is a comment
Console.WriteLine("Hello World");
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// This is a comment
Console.WriteLine("Hello World");
Console.ReadLine();
}
}
}
Source : MS Virtual Academy
23 September 2011
Oracle JDK 7 on OpenSuse as default JVM
After install of jdk-7-linux-i586.rpm, in terminal type these commands:
update-alternatives --install /usr/bin/java java /usr/java/jdk1.7.0/jre/bin/java 20000
update-alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0/jre/bin/javaws 20000
update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0/bin/javac 20000
update-alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0/bin/jar 20000
update-alternatives --config java
OpenSuse 64
cd /usr/lib64/browser-plugins
ln -s /usr/java/jdk1.7.0/jre/lib/amd64/libnpjp2.so /usr/lib64/browser-plugins/libnpjp2.so
FoxPro 64bit plugin
update-alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.7.0/jre/lib/amd64/libnpjp2.so 20000
FoxPro 32bit plugin
update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jdk1.7.0/jre/lib/i386/libnpjp2.so 20000
22 September 2011
JasperReport in NetBeans Swing Desktop Application
This is finally successfully coded procedure for showing Jasper Report in NetBeans Swing Desktop Application :
public void ShowReport() {
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/neosoft", "postgres", "postgres");
HashMap hm = new HashMap();
JasperReport jre;
jre = JasperCompileManager.compileReport("src//japi//report1.jrxml");
JasperPrint jr = JasperFillManager.fillReport(jre, hm, con);
JasperExportManager.exportReportToHtmlFile(jr, "report1.html");
JasperViewer.viewReport(jr, false);
} catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
} catch (SQLException se) {
System.out.println(se.getMessage());
} catch (JRException ex) {
System.out.println(ex.getMessage());
}
}
Also dont forget to include these jars into library :
public void ShowReport() {
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/neosoft", "postgres", "postgres");
HashMap hm = new HashMap();
JasperReport jre;
jre = JasperCompileManager.compileReport("src//japi//report1.jrxml");
JasperPrint jr = JasperFillManager.fillReport(jre, hm, con);
JasperExportManager.exportReportToHtmlFile(jr, "report1.html");
JasperViewer.viewReport(jr, false);
} catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
} catch (SQLException se) {
System.out.println(se.getMessage());
} catch (JRException ex) {
System.out.println(ex.getMessage());
}
}
Also dont forget to include these jars into library :
15 September 2011
JDBC PostgreSQL in JDeveloper
Here is how to solve postgresql jdbc driver installation for JDeveloper WebLogic 10.3.
1.) Download the driver from here (http://jdbc.postgresql.org/download.html). You will probably want to download the JDBC 4 driver. The downloaded file will be .zip, eventhough the weblogic requires .jar.
For those who are beginners should know that Sun used .jar which is
just another .zip file. Therefore rename the downloaded .zip to .jar.
2.) You can copy the file to C:\Oracle\Middleware\wlserver_10.3\server\lib .
3.) Open the following file C:\Oracle\Middleware\wlserver_10.3\common\bin\commEnv.cmd.
4.) Find the following line
set WEBLOGIC_CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%FEATURES_DIR%\weblogic.server.modules_10.3.3.0.jar;%WL_HOME%\server\lib\webservices.jar;%ANT_HOME%/lib/ant-all.jar;%ANT_CONTRIB%/lib/ant-contrib.jar
and append ;%WL_HOME%\server\lib\postgresql-8.4-701.jdbc4.jar
so it becomes
set WEBLOGIC_CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%FEATURES_DIR%\weblogic.server.modules_10.3.3.0.jar;%WL_HOME%\server\lib\webservices.jar;%ANT_HOME%/lib/ant-all.jar;%ANT_CONTRIB%/lib/ant-contrib.jar;%WL_HOME%\server\lib\postgresql-8.4-701.jdbc4.jar
5.) Make sure that the postgresql-8.4-701.jdbc4.jar reflects the postgres driver filename which you downloaded
6.) Restart the server
7.) Now if you go inside the Weblogic admin console and create a datasource you should be able to successfully test the configuration
Driver Class = "org.postgresql.Driver";
JDBC URL = "jdbc:postgresql://localhost:5432/neosoft";
USER = "postgres";
PASSWORD = "postgres";
source : Oracle Forum
1.) Download the driver from here (http://jdbc.postgresql.org/download.html). You will probably want to download the JDBC 4 driver. The downloaded file will be .zip, eventhough the weblogic requires .jar.
2.) You can copy the file to C:\Oracle\Middleware\wlserver_10.3\server\lib .
3.) Open the following file C:\Oracle\Middleware\wlserver_10.3\common\bin\commEnv.cmd.
4.) Find the following line
set WEBLOGIC_CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%FEATURES_DIR%\weblogic.server.modules_10.3.3.0.jar;%WL_HOME%\server\lib\webservices.jar;%ANT_HOME%/lib/ant-all.jar;%ANT_CONTRIB%/lib/ant-contrib.jar
and append ;%WL_HOME%\server\lib\postgresql-8.4-701.jdbc4.jar
so it becomes
set WEBLOGIC_CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%FEATURES_DIR%\weblogic.server.modules_10.3.3.0.jar;%WL_HOME%\server\lib\webservices.jar;%ANT_HOME%/lib/ant-all.jar;%ANT_CONTRIB%/lib/ant-contrib.jar;%WL_HOME%\server\lib\postgresql-8.4-701.jdbc4.jar
5.) Make sure that the postgresql-8.4-701.jdbc4.jar reflects the postgres driver filename which you downloaded
6.) Restart the server
7.) Now if you go inside the Weblogic admin console and create a datasource you should be able to successfully test the configuration
Driver Class = "org.postgresql.Driver";
JDBC URL = "jdbc:postgresql://localhost:5432/neosoft";
USER = "postgres";
PASSWORD = "postgres";
source : Oracle Forum
31 August 2011
Close all MDI children forms
procedure T_c_form_desktop.FormClose(Sender: TObject; var Action: TCloseAction);
var
i : Word;
begin
inherited;
if MDIChildCount > 0 then
for i := 0 to MDIChildCount - 1 do MDIChildren[i].Close;
end;
var
i : Word;
begin
inherited;
if MDIChildCount > 0 then
for i := 0 to MDIChildCount - 1 do MDIChildren[i].Close;
end;
25 July 2011
Future of Lazarus / FreePascal
(This post was taken from excellent subject in Lazarus Forum)
... But thats because everybody wants web bases applications and no more locally installed applications so most of the industry is working on that, abandoning desktop applications.
"Everybody wants":THAT'S SIMPLY NOT TRUE!
I face 1 customer every 1000 who prefer a web app instead of a desktop one.
If we are talking of fashion ok... I'm italian...
but the truth is that only some (AND FEW ONES ) scenarios can benefit from web based applications.
Simply ask to the extreme: what do you prefer, developing on your computer or using an online IDE? Do you prefere Aptana or Titanium? What you prefer a desktop chat client to put on the systray panel or a google chat in the browser?
Obviously if a global shared task manager is needed, surely web app is better.
But the main reason the industry/developers TRY to make everything web based, is for a WRONG paradigm: web app are OS independent and everywhere (or nowhere
). Yes, right, but are isolated from browsers, components (hundreds that born and die every year), servers, protocols, glue that interconnect a component/framework together, etc.?
Even entering the domain of what is "best" (at least more than system tools
) suited for web application, that is, business, financial and accounting management software, there are many caveats and problems, not only technical problems, but also legal and from from user point of view.
Some examples:
1) Usual user sentence when he try demo web apps: "It is too slow!!!". ALWAYS! Even using a Cray-X server! That's due to a more complicated verbose protocol. Even in the best case where java is used in the client side instead of JS, the overall software is perceived SLOW compared with a native/dedicated client.
Real case
Do you know Zurich Insurance? They had a DOS based software till last year, on novell LAN, called OASI. They have only recently changed to a web based equivalent software.
RESULT:EVERY USER feel this new application a down grade!
Everyone feel it bad because of the low responsiveness compared to the previous super quick software. Obviuosly it's not a matter of money because Zurich... you know..., nor config: dedicated lines, backup lines, etc. The problem is that there is nothing to do for phisics reasons. As the best truck of the world can't compete with a Ferrari or a Lamborghini Gallardo so a web app cant compete with a desktop one.
Responsiveness and other features are the reasons you can find desktop clients even for twitter, facebook, and other web app etc.
What developers have to understand is that end users are not developers. They don't rejoice only because we have an easy life making "write once execute everywhere" web app. When a user see a click response after 1s he think: "WHAT A SLUGGISHNESS!!!! What's wrong? (click click click click click click)".
End users are not like us. If a user wants a car and you give him a truck, is not more happy reasoning that it is tecnologically better, can carry more stuff, has more value in the industry, and so is OK that is slower.
2)
I both develop RIA and Desktop applications. Small/medium companies that call us to buy a software, after 2 seconds ask: "Isn't a web software, right?" (That means: if it is a web app I'm not interested at all).
Why? Simple:
a) They want data on their LAN, not in fantasiland or distributed all over the clouds of the world even if we are proud to hilight "cloud server" or GlassFish in the brochure!
b) They want to work even when DSL is down, and are not interested if the app is slow because of the line.
They also want to work if notebook don't have a line (for many could seem strange but in many nations trains, bus and ferry boats are places that rarely or often NEVER have a hot spot).
c) They would like to work from a pen drive if needed.
d) They know that online software (at least in Italy) is subject to the Guardia di Finanza (italian police whose specific task is to enforce tax evasion laws etc) WITHOUT ANY ASK OR ADVICE.
3) Initially I was willing to simplify my work making web app for everything. I thought I could gather every user under the same web app simply changing the location of the server:
- installing the app/server on the customer LAN (VMware/VBox) to cope with the clients mandatory will to have a desktop app
- installing on the web for those who need global access and no installation, working even from a pub client.
... but today I ask myself: what is the real benefit againsts a real dedicated client? It's only because I can't give them pub client access?
So after some years I have the evidence that only some web solutions are really well accepted from the users:
1) Software intended for occasional use, touch and go
2) Software for the big mass (es. communication like facebook, twitter, gmail)... by the way... about google.... try asking people to use Google Apps instead of m$ Word
. Have you ever tried a serious documents? Try the speed/responsiveness.
3) Software for huge companies where slowness is less important that everywhere + no maintainance (no manteinance... only idealistic idea! Let's say: Today is: I have all of the problems distributed on the cloud
)
and I'm now oriented to:
1) Hybrid apps (web app only for some functions)
2) Portable app (real native executable), that are also useable the way java web start do.
This can cope with almost every need the best way we can (in the user view point).
Developer view
Despite I have no problem developing RIA applications (I have also developed a framework), to me, there is nothing more satisfying than working with native applications, for plenty of reasons. Beyond a certain line, it's even easier because RIA apps is not that panacea. The worst thing for a desktop app is OS changes.... but now browsers war, technologies that appear and disappear, frameworks, GUI components (YUI, etc), servers, etc, brings more changes and need of mainteinance than a desktop applications using something like lazarus, all in one.
Just an example: In a small web app, i'm using jQuery and some jQ visual components, plus TinyMce + AjaxFileManager. Some days ago I update jQuery: problems!
So there is no better relief developing web apps. Don't counting problems such as resize images client side before uploading, dialogue with a cash register and other devices, changing the printer if the software has to print an invoce, using another printer if it has to print a chart, or using a Zebra card printer if it has to print a new fidelity card. Let's do it with a web app!
How easy is it? 
Web apps are limited to some targets: out of that targets the only benefit are... problems!
Quote
Not sure if you are thinking that Swing itself is dead, but from what I have read, this is referring to an enhancement that was planned for Java 7 to build a framework around Swing to make it easier for developers to build Swing apps.
That's referring to what it says: Netbeans Platform.
About the Swing framework (the best way Netbeans had to compete with VB/Delphi/Lazarus/RealBasic/code:blocks/and the rest of the desktop world), what you see when you choose New Project->Desktop application, IS DEAD!.
Swing probably will last for a long time, but the web is full of question like: "Is Swing dead?" Probably there is a real reason!
Whatever the case, I don't trust Oracle! Sun was another matter. Oracle is very similar to m$: you can aspect everything, even they shut down Java tomorrow (exaggeration but... not too much
).
About Netbeans Platform: is something like developing.... how can I say.... just imagine developing under Open Office or Microsoft Access. The developer get tied to Netbeans more than Java. With the previous way, you could choose to migrate the app to Eclipse. With NetBeans Platform is not possibile anymore.
Even though I was not very attracted from Pascal (reason why times ago I used C++ Builder instead of Delphi), Lazarus is so interesting that I changed my mind and I'm seriously studying it (I exhumed from my shelf a tome of Marco Cantu` on Delphi 6
).
So thanks to every developer and your great work with this product!
Blame the inexperienced developer, don't blame the tool.
From Lazarus forum
... But thats because everybody wants web bases applications and no more locally installed applications so most of the industry is working on that, abandoning desktop applications.
"Everybody wants":THAT'S SIMPLY NOT TRUE!
I face 1 customer every 1000 who prefer a web app instead of a desktop one.
If we are talking of fashion ok... I'm italian...
Simply ask to the extreme: what do you prefer, developing on your computer or using an online IDE? Do you prefere Aptana or Titanium? What you prefer a desktop chat client to put on the systray panel or a google chat in the browser?
Obviously if a global shared task manager is needed, surely web app is better.
But the main reason the industry/developers TRY to make everything web based, is for a WRONG paradigm: web app are OS independent and everywhere (or nowhere
Even entering the domain of what is "best" (at least more than system tools
Some examples:
1) Usual user sentence when he try demo web apps: "It is too slow!!!". ALWAYS! Even using a Cray-X server! That's due to a more complicated verbose protocol. Even in the best case where java is used in the client side instead of JS, the overall software is perceived SLOW compared with a native/dedicated client.
Real case
Do you know Zurich Insurance? They had a DOS based software till last year, on novell LAN, called OASI. They have only recently changed to a web based equivalent software.
RESULT:EVERY USER feel this new application a down grade!
Responsiveness and other features are the reasons you can find desktop clients even for twitter, facebook, and other web app etc.
What developers have to understand is that end users are not developers. They don't rejoice only because we have an easy life making "write once execute everywhere" web app. When a user see a click response after 1s he think: "WHAT A SLUGGISHNESS!!!! What's wrong? (click click click click click click)".
End users are not like us. If a user wants a car and you give him a truck, is not more happy reasoning that it is tecnologically better, can carry more stuff, has more value in the industry, and so is OK that is slower.
2)
I both develop RIA and Desktop applications. Small/medium companies that call us to buy a software, after 2 seconds ask: "Isn't a web software, right?" (That means: if it is a web app I'm not interested at all).
Why? Simple:
a) They want data on their LAN, not in fantasiland or distributed all over the clouds of the world even if we are proud to hilight "cloud server" or GlassFish in the brochure!
b) They want to work even when DSL is down, and are not interested if the app is slow because of the line.
They also want to work if notebook don't have a line (for many could seem strange but in many nations trains, bus and ferry boats are places that rarely or often NEVER have a hot spot).
c) They would like to work from a pen drive if needed.
d) They know that online software (at least in Italy) is subject to the Guardia di Finanza (italian police whose specific task is to enforce tax evasion laws etc) WITHOUT ANY ASK OR ADVICE.
3) Initially I was willing to simplify my work making web app for everything. I thought I could gather every user under the same web app simply changing the location of the server:
- installing the app/server on the customer LAN (VMware/VBox) to cope with the clients mandatory will to have a desktop app
- installing on the web for those who need global access and no installation, working even from a pub client.
... but today I ask myself: what is the real benefit againsts a real dedicated client? It's only because I can't give them pub client access?
So after some years I have the evidence that only some web solutions are really well accepted from the users:
1) Software intended for occasional use, touch and go
2) Software for the big mass (es. communication like facebook, twitter, gmail)... by the way... about google.... try asking people to use Google Apps instead of m$ Word
3) Software for huge companies where slowness is less important that everywhere + no maintainance (no manteinance... only idealistic idea! Let's say: Today is: I have all of the problems distributed on the cloud
and I'm now oriented to:
1) Hybrid apps (web app only for some functions)
2) Portable app (real native executable), that are also useable the way java web start do.
This can cope with almost every need the best way we can (in the user view point).
Developer view
Despite I have no problem developing RIA applications (I have also developed a framework), to me, there is nothing more satisfying than working with native applications, for plenty of reasons. Beyond a certain line, it's even easier because RIA apps is not that panacea. The worst thing for a desktop app is OS changes.... but now browsers war, technologies that appear and disappear, frameworks, GUI components (YUI, etc), servers, etc, brings more changes and need of mainteinance than a desktop applications using something like lazarus, all in one.
Just an example: In a small web app, i'm using jQuery and some jQ visual components, plus TinyMce + AjaxFileManager. Some days ago I update jQuery: problems!
So there is no better relief developing web apps. Don't counting problems such as resize images client side before uploading, dialogue with a cash register and other devices, changing the printer if the software has to print an invoce, using another printer if it has to print a chart, or using a Zebra card printer if it has to print a new fidelity card. Let's do it with a web app!
Web apps are limited to some targets: out of that targets the only benefit are... problems!
Quote
Not sure if you are thinking that Swing itself is dead, but from what I have read, this is referring to an enhancement that was planned for Java 7 to build a framework around Swing to make it easier for developers to build Swing apps.
That's referring to what it says: Netbeans Platform.
About the Swing framework (the best way Netbeans had to compete with VB/Delphi/Lazarus/RealBasic/code:blocks/and the rest of the desktop world), what you see when you choose New Project->Desktop application, IS DEAD!.
Swing probably will last for a long time, but the web is full of question like: "Is Swing dead?" Probably there is a real reason!
Whatever the case, I don't trust Oracle! Sun was another matter. Oracle is very similar to m$: you can aspect everything, even they shut down Java tomorrow (exaggeration but... not too much
About Netbeans Platform: is something like developing.... how can I say.... just imagine developing under Open Office or Microsoft Access. The developer get tied to Netbeans more than Java. With the previous way, you could choose to migrate the app to Eclipse. With NetBeans Platform is not possibile anymore.
Even though I was not very attracted from Pascal (reason why times ago I used C++ Builder instead of Delphi), Lazarus is so interesting that I changed my mind and I'm seriously studying it (I exhumed from my shelf a tome of Marco Cantu` on Delphi 6
So thanks to every developer and your great work with this product!
Blame the inexperienced developer, don't blame the tool.
From Lazarus forum
11 July 2011
gedit in OpenSuse 11.4
I tried to run the command “sudo gedit” which throwed me the error:
(gedit:9901): Gtk-WARNING **: cannot open display:
I discovered recently that you could run “gnomesu gedit” which, I think, is more easy to remember...
(from Blogging googling)
(gedit:9901): Gtk-WARNING **: cannot open display:
I discovered recently that you could run “gnomesu gedit” which, I think, is more easy to remember...
(from Blogging googling)
23 May 2011
Hide MDI Child Form
Use the ShowWindow function instead:
To hide:
procedure T_mdi_child_form.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
//this resolves problem with maximized MDI active form close
if Self.WindowState = wsMaximized then Self.WindowState := wsNormal ;
Action := caNone;
ShowWindow(self.WindowHandle, SW_HIDE);
end;
To show:
procedure T_mdi_child_form._action_show_Execute(Sender: TObject);
begin
inherited;
if _mdi_child_form = Nil then
Application.CreateForm(T_mdi_child_form, _mdi_child_form);
ShowWindow(_mdi_child_form.Handle, SW_SHOW);
_mdi_child_form.BringToFront ;
end;
To hide:
procedure T_mdi_child_form.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
//this resolves problem with maximized MDI active form close
if Self.WindowState = wsMaximized then Self.WindowState := wsNormal ;
Action := caNone;
ShowWindow(self.WindowHandle, SW_HIDE);
end;
To show:
procedure T_mdi_child_form._action_show_Execute(Sender: TObject);
begin
inherited;
if _mdi_child_form = Nil then
Application.CreateForm(T_mdi_child_form, _mdi_child_form);
ShowWindow(_mdi_child_form.Handle, SW_SHOW);
_mdi_child_form.BringToFront ;
end;
13 May 2011
Delphi Uses Cleanup
When you drop a VCL component on a Delphi form the Delphi IDE automatically adds the unit(s) required by the component to the interface section uses statement. If you later remove the component, the units are not removed from the uses statement. This causes the need to sometimes clean the uses statement of unused units.
The Delphi smart linker will ignore unused code so normally the presence of these "extra" units does not increase the size of the compiled program.
I generally copy the default Delphi uses clause
// for TForm
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
// for TDataModule
uses
SysUtils, Classes;
into the unit and comment out the original uses clause (in the interface section). Then I do save and Delphi will add all the units that the components on the form need. Next I add some missing units from commented block like ShellAPI e.t.c., for full compile, without errors.
from http://www.brenemanlabs.com
The Delphi smart linker will ignore unused code so normally the presence of these "extra" units does not increase the size of the compiled program.
I generally copy the default Delphi uses clause
// for TForm
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
// for TDataModule
uses
SysUtils, Classes;
into the unit and comment out the original uses clause (in the interface section). Then I do save and Delphi will add all the units that the components on the form need. Next I add some missing units from commented block like ShellAPI e.t.c., for full compile, without errors.
from http://www.brenemanlabs.com
07 May 2011
PostgreSQL > Restore 9.x backup in 8.x server
If you have a binary formatted dump file.backup, from some unknown PostgreSQL server 9.x version, and need to be restored to an older server running a 8.x version, when you try to restore it, you would got an error:
$ pg_restore -d rc -Fc dump.backup
pg_restore: [archiver] unsupported version (1.12) in file header
$ pg_restore --version
pg_restore (PostgreSQL) 8.3.13
So you probably have a version mismatch, but what where does it get 1.12 from? After some googling I found that 1.12 actually means 9.0 (naturally), so I used the 9.0 version of pg_restore to convert my binary file into a plan SQL file via the -f parameter.
$ pg_restore --version
pg_restore (PostgreSQL) 9.0.3
$ pg_restore -Fc dump.backup -f dump.sql
Copy dump.sql back to 8.3 server
$ psql database -f dump.sql
If you have some functions in that backup, you need to put these statment in start of dumped sql file :
CREATE LANGUAGE plpgsql;
Now everything shold work fine.
$ pg_restore -d rc -Fc dump.backup
pg_restore: [archiver] unsupported version (1.12) in file header
$ pg_restore --version
pg_restore (PostgreSQL) 8.3.13
So you probably have a version mismatch, but what where does it get 1.12 from? After some googling I found that 1.12 actually means 9.0 (naturally), so I used the 9.0 version of pg_restore to convert my binary file into a plan SQL file via the -f parameter.
$ pg_restore --version
pg_restore (PostgreSQL) 9.0.3
$ pg_restore -Fc dump.backup -f dump.sql
Copy dump.sql back to 8.3 server
$ psql database -f dump.sql
If you have some functions in that backup, you need to put these statment in start of dumped sql file :
CREATE LANGUAGE plpgsql;
Now everything shold work fine.
06 May 2011
Lazarus > PostgreSQL > Post data
To post data in PostgreSQL database, even after active session, using standard Lazarus IDE TPQConnection control, create event :
procedure T_c_data._sql_tableAfterPost(DataSet: TDataSet);
begin
_sql_table.ApplyUpdates;
_db_transaction.Commit/Retaining;
end;
procedure T_c_data._sql_tableAfterPost(DataSet: TDataSet);
begin
_sql_table.ApplyUpdates;
_db_transaction.Commit/Retaining;
end;
25 April 2011
PostgreSQL Backup and Restore
To backup and restore PostgreSQL with ignoring of database version us pg_dump and pg_restore like in next commands:
For Backup :
C:\pgsql\bin\pg_dump.exe
--host localhost
--port 5432
--username "username"
--format custom
--blobs
--ignore-version
--verbose
--file "postgresql.backup" databasename
For Restore :
C:\pgsql\bin\pg_restore.exe
--host localhost
--port 5432
--username username
--dbname databasename
--clean
--ignore-version
--verbose "postgresql.backup"
For Backup :
C:\pgsql\bin\pg_dump.exe
--host localhost
--port 5432
--username "username"
--format custom
--blobs
--ignore-version
--verbose
--file "postgresql.backup" databasename
For Restore :
C:\pgsql\bin\pg_restore.exe
--host localhost
--port 5432
--username username
--dbname databasename
--clean
--ignore-version
--verbose "postgresql.backup"
20 April 2011
How to change encoding type
Dump your database, drop your database, recreate your database with the
different encoding, reload your data. Make sure the client encoding is
set correctly during all this. P.S.: CREATE DATABASE test
WITH OWNER = postgres
ENCODING = 'WIN1250'
TABLESPACE = pg_default
LC_COLLATE = 'Serbian (Latin)_Serbia.1250'
LC_CTYPE = 'Serbian (Latin)_Serbia.1250'
CONNECTION LIMIT = -1;
25 December 2010
Lazarus, PostgreSQL, Fortes report - Bytea String BLOB fields
To save some image into dbimage control on a form :
procedure T_form._dbimageDblClick(Sender: TObject);
begin
if _opendialog.Execute then
begin
_db_grid.DataSource.DataSet.Edit;
_dbimage.Picture.LoadFromFile(_opendialog.FileName) ;
end;
end;
To print those fields in Fortes report, use dbimage >
procedure T_report._rlimageBeforePrint(Sender: TObject; var PrintIt: boolean);
var
st : Tstream;
s : string;
gc : TGraphicClass;
AGraphic : TGraphic;
begin
gc := nil;
AGraphic := nil;
st := _datamodule._table.CreateBlobStream(_datamodule._table_image_field,bmRead);
s := st.ReadAnsiString;
try
gc := GetGraphicClassForFileExtension(s);
if assigned(gc) then // gc is never assigned
begin
AGraphic := gc.Create; // never executed
AGraphic.LoadFromStream(st); // never executed
_rlimage.Picture.Assign(AGraphic); // never executed
end;
finally
if assigned(AGraphic) then
AGraphic.Free;
st.Free;
end
end;
I spend whole day just to develop those code ...
procedure T_form._dbimageDblClick(Sender: TObject);
begin
if _opendialog.Execute then
begin
_db_grid.DataSource.DataSet.Edit;
_dbimage.Picture.LoadFromFile(_opendialog.FileName) ;
end;
end;
To print those fields in Fortes report, use dbimage >
procedure T_report._rlimageBeforePrint(Sender: TObject; var PrintIt: boolean);
var
st : Tstream;
s : string;
gc : TGraphicClass;
AGraphic : TGraphic;
begin
gc := nil;
AGraphic := nil;
st := _datamodule._table.CreateBlobStream(_datamodule._table_image_field,bmRead);
s := st.ReadAnsiString;
try
gc := GetGraphicClassForFileExtension(s);
if assigned(gc) then // gc is never assigned
begin
AGraphic := gc.Create; // never executed
AGraphic.LoadFromStream(st); // never executed
_rlimage.Picture.Assign(AGraphic); // never executed
end;
finally
if assigned(AGraphic) then
AGraphic.Free;
st.Free;
end
end;
I spend whole day just to develop those code ...
09 November 2010
Fedora pgAdmin3
If you get error while loading shared libraries: libssl.so.0.9.8 in fedora while start pgadmin3
you have to make symlinks
sudo ln -s /lib/libssl.so.0.9.8b /lib/libssl.so.0.9.8
sudo ln -s /lib/libcrypto.so.0.9.8b /lib/libcrypto.so.0.9.8
you have to make symlinks
sudo ln -s /lib/libssl.so.0.9.8b /lib/libssl.so.0.9.8
sudo ln -s /lib/libcrypto.so.0.9.8b /lib/libcrypto.so.0.9.8
31 October 2010
Dynamic libraries can be found: libpq.so.4, libpq.so
I'm investigating the use of lazarus/postgresql for a linux desktop application.
Fresh Linux installation produce this error, when starting application
Sender=Exception
Exception=None of the dynamic libraries can be found: libpq.so.4, libpq.so
Fix is
Fresh Linux installation produce this error, when starting application
Sender=Exception
Exception=None of the dynamic libraries can be found: libpq.so.4, libpq.so
Fix is
ln -s /usr/lib/libpq.so.5 /usr/lib/libpq.so
18 October 2010
Lazarus Report Preview
This is a main logic of sample code to produce Preview of LazReport :
procedure T_f_main._ButtonClick(Sender: TObject);
begin
_frReport.LoadFromFile('_izvestaj.lrf');
_frReport.ShowReport;
end;
procedure T_f_main._ButtonClick(Sender: TObject);
begin
_frReport.LoadFromFile('_izvestaj.lrf');
_frReport.ShowReport;
end;
Lazarus ZeosDBO Stored Procedure Call for PostgreSQL functions
This is main logic in some Lazarus database form, powered by ZeosDBO, to call stored procedure (postgresql function), who is placed in ZSQLReadOnly SQL property, like
SELECT * FROM Name_Of_Function()
Then In ZTable BeforePost event, you reopen that ZSQL to retrieve default value of primary key, like this code :
procedure T_f_main._ZTableBeforePost(DataSet: TDataSet);
begin
if _DataSource.State in [dsInsert] then
with _ZSQL_readonly_procedure do
begin
Open ;
_ZTableID.Value := Fields[0].asInteger;
Close ;
end;
end;
SELECT * FROM Name_Of_Function()
Then In ZTable BeforePost event, you reopen that ZSQL to retrieve default value of primary key, like this code :
procedure T_f_main._ZTableBeforePost(DataSet: TDataSet);
begin
if _DataSource.State in [dsInsert] then
with _ZSQL_readonly_procedure do
begin
Open ;
_ZTableID.Value := Fields[0].asInteger;
Close ;
end;
end;
16 October 2010
postgresql on OpenSuse default login error (solved)
On terminal test : psql -h 127.0.0.1 -p 5432 postgres postgres
If you receive error:
psql: FATAL: Ident authentication failed for user "postgres"
Edit /var/lib/pgsql/data/pg_hba.conf, and write
trust
instead of "ident"
then reload PostgreSQL
As root: service postgresql reload
or as postgres user: pg_ctl reload
Ownership of pg_hba.conf has nothing to do with the authentication.
If you receive error:
psql: FATAL: Ident authentication failed for user "postgres"
Edit /var/lib/pgsql/data/pg_hba.conf, and write
trust
instead of "ident"
then reload PostgreSQL
As root: service postgresql reload
or as postgres user: pg_ctl reload
Ownership of pg_hba.conf has nothing to do with the authentication.
14 October 2010
Is Lazarus ready for writing commercial applications ?

(this is one software developer experience from Blaise Pascal Newsletter , that proves that Delphi multiplatform magic is possible, but in Open Source world through Lazarus project, so I simply must share it on my blog...)
"This article illustrates the enormous progress Lazarus has made because of the dedicated work of the core developer team: it shows Nowadays Lazarus is in many ways on a par with Delphi. In several key areas it is way ahead of Delphi (64 bit compiled executables, multi-platform and multi-OS, allows development on mobile and embedded systems).
Of course it is not the same as Delphi, but very cheap - see the price of the Lazarus USB stick in the Advertisement. So affordable for anyone and you get started immediately with no installation required. You can create any application you ever wanted and the number of components available is grows steadily. So the answer is YES. Perfect for commercial applications!
I started my job in 2001 at a Croatian company called Holobit...
At that time Holobit was a pretty small company with a few dozen customers. My primary task was to make the company's current C++ business applications run on Linux and Windows by using Delphi and Kylix and Borland's CLX technology. After years of C/C++ coding on linux OOP looked very simple and well organized. Two months later I concluded that Borland had great products, and the coding time is much shorter than it was with C/C++ (gtk+,qt) using vi editor. Anyway, within 3 months our business applications were converted to CLX and the company started selling for Linux & Win32. All was done with Kylix 2 and Delphi 6 (later upgraded to K3 & D7).
Creating native Linux apps was a good decision, so the number of customers started growing rapidly. Our customers were happy with the ability to choose between Linux and Windows client apps for dekstop PC’s, because it saves some money and creates a better and more secure environment. The second conversion issue that looked rather complicated - at that time - were databases. When I started to convert our applications, all of them used Foxpro, and I was very disapointed with it, because I already used Postgresql on Linux. So your guess that we moved all of our applications to Postgresql is quite correct.
At that time I didn't know third party components like Zeos etc..., so I wrote my own Postgresql driver and used it for several years. Later when I found Zeos - a nice surprise – I immediately started to use that. So it went on until 2004, there were rumors that Kylix was Exit, no news from Borland – just silence ... Yes it was Exited: shame on you Borland, not because you put Kylix into grave, but because you cheated your customers. For years, then, we were fighting with Borland products. (In the meantime Kylix could not run on any distributions based on Glibc higher than 2.4.X) then, until I saw someone had started a qt-widgetset in a Lazarus project, and that guy was Felipe, and thanks to Den Jean for Qt C bindings, because without C bindings we could not have a Qtwidgetset inside Lazarus.
I had looked into Lazarus just a few times before, but I was not attracted previously, because it supported only the Gtk1 widgetset which looked awful compared to the Qt2 used by Kylix, so now I got motivated to download the lazarus trunk and find out to see the way how it worked with Qt. (I already tried Gtk before). Well, as IG mentioned already, work on the Qt widgetset having only just started, the result needed a lot of improvements, so it does not work.
After a quick scan of Lazarus principles, the Lazarus component library (LCL) and widgetset connections to the LCL I began to contribute to the Lazarus project with a primary goal to get Qt widgetset up and running. My first patches then were sent to Felipe. He argued about my coding standards (hey, hey), but I fixed that and changed my coding standards to the Lazarus coding standard. Anyway, after a year or so the Qt widgetset became useable - in the meantime Lazarus developers granted me svn write access - so no more need to wait for Felipe and others to commit my patches. At the same time – business problems arose with Kylix & Delphi programming and the company management considered moving our thought about to move the complete codebase to Java or .Net . When the management decided this change must be made quickly I objected.
I was not very happy with that. Not because of the applications, but because of all the third party components used in our applications (ZeosLib, FastReports, TMS grids, VirtualTrees etc). I said that we would need a lot of time and resources to move our code to Java or .Net and the result of that operation was not reassuring. I was disturbed by these business decisions (and already had in mind to change the job), so at one day I asked the chief if they could agree to let me spend some time developing code using Lazarus, and in the next few months I showed some of our apps running on Qt4.
I had started a race against time, I had to fix the Qt-LCL and convert one of our applications to LCL (only a small one). That wasn't an easy task since qt-lcl is still not finished and lot of things were not working. Zeos for Lazarus already existed, but for this simple applications I had to have FastReports and TMS grids. So I had three months to make Qt under Lazarus useable, convert FastReports and TMS grids (both CLX licensed)...
After hundreds of hours of coding, the day of reckoning came. I had to show my work at the end of February 2008. I made a presentation on Linux, 32 bit Windows and on Mac OSX and the company management was pleased and satisfied with it. Of course there were still bugs and features not yet implemented, but they appreciated my main argument. If we moved to Lazarus we would be able to work on other (even more) supported platforms, and also because Lazarus is an open source project, we would not be at the mercy of decisions made by other companies (such as Borland) that had harmed us in the past. That became the happiest day in the last few years of my working life. I was given the budget and time required to move our applications to Lazarus. Now I had a reasonable time (15 months) to improve Lazarus and re-write our applications for Lazarus (and deal with other everyday tasks). During 2008/2009 I converted all the third party components and all of our applications to FPC/Lazarus, and therefore also contributed a lot of patches to the Lazarus project. The Goal is reached – Lazarus is better now than Kylix 3 and we started to deploy Lcl LCL applications over more than 3,500 at customers’ sites.
User impressions were positive since our apps looks native on all platforms. A few dozen of Mac OSX users were also happy since we give them native apps for the first time (they used Parallels + linux VM). WOW, what a glorious day. We just did not need the Borland products anymore.
Now our complete range of software is developed using FPC/Lazarus and uses PostgreSQL RDBMS:
1. HoloERP – ERP system with > 400 modules (forms)
2. Cafeman – Caffe bars & restaurants backoffice and POS system
3. TSuS – small shops backoffice & POS system
4. Cinema – software for cinemas (reservations, tickets etc)
5. ArhStudio – architects documentation database.
All of those these applications use the following 3rd party components:
· ZeosLib
· FastReports (ported CLX)
· TMS Grids (ported CLX, but also we licensed the newest VCL
and ported it also)
· TMS Planner (ported CLX, later VCL)
· FlexCell (licensed LCL , yes there's LCL version)
· Our custom components
Conclusion:
Why?
Lazarus is ready for commercial usage especially for people with legacy Kylix3 / Delphi7 codebases.
My personal opinion is that Lazarus Qt is much better than K3/D7 at this time (0.9.29 trunk), and developers will be happy with it's new 0.9.30 version.
· The only OOP RAD which supports so many platforms.
· Constantly developed by volunteers, it does not depend on commercial decisions so you can avoid bankrupcy etc.
· Costs almost nothing except energy and time.
· If it doesn't fit your needs, you can change it and contribute.
· If there's a bug - you can fix it and contribute it, but at least you can open an issue at lazarus mantis issue tracker."
Author of this blog text is Lazarus forum member Zeljan and software case is from http://www.holobit.net
02 October 2010
MS Windows Mobile 6.5 - How to return default lock screen
To return default lock screen in MS Windows Mobile 6.5 in some cooked ROM (NRG, TAEL and other), you should remove these registry keys :
[HKEY_LOCAL_MACHINE\Security\Shell\Lock]
"CustomLockScreensMask"=dword:00000013
"CustomLockScreensPath"="\\Windows\\LockScreen"
[HKEY_LOCAL_MACHINE\Security\Shell\Lock]
"CustomLockScreensMask"=dword:00000013
"CustomLockScreensPath"="\\Windows\\LockScreen"
Subscribe to:
Posts (Atom)
