March 15, 2018

Sreekanth B

Delphi Advanced Experienced Freshers Interview Questions Answers

What Is Delphi?

Delphi is a product of Borland International. It is a native code compiler that runs under Windows 3.1 and provides visual programming tools somewhat similar to those found in Microsoft Visual Basic 3.0. The underlying language is Object Pascal, which is an extension of the object-oriented Pascal found in Turbo/Borland Pascal starting with version 5.5.

What Are The Different Types Of Pointers Used In Delphi?

There are typed pointers types that are being provided by Delphi like PChar and PExtended.
These points work with the Inc and Dec functions and don’t have any issue with the use of it.
They can increment the Pint64 pointer type and add the SizeOf(Int64) bytes at the pointer address location.
This way it allows the pointing of the pointer to point to the next memory location in the memory.
There are generic pointers that are used to point to anything and very useful in case of dynamic memory allocation.

How Does Delphi Handle Windows Callbacks?

Just like C: You can get a far pointer to your callback procedure (you have to remember to declare it with the "far" qualifier, unless you have {F$+} in effect to force all calls to be far), pass the pointer to the Windows callback function, and there it is.

How Does Delphis Exception Handling Work?

The basic structure goes something like this:

p := new(big_thing);
try
blah(p);
foo(p);
finally
dispose(p);
end;

The first line allocates a big block of memory. Then, in the "try" block, we execute several statements, each of which might produce an error--or, in other words, "raise an event." If an error does occur, the rest of the "try" block will be skipped, "finally" blocks will be executed.

If there are no errors, then the "finally" block will be entered when the last statement in the "try" block completes. So, either way, the big block of memory gets freed. These "try/finally" blocks will trap anything up to and including a Windows GPF.


Do I Have To Understand Object-oriented Programming To Use Delphi?

Well, yes, to a point. Delphi's user interface design tools produce object-oriented code. However, if you're familiar with either Visual Basic or Powerbuilder, you probably have enough understanding of OOP to get by.

You can do a great deal in Delphi without having to create your own objects, which is the point at which it becomes important to really understand something about them.

Do I Have To Know A Lot About The Windows Api To Use Delphi?

There seems to be a feeling that you need to know more about Windows to use Delphi than you do to use Visual Basic. This isn't really true; you can get by in both environments with a very minimal understanding of Windows internals. However, in both environments, you have to know at least a little about the Windows API in order to really make the most of what you have. The difference is that Delphi gives you a lot more power to do all these interesting things, so you feel more limited if you don't know how.

What Should I Give To Windows Api Functions That Want A Hwnd?

Each form has a property called Handle, which contains the form's hWnd. Many controls also have hWnd properties. However, don't try to pass Canvas.Handle to an API function expecting a hWnd, because TCanvas's Handle property is a hDC, not a hWnd.

Why Do I Get Exception Messages Even Though I Am In Protected Code?

By default, the internal debugger will halt any time there is an exception, even if the exception is trapped by code. This can often be useful for debugging purposes. If it offends you, turn it off. You control it from the Options/Environment menu.

How Do I Write A Global Error Handler?

Use the Application.OnException event. Look in the help under "application events" for details of how to create and attach an event handler to the application variable.

I Am Trying To Call From Delphi And It Gpfs. Whats Up?

Based on the number of postings to comp.lang.pascal, it would seem that by far the largest number of problems calling Windows API functions or non-Delphi DLLs are caused by passing Pascal-style strings to functions that expect null-terminated (PChar) strings.

This is the first thing you should check if you get a GPF or other strange results when calling an external function. See section 6.11 for more information on which type of strings go where.

When I Use The Glyph Property, How Do I Know Which Color Is Transparent?

Delphi always assumes that the color of the bottom left-hand corner pixel is the background color and should be displayed as transparent. Yes, it took me a while to figure this out. It's not documented anywhere, but if you have the VCL source, you can look at the code in BUTTONS.PAS.

How Do I Close A Modal Form? For That Matter, What Is The Best Way To Close Any Form?

Generally speaking, you call the form's Close method. This runs the OnClose event, which may decide it doesn't want to close, for example if there is unsaved data in the form. Close doesn't free the memory associated with the form, unless of course you put a call to Release in the form's OnClose event.

If you want to close a form without giving it a chance to argue, call the form's Release method. This is similar to Free, but it allows event handlers (e.g. OnDestroy) to finish running before the memory goes away.

Modal forms "end their modal state" when you set the form's ModalResult property to anything greater than zero. If you put a button on a modal form and set the button's ModalResult property to some value, then when the user clicks on that button the form will close with the result you specified. You can find out what the result was by calling ShowModal as a function; i.e. result := Form.ShowModal.

Are There Any Tools To Help Me Migrate My Applications To Delphi?

There is an automated translator that converts Visual Basic projects to Delphi. I have heard from a couple people who have tried using it, and the results seem to be pretty mixed. It's very useful for some people, but not useful at all for others.

Why Do I Get Compile Errors Acessing The Sender Object In Events?

