DelphiDLL200310Dr.Dobb's3DLLDLLDLLDelphiDLLDLLDLL1DelphiusesDelphiEXEDelphiusesWindowsMessagesbplDLLCOM+externalWindowsDLLWindowsDLLDLLDLLDelphiDLL2DLLDLLDynamicLinkLibraryDelphiDLLDLLDLLDLLDLLDLLDLLDLLDLLDelphi6DLLP271DLLyDLLDLLyDLLyDLLDLLDLLyDLLDLLyDLLDLLyDLLDLLDLL3DemofrmDemoDLLDemofrmDemoDLLObjDemo.dpr1ProjectManagerProjectGroup1AddNewProject...2NewItemsDLLWizardDelphiDLLDLLDemoSvr1ProjectGroup1AddNewProject...2NewItemsDLLWizardDemoSvr11DemoSvrlibraryDemoSvr;{ImportantnoteaboutDLLmemorymanagement:ShareMemmustbethefirstunitinyourlibrary'sUSESclauseANDyourproject's(selectProject-ViewSource)USESclauseifyourDLLexportsanyproceduresorfunctionsthatpassstringsasparametersorfunctionresults.ThisappliestoallstringspassedtoandfromyourDLL--eventhosethatarenestedinrecordsandclasses.ShareMemistheinterfaceunittotheBORLNDMM.DLLsharedmemorymanager,whichmustbedeployedalongwithyourDLL.ToavoidusingBORLNDMM.DLL,passstringinformationusingPCharorShortStringparameters.}usesShareMem,SysUtils,Classes,Demoin'Demo.PAS';{$R*.res}functionCarObj:TCar;beginResult:=TCar.create;end;functionBicycleObj:TBicycle;beginResult:=TBicycle.create;end;exportsCarObj,BicycleObj;end.DLLDLLCarObjBicycleObjCarBicycleDemoSvrCarObjBicycleObjCarBicycleCarBicycleDemo.pasusesDemo.PASDemo.PASDemo.pasObjDemoDemoSvr33Demo.pasObjDemoDemoSvrDemo.pasTBicycleTCarTBicycle=class(TVehicle)publicconstructorcreate;destructorDestory;procedureride;virtual;end;TCar=class(TVehicle)protectedFEngine:TEngine;publicconstructorcreate;destructorDestory;proceduredrive;virtual;end;ridedriveTBicycleTCarridedriveDLLDLLDLLVMTVMTVMTridedriveVMTfrmDemoDLLridedrivefrmDemoridedrivefrmDemo22DLLunitfrmDemo;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;type//---DLL---TVehicle=class(TObject);TCar=class(TVehicle)publicproceduredrive;virtual;abstract;end;TBicycle=class(TVehicle)publicprocedureride;virtual;abstract;end;//----------------------------TForm1=class(TForm)Button1:TButton;Button2:TButton;procedureButton2Click(Sender:TObject);procedureButton1Click(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}end;varForm1:TForm1;//---DLL---functionCarObj:TCar;external'DemoSvr.dll';functionBicycleObj:TBicycle;external'DemoSvr.dll';implementation{$R*.dfm}procedureTForm1.Button2Click(Sender:TObject);varMyCar:TCar;beginMyCar:=CarObj;ifMycar=nilthenexit;tryMyCar.drive;finallyMyCar.Free;end;end;procedureTForm1.Button1Click(Sender:TObject);varBicycle:TBicycle;beginBicycle:=BicycleObj;tryBicycle.ride;finallyBicycle.Free;end;end;end.BuildAllProjects4DLLDLLDLLvirtualabstractSteveTeixeiraDelphi62003209DLL4DelphiDLLDLLDLLDLLDelphi4BuildAllProjectsIDemoICarIBicycleDriveRide33IDemounitIDemo;interfacetypeICar=interface(IInterface)['{ED52E264-6683-11D7-B847-001060806215}']procedureDrive;end;IBicycle=interface(IInterface)['{ED52E264-6683-11D7-B847-001060806216}']procedureRide;end;implementationend.IDemoDLLUsevirtualabstractDemoTBicycleTCarunitDemo;interfaceusesSysUtils,Windows,Messages,Classes,Dialogs,IDemo;typeTVehicle=class(TInterfacedObject)protectedFColor:string;FMake:string;FTopSpeed:Integer;FWheel:TWheel;FWheels:TList;procedureSlowDown;procedureSpeedUp;procedureStart;procedureStop;end;TBicycle=class(TVehicle,IBicycle)publicconstructorcreate;destructorDestory;procedureride;end;TCar=class(TVehicle,ICar)protectedFEngine:TEngine;publicconstructorcreate;destructorDestory;proceduredrive;end;DLLIDemo55DLLIDemo4DLLunitfrmDemo;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,IDemo;//UseIDemotypeTForm1=class(TForm)Button1:TButton;Button2:TButton;procedureButton2Click(Sender:TObject);procedureButton1Click(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}end;varForm1:TForm1;functionCarObj:ICar;external'DemoSvr.dll';functionBicycleObj:IBicycle;external'DemoSvr.dll';implementation{$R*.dfm}procedureTForm1.Button2Click(Sender:TObject);varMyCar:ICar;beginMyCar:=CarObj;MyCar.drive;Mycar:=nil;end;procedureTForm1.Button1Click(Sender:TObject);varBicycle:IBicycle;beginBicycle:=BicycleObj;Bicycle.ride;Bicycle:=nil;end;end.4UseIDemoDLL425DLLDLLDelphiDLL6distributabel2.exeTfrmUsersUserSvr.dllTuserMaintTuserDMoperations+create+GetDepList:TStrings;+GetUserList(..):OLEVariant;+UpdateUserData(..)TIUserMaintTFormTDataModuleoperations+create+Destroy+GetDepList:TStrings;+GetUserList(..):OLEVariant;+UpdateUserData(..)TUserMaintoperationsoDataModuleCreate(..)TUserDMoperationsobtnExitClick(..)obtnQryByNameClick(..)obtnUpdateClick(..)oFormCreate(..)oFormDestroy(..)TfrmUsersdistributable2.exeTfrmUsersunitufrmUsersTIUserMaintunituIUserMaintUserSvr.dllTUserDMunitudmUserTUserMaintunituUserMaintTIUserMaintunituIUserMaintobjUsersUserDM677TfrmUsersTUserMaintDLLDLLDLLDLLTIUserMaintTIUserMaintTIUserMaintuIUserMaint.pas5UserSvrDistributable275uIUserMaintunituIUserMaint;interfaceusesClasses;typeTIUserMaint=class(TObject)publicfunctionGetDepList:TStrings;virtual;abstract;functionGetUserList(strName:String):O