Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 4 - Creating an About Box Plug-in
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Creating an About Box Plug-in
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2006-11-20

    Table of Contents:
  • Creating an About Box Plug-in
  • Continuing with our example
  • Creating a package
  • Adding some more code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating an About Box Plug-in - Adding some more code


    (Page 4 of 4 )

    In the host form, double click on the "About" menuitem and add the following code:

    procedure TForm1.About1Click(Sender: TObject);
    begin
    packhandle := LoadPackage('Myplugin1.bpl');
     if packhandle <> 0 then
    begin
    AClass := GetClass('TForm2');
     if AClass <> nil then
     begin
    with TComponentClass(AClass).Create(Application)
        as TCustomForm do
      begin
        Show;
        Free;
      end;
      end
      else
      begin
      showmessage('Could not load class');
      end;
    end
      else
      begin
      showmessage('Package handle empty');
      end;
    end;

    Also add the following two variables to the forms "var" section:

      packhandle: HModule;
      AClass: TPersistentClass;

    The code should be familiar to you by now. First we load the plug-in by calling the loadpackage() function, and then store the returned value in the "packhandle" variable:

    packhandle := LoadPackage('Myplugin1.bpl');

    Then we check to see whether the handle is empty. If it is not empty, we retrieve the class that is exposed by the package:

    if packhandle <> 0 then
    begin
    AClass := GetClass('TForm2');
     if AClass <> nil then
     begin
    with TComponentClass(AClass).Create(Application)
        as TCustomForm do
      begin
        Show;
      end;

    The AClass variable holds the exposed class(TForm2) and is then instantiated and called "TCustomForm." This new object gives us access to all the usual methods of a normal form. One of these is "show," which as the name implies shows a form.

    Then we simply use the "show" function to view the about box, and then free the TCustomForm object. I have not done this in this code, but it would be better to first check to see whether the package exists by using the fileexists() function (or any other method), and then based on that condition continue with the rest of the code.

    That is how simple and easy it is to create a plug-in. Of course you could always improve the code by including some kind of interface class that will reduce the chance of errors. But this should give you enough information to start creating your own plug-ins.

    Conclusion

    Delphi packages are ideal for building plug-ins. They provide a great way to make your applications small in size and modular. They also make your applications more useful by letting other developers extend their capabilities.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article explains how to use packages to built a plugin.
     

    DELPHI-KYLIX ARTICLES

    - Loading an XML Document into the DOM
    - Delphi Wrapper Classes and XML
    - Delphi and the DOM
    - Delphi and XML
    - Internet Access: Client Service
    - Finishing the Client for an Internet Access ...
    - The Client for an Internet Access Control Ap...
    - User Management for an Internet Access Contr...
    - Important Procedures for an Internet Access ...
    - Server Code for an Internet Access Control A...
    - Constructing the Interface for an Internet A...
    - Building a Server Application for an Interne...
    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek