我做的一个例子:
//dll
library Resource;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }{$R *.RES}
{$R Bitmap.RES}begin
end.
//程序
unit MainFrm;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, ExtCtrls;type
TForm1 = class(TForm)
sbCut: TSpeedButton;
sbCopy: TSpeedButton;
sbPaste: TSpeedButton;
sbBold: TSpeedButton;
sbItalic: TSpeedButton;
sbUnderLine: TSpeedButton;
sbLargeIcon: TSpeedButton;
sbSmallIcon: TSpeedButton;
sbDetails: TSpeedButton;
sbOpen: TSpeedButton;
sbNew: TSpeedButton;
sbSave: TSpeedButton;
sbLeftAlign: TSpeedButton;
sbRightAlign: TSpeedButton;
sbCenterAlign: TSpeedButton;
sbAdd: TSpeedButton;
sbAddTable: TSpeedButton;
sbAddFile: TSpeedButton;
sbTxt: TSpeedButton;
sbRtf: TSpeedButton;
sbHtml: TSpeedButton;
sbFolder: TSpeedButton;
sbFolderOpen: TSpeedButton;
sbFolderChild: TSpeedButton;
sbDel1: TSpeedButton;
sbDel2: TSpeedButton;
sbDel3: TSpeedButton;
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FResourceDll:THandle;
procedure LoadImage;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.LoadImage;
begin
FResourceDll:=LoadLibrary(Pchar('Resource.dll'));
if FResourceDll<>0 then
begin
sbCut.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Cut'));
sbCopy.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Copy'));
sbPaste.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Paste'));
sbBold.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Bold'));
sbItalic.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Italic'));
sbUnderLine.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('UnderLine'));
sbLargeIcon.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('LargeIcon'));
sbSmallIcon.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('SmallIcon'));
sbDetails.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Details'));
sbOpen.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Open'));
sbSave.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Save'));
sbNew.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('New'));
sbLeftAlign.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('LeftAlign'));
sbRightAlign.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('RightAlign'));
sbCenterAlign.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('CenterAlign'));
sbAdd.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Add'));
sbAddTable.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('AddTable'));
sbAddFile.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('AddFile'));
sbTxt.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Txt'));
sbRtf.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Rtf'));
sbHtml.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Html'));
sbFolder.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Folder'));
sbFolderOpen.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('FolderOpen'));
sbFolderChild.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('FolderChild'));
sbDel1.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Del1'));
sbDel2.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Del2'));
sbDel3.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Del3'));
FreeLibrary(FResourceDll);
end;
end;procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_ESCAPE then Close;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
LoadImage;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeLibrary(FResourceDll);
end;end.
//dll
library Resource;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }{$R *.RES}
{$R Bitmap.RES}begin
end.
//程序
unit MainFrm;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, ExtCtrls;type
TForm1 = class(TForm)
sbCut: TSpeedButton;
sbCopy: TSpeedButton;
sbPaste: TSpeedButton;
sbBold: TSpeedButton;
sbItalic: TSpeedButton;
sbUnderLine: TSpeedButton;
sbLargeIcon: TSpeedButton;
sbSmallIcon: TSpeedButton;
sbDetails: TSpeedButton;
sbOpen: TSpeedButton;
sbNew: TSpeedButton;
sbSave: TSpeedButton;
sbLeftAlign: TSpeedButton;
sbRightAlign: TSpeedButton;
sbCenterAlign: TSpeedButton;
sbAdd: TSpeedButton;
sbAddTable: TSpeedButton;
sbAddFile: TSpeedButton;
sbTxt: TSpeedButton;
sbRtf: TSpeedButton;
sbHtml: TSpeedButton;
sbFolder: TSpeedButton;
sbFolderOpen: TSpeedButton;
sbFolderChild: TSpeedButton;
sbDel1: TSpeedButton;
sbDel2: TSpeedButton;
sbDel3: TSpeedButton;
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FResourceDll:THandle;
procedure LoadImage;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.LoadImage;
begin
FResourceDll:=LoadLibrary(Pchar('Resource.dll'));
if FResourceDll<>0 then
begin
sbCut.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Cut'));
sbCopy.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Copy'));
sbPaste.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Paste'));
sbBold.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Bold'));
sbItalic.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Italic'));
sbUnderLine.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('UnderLine'));
sbLargeIcon.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('LargeIcon'));
sbSmallIcon.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('SmallIcon'));
sbDetails.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Details'));
sbOpen.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Open'));
sbSave.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Save'));
sbNew.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('New'));
sbLeftAlign.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('LeftAlign'));
sbRightAlign.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('RightAlign'));
sbCenterAlign.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('CenterAlign'));
sbAdd.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Add'));
sbAddTable.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('AddTable'));
sbAddFile.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('AddFile'));
sbTxt.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Txt'));
sbRtf.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Rtf'));
sbHtml.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Html'));
sbFolder.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Folder'));
sbFolderOpen.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('FolderOpen'));
sbFolderChild.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('FolderChild'));
sbDel1.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Del1'));
sbDel2.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Del2'));
sbDel3.Glyph.Handle:=LoadBitmap(FResourceDll,Pchar('Del3'));
FreeLibrary(FResourceDll);
end;
end;procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_ESCAPE then Close;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
LoadImage;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeLibrary(FResourceDll);
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货