library Colorlib;
{ Important note about DLL memory management: ShareMem must be
the first unit in your library's USES clause AND your
project's (select View-Project 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
DELPHIMM.DLL shared memory manager, which must be deployed
along with your DLL. To avoid using DELPHIMM.DLL, pass string
information using PChar or ShortString parameters. }
uses
ShareMem,
SysUtils,
Classes,
Clrform in 'CLRFORM.PAS' {ColorForm};
exports
FBGetColors,
MyStrings,
MyString;
{$R *.RES}
begin
end.
unit Clrform;
interface
uses
ShareMem,Windows, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Buttons, ColorGrd, ExtCtrls;
type
TColorForm = class(TForm)
ColorGrid: TColorGrid;
Label1: TLabel;
Label2: TLabel;
CancelBitBtn: TBitBtn;
OkBitBtn: TBitBtn;
Bevel1: TBevel;
procedure CancelBitBtnClick(Sender: TObject);
procedure OkBitBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ColorForm: TColorForm;
function FBGetColors(var FColor, BColor: TColor;TempStr:String): WordBool;export;
function MyStrings(TempStr:String): TStringList;export;
function MyString(TempStr:String): String;export;
implementation
{$R *.DFM}
{- Exit dialog via Cancel button }
procedure TColorForm.CancelBitBtnClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
{- Exit dialog via Ok button }
procedure TColorForm.OkBitBtnClick(Sender: TObject);
begin
ModalResult := mrOk;
end;
{- Get foreground and background colors }
function FBGetColors(var FColor, BColor: TColor;TempStr:String): WordBool;
begin
Result := False;
ColorForm := TColorForm.Create(Application);
try
if ColorForm.ShowModal = mrOk then
with ColorForm do
begin
FColor := ColorGrid.ForegroundColor;
BColor := ColorGrid.BackgroundColor;
TempStr:='ooo';
Result := True;
end;
finally
ColorForm.Free;
end;
end;
function MyString(TempStr:String): String;
begin
Result:='OutString';
end;
function MyStrings(TempStr:String): TStringList;
var
s: TStringList;
begin
s := TStringList.Create;
s.Add('11');
s.Add('22');
s.Add('33');
// s.CommaText := '1 234 344 34232';
Result:=s;
// showMessage(s[2]);
s.Free;
end;
end.
//以下是测试程序exe
program Testdll;
uses
ShareMem,Forms,
Main in 'MAIN.PAS' {MainForm};
{$R *.RES}
begin
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
unit Main;
interface
uses
ShareMem,
Windows, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TMainForm = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
{- Declare external function in the Colorlib.Dll }
function FBGetColors(var FColor, BColor: TColor;TempStr:String): WordBool; external 'Colorlib.dll';
function MyStrings(TempStr:String): TStringList; external 'Colorlib.dll';
function MyString(TempStr:String): String; external 'Colorlib.dll';
{- Activate color dialog in the Colorlib.Dll }
procedure TMainForm.Button1Click(Sender: TObject);
var
FColor, BColor: TColor;
TempStr:String;
begin
FColor := Font.Color; { Form's text color }
BColor := Color; { Window background color }
if FBGetColors(FColor, BColor,TempStr) then { Call DLL ! }
begin
Memo1.Color := BColor; { Assign window color }
Memo1.Font.Color := FColor; { Assign text color }
end;
end;
procedure TMainForm.Button2Click(Sender: TObject);
begin
Button2.Caption:=MyString('iii');
end;
procedure TMainForm.Button3Click(Sender: TObject);
var
s1: TStringList;
begin
s1 :=TStringList.Create;
s1:=MyStrings('ssss');
s1.Free;
end;
end.