5,379
社区成员
发帖
与我相关
我的任务
分享
library Project1;
{ 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. }
uses
//SysUtils,
//Classes,
StdCtrls;
{$R *.res}
procedure setlabelfont(l: TLabel);
begin
l.Font.Size := 24
end;
exports
setlabelfont;
begin
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure setlabelfont(l: TLabel); external 'project1.dll';
procedure TForm1.FormCreate(Sender: TObject);
begin
setlabelfont(Label1)
//Label1.Font.Size := 24
end;
end.
procedure TResourceManager.ChangeResource(GraphicsObject: TGraphicsObject;
const ResData);
var
P: PResource;
begin
Lock;
try // prevent changes to GraphicsObject.FResource pointer between steps
P := GraphicsObject.FResource;{上一个FResource}
GraphicsObject.FResource := AllocResource(ResData);{分配资源}
if GraphicsObject.FResource <> P then GraphicsObject.Changed;
FreeResource(P);{释放上一个FResource,此方法内部报错}
finally
Unlock;
end;
end;
procedure TResourceManager.FreeResource(Resource: PResource);
var
P: PResource;
DeleteIt: Boolean;
begin
if Resource <> nil then
with Resource^ do
begin
Lock;
try
Dec(RefCount);
DeleteIt := RefCount = 0;
if DeleteIt then
begin
if Resource = ResList then
ResList := Resource^.Next
else{调整字体资源链表ResList,删除掉Resource所在节点}
begin
P := ResList;
while P^.Next <> Resource do P := P^.Next;
{这里报错,P^.Next最终会等于nil,这时如果再取P^.Next即nil^.Next,当然会报错!}
P^.Next := Resource^.Next;
end;
end;
finally
Unlock;
end;
if DeleteIt then
begin // this is outside the critsect to minimize lock time
if Handle <> 0 then DeleteObject(Handle);
FreeObjects(Resource);
FreeMem(Resource);
end;
end;
end;