Posts

Parameters in Delphi

Parameters Parameters are special kind of variables declared in a subroutine that are used to input some value into that subroutine. And the values that we pass in a function call is called as Arguments. in Delphi we can declare functions/procedures with parameters like following Example of a  Function declaration     function Add(Num1: integer; Num2: integer) : Integer; In above function declaration Num1, Num2 is called as Parameters. Using of function Add... var    iResult: integer; .......    iResult := Add(10, 20); 10, 20 are called as Arguments that are passed in function call. We can pass a single or multiple Parameter list to a Delphi subroutine. In case of Parameter list we declare Parameters separated by " ; " and enclosed by parenthesis. Parameter names must be valid identifiers. The parameter list specifies the number, order, and type of parameters that must be passed to the routine when it is called. With...

How to check for a valid EMail Address format in Delphi

Now a days most of applications have facility to send Email to Users with some information. So before send Email we generally check for valid Email address format. Here I have 2 approaches how to validate an Email address format in Delphi. 1. Validating Email addresses format using Regular Expression A regular expression is a special text that we can use as a search pattern. So for this we can use a regular expression string to check Email address syntax. And Delphi XE or later versions provide TRegEx class to use regular expression functions. So we can use this approach only on Delphi XE or latter versions. But f or this we have to use  System.RegularExpressions unit in Uses part.  ....     function IsMatch(const Input, Pattern: string): boolean;     function IsValidEmailRegEx(const EmailAddress: string): boolean; .... function TForm1.IsMatch(const Input, Pattern: string): boolean; begin   Result := TRegEx.IsMatch(Input, Pa...

Abstract Classes and Final Classes in Delphi

Abstract Classes in Delphi If a Class have at least one Abstract member then we call it Abstract Class. An Abstract member is a Class member that have only declaration on that class and the implementation of that member is expected to be done in its descendant classes. An Abstract Class can have normal methods also. In Delphi it allows to create Object of an Abstract Class but we should not create because when we try to access any Abstract member then we will get run time  exceptions. And if a class is having only Abstract members then it is called as pure Abstract class. Why we use Abstract Class? An Abstract Class is written when there are some common features are shared by all the objects. Suppose in your project if you have some common features then declare that type of properties and methods as Abstract and you can extend wherever you want in your Module For example... If you want to make a new car(WagonX) in which all the another car's p...

Delphi Classes and Objects

Classes in Delphi A Class consists of fields, methods and properties which defines character and behavior of an object. Instances of a Class are called as Objects and fields, methods are called as class members. -> A Field is essentially a variable that  is part of an object. -> Methods are procedures or functions that associated with a class and which operates on Class Objects. -> Property is an interface to data associated with an Object. A property have access specifiers which defines how the data will be read and modified. Objects are dynamically allocated blocks of memory whose structure is determined by their Class type. Each object has a unique copy of every field defined in the class, but all instances of a class share the same methods. Objects are created and destroyed by special methods called Constructor and Destructor . A variable of a Class is actually a pointer that references an object. Hence more than one variable can re...

Generic Types and Classes in Delphi

Generic Classes in Delphi Generics are powerful language features that allows to write type-safe classes, methods that act upon a type to be provided later. Generic classes makes it possible to bind a specific type with a class that means we can instantiate a class tied to a given data type. This makes code type safer. We can declare  generic type to accept any type, or we can use constraints, which will limit the types that can be passed to ones with parameterless constructors, or types of a specific class or those that implement specific interfaces. Once we define a specific type on generic declaration, this is enforced by the compiler that we cannot assign a different type value to the class member. Generic classes are as efficient as normal classes but in some case it is more efficient than other classes as the need for runtime type cast is reduced. Generally we use Generics  on cases when we need lots of type casting with a specific type or we are writing a lots of su...