If you look at the declaration, the Sender object is of type TObject, which is the class from which (almost) all other objects are derived. You're probably trying to access a property that isn't defined in TObject, like Text or Caption or something. For this reason, "Sender.Text" will fail, but if (for example) you know that the sender is of type TEdit, then you could use "(Sender As TEdit).Text". If you aren't certain that the Sender object will always be the same type, you can check it with "if (Sender is TEdit) then < blah> ;".

Can I Make Calls To Delphi Code From C Or C++?

Delphi can generate DLLs, which can be called from C, C++, Visual Basic, Powerbuilder, or anything else that understands standard Windows DLLs. There is an example of a database-capable DLL in the DEMOSDBDLL directory.

As is the case in all Windows programming languages that I know of, DLLs are difficult to debug and will crash your system if they aren't quite right. Save your source code frequently.

Can I Use Dlls Developed In C Or C++ From Delphi?

Delphi is capable of making calls to and receiving callbacks from any standard Windows DLL. In addition, it is said to be possible (though rather tricky) to get Delphi to access classes within C++ DLLs. Borland's WWW server has instructions on how to do this. I wasn't able to get it to work, but I think that's because I have weird DLLs.

What Technical Support Do We Get With Delphi?

You get access to the "up and running" line, which will only answer questions related to installing Delphi and getting it to run on your machine. The long hold times that were common when Delphi was first released seem to have improved--the current average seems to be about five minutes or so.

In order to get what borland calls "consultative" tech support (I.E. someone with whom you can discuss reasons why a program is not working), you have to pay $2/minute. You can call (900) 555-1015 and have the charges put on your phone bill, or else (800) 330-3372 and use a credit card. I have called twice, and they couldn't answer my question either time; however, they didn't charge me for the calls.

What If I Do Not Have A Cd-rom Drive?

Borland will ship Delphi on 3.5" floppy diskettes, but they charge extra for them. The resellers I have spoken to only carry the CD-ROM version because they don't want to have to stock two different items. I got my copy on CD, but the CD has directories on it called DISK1 through DISK15, so I assume it would be 15 diskettes if you got it that way. If you don't get the CD, you won't get the stuff they use to fill up space on the CD, like an AVI file of an animated spinning Delphi logo.

What Is The History Of Delphi?

Delphi is the descendant of Turbo Pascal, which was first released in 1983 for the CP/M operating system. Turbo Pascal was ported to MS-DOS in early 1984. During the early history of the IBM PC, Turbo Pascal was arguably the most popular language for serious development work--mostly because it was a real compiler, including the program editor and everything, that cost $19.95 and would run on a 64k machine. Borland introduced Turbo Pascal for Windows in 1990. The latest release of Borland Pascal (as it is now called), not including Delphi, was version 7.0 in late 1992.

Can We Write Multi-user Database Applications In Regular Delphi?

Using regular, non-client/server Delphi, I have developed an application that talks to a Sybase server using ODBC drivers. I didn't have to go to any serious trouble getting it to work, and data access speed is quite acceptable, better than it was under Visual Basic.

What Is The Difference Between Delphi And Delphi Client/server?

Delphi Client/Server includes everything from Delphi Desktop, plus the following:

