Posts

Showing posts from August, 2014

Difference between Override and Reintroduce in Delphi

Difference between Override and Reintroduce in Delphi When you decide to declare a method as virtual, you are giving permission to derived classes to extend and override the method with their own implementation. Use the reintroduce keyword to introduce a new implementation of a parent method (this hides the parent method). You can hide a method without using reintroduce but you will get a compiler warning. Using reintroduce will suppress the warning. You tell the compiler that you know that you hide the ancestor function and replace it with this new function and do so deliberately. Difference between Override and Reintroduce 1. The reintroduce and override modifiers have different meanings. The reintroduce modifier creates a new member with the same name, signature, and visibility and hides the original member. The override modifier extends the implementation for an inherited member and allows you to implement inheritance-based polymorphism. 2. Override is used in conjuction with Virtu

Difference between Virtual, Dynamic and Abstract methods in Delphi

Difference between Virtual, Dynamic and Abstract methods in Delphi Virtual and Dynamic methods are the strong concepts of Polymorphism in Delphi. Dynamic is semantically equivalent to Virtual. Both Virtual and Dynamic directives allows a class method to be override (replaced) by a same named method in a derived class.  You would mark a function or procedure as Virtual or Dynamic when you allow a programmer who creates a class based on your class to replace its functionality.  Virtual and Dynamic may be followed by the Abstract directive. This modifies the effect of the Virtual and Dynamic directives. It means that the current class must not code the method - it is there only as a placeholder to remind and ensure that derived classes implement it. Difference between Virtual and Dynamic methods in Delphi Although Virtual and Dynamic methods appear same but there is some differnce in their internal implementation. Virtual methods are implemented with a Virtual Method Table (VMT). There is

Difference between Owner and Parent in Delphi

Difference between Owner and Parent in Delphi Parent is the Window control where the control is displayed. Owner is the component responsible for making sure it's destroyed. Parent refers to the component that another component is contained in, such as TForm, TGroupBox or a TPanel. If one control (parent) contains others, the contained controls are child controls of the parent. Example of Owner and Parent Whenever we try add a button on a panel in a form, we try to make an invisible connection between the components.  When a component is dropped on a form at design time, the owner is the form and the parent is the container on which it is dropped. As we add the button on the panel, the panel automatically is set as the parent of the button while the form becomes the owner.   Another example, drop a group box on a form. Its owner and parent are both the form. Drop a check box on the group box. Its owner is the form and its parent is the group box. Parent is required to make a contro

Difference between Components and Controls in Delphi

Difference between Components and Controls in Delphi Controls are the visible elements on the Delphi Forms to which you can focus and interact. All the controls are components and vice versa is not true. So we can say that Controls are the subset of Components in Delphi. TComponent is the common ancestor of all component objects in Delphi. TControl is the abstract base class for all visual components. Everything that goes into the component palette is a Component. Everything that goes into the component and is something that the user of the program can control by using mouse or keyboard is a Control. For example: TTimer component is a component that you can place on a form, but it is not visible to the end-user. So TTimer is only the component but not a control in Delphi. Other examples like TTimer are TXMLDocument , TDatabase , TQuery , TTable , TDataSet , TDataSource etc. These all components play a vital role but never appear in front of the end user. A TEdit or TButton is visible

How to create and extract ZIP files in Delphi XE6?

How to create and extract ZIP files in Delphi XE6? Delphi provides System.Zip unit for creating ZIP files. System.Zip unit contains a simple ZIP extractor and creator class named TZIPFile . TZIPFile class mainly has three methods which are used to create and extract zip files: ZipDirectoryContents : Creates the zipped file IsValid : Validates the zip file ExtractZipFile : Extracts the zip file Following is the code snippet in Delphi to create a zip file. uses System.Zip; TZIPFile.ZipDirectoryContents('C:\FolderToZip', 'C:\ZippedFolder.zip'); Following is the code snippet in Delphi to extract a zip files.  uses System.Zip; ZipFile := 'ZippedFolder.zip'; //This is my zip file if TZipFile.IsValid(ZipFile) then //Validate zip file begin   TZipFile.ExtractZipFile(ZipFile, 'C:\DestinationDirectory'); //Extract the zip file end else begin   ShowMessage('Zip File is not valid'); end;

How to create XML document in Delphi XE4 using IXMLDOCUMENT and IXMLNODE?

How to create XML document in Delphi XE4 using IXMLDOCUMENT and IXMLNODE? Following is the self explanatory code in Delphi XE4 to create XML document using IXMLDOCUMENT and IXMLNODE interfaces. You should have XMLIntf and XmlDoc units in your uses section. Following CreateXMLinDelphi Delphi procedure creates an XML named MyXML in D drive. procedure CreateXMLinDelphi; var   XML : IXMLDOCUMENT;   RootNode, CurNode : IXMLNODE; begin   XML := NewXMLDocument;   XML.Encoding := 'UTF-8';   XML.Options := [doNodeAutoIndent];   RootNode := XML.AddChild('ParentNode');   CurNode := RootNode.AddChild('ChildNode1');   CurNode.Text := 'ChildNode Text 1';   CurNode := RootNode.AddChild('ChildNode2');   CurNode.Text := 'ChildNode Text 2';   XML.SaveToFile('D:\MyXML.xml');   ShowMessage('XML created successfully'); end; The above code generates following XML document: <?xml version="1.0" encoding="UTF-8"?> <Par

How to create an XTR file from XML in Delphi XE4 using XML Mapper?

Image
How to create an XTR file from XML in Delphi XE4 using XML Mapper? By using Delphi XE4 RAD Studio, you can create an XTR file from the given XML file using XML Mapper. XML Mapper Tool is provided in RAD Studio XE4 under Tools -> XML Mapper. Following are the steps to create an XTR file from XML in Delphi XE4 using XML Mapper: 1. Open the XML Mapper Tools from RAD Studio.  Now load an XML. In my case I am loading following simple XML: <?xml version="1.0" encoding="UTF-8"?> <Parent>   <Child1>ABC</Child1>   <Child2>XYZ</Child2> </Parent> All the nodes will appear on the left section of XML Mapper. 2. Right click on left section and select " Select All Children " option. Transformation will be created on the middle section. 3. Right click on left section again and select " Create Datapacket from XML ". You will see the generated datapacket on the right section of the XML Mapper. 4. Hit " Create