Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
An Introduction to COM Programming with Delphi (4 / 6)
Page 3: Our first true COM Object program
 More of this Feature
• Page 1: A Com Object walk-a-bout. A Class Factory tour.
• Page 2: Our first true COM Object program
 More Delphi COM Lessons
• TOC
• Lesson 1
• Lesson 2
• Lesson 3
• Lesson 5
• Lesson 6
 Join the Discussion
"Post your views, comments, questions and doubts to this article."
Discuss!
 Related Resources
• COM / OLE / ActiveX programming with Delphi
 Download Source Code
• HomeWork done

We've finished our Com Object walk-a-bout and a Class Factory tour. Our first true COM Object program was developed, we are ready for:

Homework Assignment

In this homework assignment, you are going to create an in-process COM server and a client application that will access the data from it. This in-process COM server will return system information to the client through the use of functions that perform Win API calls.

Homework Project (Server)

  1. Create 3 Com Objects that provide the implementation for the following interfaces. The names of them should be:
    1. TSystemDirectories
    2. TSystemInformation
    3. TCompleteSystemInformation
  2. Create an interface called ISystemDirectories that contains 2 methods.
    1. Method 1 returns a widestring containing the windows system directory name.
    2. Method 2 returns a widestring containing the windows directory name.
  3. Create another interface called ISystemInformation that contains 4 methods.
    1. Method 1 returns a widestring containing the name of the computer
    2. Method 2 returns a widestring containing the name of the keyboard
    3. Method 3 returns an Integer containing the number of function keys available on the keyboard.
    4. Method 4 returns an Integer containing the delay rate of the keyboard.
  4. Create a 3rd interface called ICompleteSystemInformation that allows you to access the functionality of the previous 2 interfaces, but provides no actual implementation of the methods.

Homework Project (Client)

  1. Create a new application
  2. Add a TListbox component to it and name it "OutputList"
  3. Add 3 buttons
    1. Get System Information button: Displays the results of the 4 methods defined in the ISystemInformation interface into the OutputList TListBox
    2. Get System Directories button: Displays the results of the 2 methods defined in the ISystemDirectories interface into the OutputList TListBox
    3. Get Complete SysInfo button: Displays all methods defined in the ISystemDirectories interface and ISystemInformation through the use of the ICompleteSystemInformation interface into the OutputList TListBox

Homework Summary
This homework isn’t that bad actually. You will probably spend more time trying to find the Win API calls that you will programming the interfaces and COM Objects. There is one major catch to this though that you must work though. It isn’t easy, but I’ve given you several clues in the Homework Project descriptions listed above. Because I am a nice guy, I’ll even give you another nugget of information:

When you instantiate a Com Object, the Class Factory never calls the objects constructor Create. It does call a certain abstract method however ... this may help with the 3rd interface I want you to build ...

Download the solution to this homework assignment.

That's all folks! (for this lesson)

First page > A Com Object walk-a-bout. A Class Factory tour. > Page 1, 1, 2, 3

An Introduction to COM Programming with Delphi: Table of Content
<< Previous Lesson (3): What is the implements directive? What is the Method Resolution Clauses? Pseudo-Multiple Interface Inheritance. Interface properties and other fine tales of horror.
>> Next Lesson (5): Marshaling Data. Behold the power of Variant Arrays. Using Variants and Variant Arrays.

 

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.