Posts

Showing posts from March, 2014

How to use Generic TList Class in Delphi?

How to use Generic TList Class in Delphi? TList generic class is used to store a list of various data type variables in Delphi. Below is the simple program to illustrate the concept of TList generic class in Delphi. var   List: TList<Integer>;   FoundIndex: Integer; begin   { Create a new List. }   List := TList<Integer>.Create;   { Add a few values to the list. }   List.AddRange([5, 1, 8, 2, 9, 14, 4, 5, 1]);   writeln('Index of first 1 is ' + IntToStr(List.IndexOf(1)));   writeln('Index of last 1 is ' + IntToStr(List.LastIndexOf(1)));   writeln('Does List contains element 100? ' + BoolToStr(List.Contains(100)));   { Add another element to the list. }   List.Add(100);   writeln('There are ' + IntToStr(List.Count) + ' elements in the list.');   { Remove the first occurrence of 1. }   List.Remove(1);   { Delete a few elements from position 0. }   List.Delete(0);   List.DeleteRange(0, 2);   { Extract the remaining 1 from the list. }   L

How to use TDictionary Generics Collection in Delphi?

How to use  TDictionary  Generics Collection in Delphi? TDictionary is used to store key-value pair in Delphi. TDictionary is an example of Generic Collections in Delphi. Below is the simple Delphi program to illustrate the concept of TDictionary in Delphi. type   TCity = class     Country: String;     Latitude: Double;     Longitude: Double;   end; const   EPSILON = 0.0000001; var   Dictionary: TDictionary<String, TCity>;   City, Value: TCity;   Key: String; begin   { Create the dictionary. }   Dictionary := TDictionary<String, TCity>.Create;   City := TCity.Create;   { Add some key-value pairs to the dictionary. }   City.Country := 'Romania';   City.Latitude := 47.16;   City.Longitude := 27.58;   Dictionary.Add('Iasi', City);   City := TCity.Create;   City.Country := 'United Kingdom';   City.Latitude := 51.5;   City.Longitude := -0.17;   Dictionary.Add('London', City);   City := TCity.Create;   City.Country := 'Argentina';   { Notic

Generic Types in Delphi

Generic Types in Delphi Generics, a powerful addition to Delphi, were introduced in Delphi 2009 as a new language feature. Generics or generic types (also know as parametrized types), allow you to define classes that don't specifically define the type of certain data members. As an example, instead of using the TObjectList type to have a list of any object types, from Delphi 2009, the Generics.Collections unit defines a more strongly typed TObjectList. Simple Generics Type Example in Delphi Here's how to define a simple generic class: type   TGenericContainer<T> = class   Value : T;  end; With the following definition, here's how to use an integer and string generic container: var   genericInt : TGenericContainer<integer>;   genericStr : TGenericContainer<string>; begin   genericInt := TGenericContainer<integer>.Create;   genericInt.Value := 2009; //only integers   genericInt.Free;   genericStr := TGenericContainer<string>.Create;   genericStr.

Basic WCF Interview Questions and Answers for .NET Developers

Basic WCF Interview Questions and Answers for .NET Developers If you are preparing of .NET interview, must brush up WCF concepts also. Mostly in every .NET project, WCF is used. So, every .NET developer must know at least basics of WCF. By keeping that in mind, I have tried to list down some basic WCF interview questions and answers which every .NET developer should know before going to the interview room. These WCF interview questions and answers cover basic concepts of WCF, SOA, difference between WCF and web services, need of WCF, endpoints in WCF like Address, Contracts and Bindings, types of Bindings in WCF, types of contracts in WCF, components of WCF, transport schemas in WCF, transactions in WCF, isolation levels in WCF, how to host WCF services, generating proxies for WCF services etc. So, lets have a look upon thes basic WCF interview questions and answers. 1. What is WCF (Windows Communication Foundation)? Windows Communication Foundation (WCF) is an SDK for developing and d

Encoding and Decoding a String in Delphi XE4 using Indy 10

Encoding and Decoding a String in Delphi XE4 using Indy 10 I am using Delphi XE4 and Indy 10. I want to share how I encoded and decoded a file in Delphi XE4 using Indy 10 client. Include IdCoder, IdCoder3to4, IdCoderMIME units and use TIdEncoderMIME and TIdDecoderMIME classes for this purpose. Following are two simple Delphi functions which illustrate the way of encoding and decoding a file in Delphi XE4 in very simple way.  uses IdCoder, IdCoder3to4, IdCoderMIME; //Encoding function in Delphi XE4 procedure TMyForm.EncodeMIME_Example; var   EncodeMIME: TIdEncoderMIME;   myEncryptedFile: WideString;   stringToBeEncoded: WideString; begin   EncodeMIME :=  TIdEncoderMIME.Create(Self);   try     myEncryptedFile := EncodeMIME.Encode(stringToBeEncoded);   finally     EncodeMIME.Free;   end; end //Decoding function in Delphi XE4 procedure TMyForm.DecodeMIME_Example; var   DecodeMIME: TIdDecoderMIME;   myDecryptedFile: WideString;   stringToBeDecoded: WideString; begin   DecodeMIME :=  TIdDeco

How to Insert, Append, Edit and Delete Rows in a Dataset in Delphi?

How to Insert, Append, Edit and Delete Rows in a Dataset in Delphi? You can insert, append, edit and delete rows in datasets in Delphi. Following are the methods for performing these operations: Insert: Add a new record to the dataset at current position Append: Add a new record to the dataset at the end Edit: Sets the dataset in the 'edit' mode Post: Post changes to database Cancel: Cancel an edit/insert action Delete: Removes the active record Inserting/Appending a row in the dataset: The Append and Insert methods allow you to begin the process of adding a row to the dataset. The only difference between these two methods is the Insert method will insert a blank row buffer at the current position in the dataset, and the Append method will add a blank row buffer at the end of the dataset. This row buffer does not exist in the physical datset until the row buffer is posted to the actual dataset using the Post method. If the Cancel method is called, then the row buffer and

Why you should choose Dedicated Web Server Hosting for your business website?

Why you should choose Dedicated Web Server Hosting for your business website? If you are starting a website for your business and are thinking to go for a dedicated web server hosting, here are some points to which you should give a thought before making any decision. A dedicated web server hosting provides you good bandwidth to handle massive traffic to your website. You can easily scale your website with dedicated web server hosting. Also, you will get flexibility, security and full control on the various resources in a dedicated web server hosting.  Do you need to handle huge traffic? If your website encounters a huge traffic everyday, you need to opt for dedicated web hosting. In shared hosting, your website is being hosted on a server with other clients, you are at risk of not having enough memory or ample bandwidth because other websites are sapping it all up. Sometimes it may happen that a massive traffic hit your website and your shared hosting is already running with low perfo