SQL-Links 2.5, which includes native client drivers for Oracle, Sybase, Informix, and InterBase, and includes full royalty-free redistribution rights to those drivers, and which costs $995 if bought separately;
The Local InterBase Deployment Kit, $495 ;
ReportSmith/SQL, $300;
"Team development support" -- interoperation with PVCS (obviously, this is no use to you if you don't own PVCS), not available separately;
The visual query builder, which creates SQL statements for you, also not available separately;
The VCL source code, which is available separately for $100.

How Much Disk Space, Memory, Etc, Do I Need To Run Delphi?

The minimum installation of Delphi takes about 30Mb, and the full install takes 80Mb. In order to run it well, you'll need a 486 with a minimum of 8Mb of RAM, though I personally wouldn't try to run it in less than about 12Mb. I use a 486DX2/66 at home and a Pentium-90 at work, and to be honest, there's not much difference between them--Delphi's compiles are so fast that the CPU is really not a bottleneck.

What Operating Systems Does Delphi Support?

The only version of Delphi that has been released is for Windows 3.1. There is no reason why it should not run correctly under systems that provide Windows 3.1 emulation, like OS/2 Warp, Windows NT, etc. Borland has announced plans for a 32-bit version to coincide with Windows 95. It is rumored that this might be a free upgrade to users of Delphi 1.0, but I wouldn't count on it. It is also known that Delphi 1.0 does not run correctly on the prerelease version of Windows 95.

Applications built in Delphi are Windows 3.1, 16-bit applications. However, Borland has stated that existing Delphi applications will compile unmodified in 32-bit Delphi.

What Are The Different Types Of Inheritance Present In Delphi?

Specialization inheritance: this is the type of inheritance in which the child class is the advanced version of the parent’s class.

 Class inheritance: provides a way for the child class to include the features and complete properties of the parent’s class.

 It is used to extend the parent class and provide the left out features and methods.

 Abstract inheritance: this is the method that provides other skeleton methods which is being implemented by the child class.

 Interface: this is the way by which the class implements all the skeleton methods by using the interface itself.

What Is The Function Of Inheritance In Delphi?

 Inheritance is a method to inherit the properties of the parent’s class by the child class.
 Inheritance is used in Object oriented language and it deals with the real world objects and information.
 The data in these scenarios is treated as an object and it has the characteristics like size and the actions that are performed on them.
 In inheritance a class is dependent on another object. The child object inherits the properties of the parent’s class and uses it.
 Child class has its own features but it also inherits the properties or the features from the parent’s class.

The example shows it:

Type
TBall = class
protected
ballSize : Byte;
published
procedure Kick(power : Byte);
function GetSpeed : Byte;
constructor Create(size : Byte);
end;

TFootball = class(TBall)
private
ballPanels : Byte;
published
constructor Create(size : Byte; panels : Byte);
end;

What Does Memory Leak Show In Delphi?

Memory leak shows that the system is using more and more memory to assign to objects that are no longer active.
 This is the case when the object is unused and it is not getting deleted so in this case the memory doesn’t get freed.
 The program that doesn’t delete the unused object, in this case it uses more and more memory as it runs.
 Memory leak happens in the case of discarding unwanted blocks of memory.
 This situation doesn’t help the system and it uses more and more resources to slow down the system and due to this the system hangs up.

What Is The Procedure To Access The Database From Delphi?

To access the database the BDE needs to be configured as it defines an alias for the database that has to be connected.
 The configuration allows the avoidance of coding the directory path and it just takes the referring of the alias.
 The creation of three objects is required to access the database and that includes: Query or table object that in synchronization with the alias and it also fetches some data.
 Data source object that allows the linking between the data and the controls used to connect the database.
 Setting the active property on the table or query to TRUE will open the database and allow the accessing to be done.

How Is The Memory Used Within An Object In Delphi?

Classes are built to create objects and then the objects are allocated in the constructors and used in the methods.
The objects that are allocated in the constructor should have a releasing point and that is also in the destructor method.
The process in which, the constructor constructs, and after the work destructor destructs is called converse process.
The classes can be made to handle the memory properly by using the persistence property after the object that is currently used is being destroyed.

The example is as follows:

unit My;
interface
uses
Classes;
type
TMy = class
private
fileData : TStringList;
published
Constructor Create(const fileName : string);
Destructor Destroy; override;
procedure PrintFile;
end;

What Is The Process Of Exception Handling In Delphi?

The process of exception handling is as follows:

Allocate the memory and use the try block to execute the statements. The statements written in the try block will help to produce the error or it will raise an event.
After the error occurs then the try block will be skipped and it will be catched by the finally block.
In case of no error the finally block will be executed only after the last statement of the try block.
The memory gets freed due to handling of exceptions in a proper way.
The try and finally blocks are used to trap any exception that comes under way.
Providing of an “except” block that allows the handling of local errors or all the errors that can create the global error handler.

The program shows the use of exception handling:

p := new(hello);
try
me(p);
foo(p);
finally
dispose(p);
end;

How Can I Manipulate Data Programatically?

It is sometimes desirable to write code that deals with databases but is not associated with any particular form or user-interface details. To do this, you declare variables of type TDatabase, TTable and/or TQuery, and set their properties in code just as you would in the design environment. Make sure that you include the DB and DBTables units in your uses statement, or you will get "unknown identifier" errors during compilation.

How Do I Write A Change Password Function For A Paradox Table?

There is no way to do this within the Delphi VCL. Seems like a pretty serious omission to me. However, it is possible to do it by talking directly to the Borland Database Engine through the interface provided by the DBIPROCS and DBITYPES units.

You call DbiDoRestructure, but set all the "number of" variables to zero, which makes it leave the existing values intact. I have code to do this, but it's a bit too long to included here. E-mail graham (at) mhn.org if you want it.

Can I Use The Odbc Drivers That I Got With ?

Yes, generally. I have not encountered any ODBC drivers that don't work with Delphi, but on the other hand, I haven't tried any really exotic ones.

Does Delphi Support The Back-end?

Delphi Desktop does not directly support any back-ends except for Local InterBase, and of course the BDE (Borland Database Engine) itself. Delphi Client/Server directly supports Oracle, Sybase, Informix, and InterBase. In both cases, you can use third-party ODBC drivers to connect to any system you want.

How Do We Get Access To A Database From Delphi?

In general, you have to go to "BDE Config" and define an alias for the database you want to connect to. This allows you to avoid hard-coding a directory path into your application; you just refer to the alias. Then, you create a minimum of three objects on the desktop: A Query or Table object that actually talks to the alias and gets some data; a Data Source object that links between the data and the controls, and at least one data-aware control.

If you've been trying for hours to get this to work, and no matter what you do you just don't see anything happening, try setting the "active" property on the Table or Query to "True." This will open the database. I have seen many people get caught out by this the first time they try it.

Subscribe to get more Posts :