下面是我写的一个简单的demo,想请大家告诉我怎么把它转换成一个dll文件!unit demo;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,IniFiles, Mask;type
TForm1 = class(TForm)
Button1: TButton;
Button4: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button5: TButton;
ComboBox1: TComboBox;
ScrollBar1: TScrollBar;
Button3: TButton;
Button6: TButton;
Button7: TButton;
Button2: TButton;
Button8: TButton;
RadioButton1: TRadioButton;
ListBox1: TListBox;
MaskEdit1: TMaskEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
IniFile,IniFile1: TIniFile;
total,wCount: Integer;
slabel,nName,nLanguage,nShortcuts,nColor,nSize,nTips,nRes: string;implementation{$R *.dfm}function SplitStr(var AStr: string; ASplitChar: Char = ';'): string; //截取字串
var
sF: string;
begin
sF := '';
if AStr <> '' then
if Pos(ASplitChar, AStr) > 0 then
begin
sF := Copy(AStr, 1, Pos(ASplitChar, AStr) - 1);
AStr := Copy(AStr, Pos(ASplitChar, AStr) + 1, MaxInt);
end
else
begin
sF := AStr;
AStr := '';
end;
Result := sF;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i,wCount:integer;
IniFile: TIniFile;
begin
{生成語言庫}
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'demo1.ini');
IniFile.WriteInteger('language','ivar',0);
IniFile.WriteInteger('frmCount','wCount',1);
wCount:=IniFile.ReadInteger('frmCount','wCount',1);
IniFile.WriteInteger('frm'+IntToStr(wCount),'total',Componentcount);
IniFile.WriteString('frm'+IntToStr(wCount),'frmCaption','form'+IntToStr(wCount));
form1.Caption:=IniFile.ReadString('frm'+IntToStr(1),'frmCaption','');
for i := 1 to Componentcount do
begin
iniFile.WriteString('frm'+IntToStr(wCount),'label'+IntToStr(i),TForm(Components[i-1]).Caption+'^'+TForm(Components[i-1]).ClassName+'^'+''+'^'+inttostr(TForm(Components[i-1]).Font.Color)+'^'+inttostr(TForm(Components[i-1]).Font.Size)+'^'+TForm(Components[i-1]).Hint+'^'+'');
end;
copyfile('demo1.ini' ,'language.ini',false);
deletefile(ExtractFilePath(ParamStr(0))+'demo1.ini');
{調用語言庫}
for i := 1 to Componentcount do
begin
IniFile1:=TInifile.Create(ExtractFilePath(ParamStr(0))+'lang\language.ini');
slabel:=IniFile1.ReadString('frm'+IntToStr(1),'label'+IntToStr(i),'');
nName:=SplitStr(slabel,'^');
nLanguage:=SplitStr(slabel,'^');
nShortcuts:=SplitStr(slabel,'^');
nColor:=SplitStr(slabel,'^');
nSize:=SplitStr(slabel,'^');
nTips:=SplitStr(slabel,'^');
nRes:=SplitStr(slabel,'^');
if nName<>'' then
begin
TForm(Components[i-1]).Caption:=nName;
TForm(Components[i-1]).Font.Color:=strtoint(nColor);
TForm(Components[i-1]).Font.Size:=strtoint(nSize);
TForm(Components[i-1]).Hint:=nTips;
end;
end;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,IniFiles, Mask;type
TForm1 = class(TForm)
Button1: TButton;
Button4: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button5: TButton;
ComboBox1: TComboBox;
ScrollBar1: TScrollBar;
Button3: TButton;
Button6: TButton;
Button7: TButton;
Button2: TButton;
Button8: TButton;
RadioButton1: TRadioButton;
ListBox1: TListBox;
MaskEdit1: TMaskEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
IniFile,IniFile1: TIniFile;
total,wCount: Integer;
slabel,nName,nLanguage,nShortcuts,nColor,nSize,nTips,nRes: string;implementation{$R *.dfm}function SplitStr(var AStr: string; ASplitChar: Char = ';'): string; //截取字串
var
sF: string;
begin
sF := '';
if AStr <> '' then
if Pos(ASplitChar, AStr) > 0 then
begin
sF := Copy(AStr, 1, Pos(ASplitChar, AStr) - 1);
AStr := Copy(AStr, Pos(ASplitChar, AStr) + 1, MaxInt);
end
else
begin
sF := AStr;
AStr := '';
end;
Result := sF;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i,wCount:integer;
IniFile: TIniFile;
begin
{生成語言庫}
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'demo1.ini');
IniFile.WriteInteger('language','ivar',0);
IniFile.WriteInteger('frmCount','wCount',1);
wCount:=IniFile.ReadInteger('frmCount','wCount',1);
IniFile.WriteInteger('frm'+IntToStr(wCount),'total',Componentcount);
IniFile.WriteString('frm'+IntToStr(wCount),'frmCaption','form'+IntToStr(wCount));
form1.Caption:=IniFile.ReadString('frm'+IntToStr(1),'frmCaption','');
for i := 1 to Componentcount do
begin
iniFile.WriteString('frm'+IntToStr(wCount),'label'+IntToStr(i),TForm(Components[i-1]).Caption+'^'+TForm(Components[i-1]).ClassName+'^'+''+'^'+inttostr(TForm(Components[i-1]).Font.Color)+'^'+inttostr(TForm(Components[i-1]).Font.Size)+'^'+TForm(Components[i-1]).Hint+'^'+'');
end;
copyfile('demo1.ini' ,'language.ini',false);
deletefile(ExtractFilePath(ParamStr(0))+'demo1.ini');
{調用語言庫}
for i := 1 to Componentcount do
begin
IniFile1:=TInifile.Create(ExtractFilePath(ParamStr(0))+'lang\language.ini');
slabel:=IniFile1.ReadString('frm'+IntToStr(1),'label'+IntToStr(i),'');
nName:=SplitStr(slabel,'^');
nLanguage:=SplitStr(slabel,'^');
nShortcuts:=SplitStr(slabel,'^');
nColor:=SplitStr(slabel,'^');
nSize:=SplitStr(slabel,'^');
nTips:=SplitStr(slabel,'^');
nRes:=SplitStr(slabel,'^');
if nName<>'' then
begin
TForm(Components[i-1]).Caption:=nName;
TForm(Components[i-1]).Font.Color:=strtoint(nColor);
TForm(Components[i-1]).Font.Size:=strtoint(nSize);
TForm(Components[i-1]).Hint:=nTips;
end;
end;
end;end.
解决方案 »
- 在stringgrid中如何用回车键代替tab
- 如何判断dbchart中的某条线是否存在,若则把这条线取消,应该怎么做啊(这些都需用代码动态实现),在线急急急啊
- JuckFapan来领分
- 我的程序需要控制用Modem建立的连接,请问如何挂断它
- DELPHI中的控件、API该如何学?
- 关于用循环语句控制控件的问题,高手请进(在线等待...)
- 诚信,中国人,答应给得分应该给
- 怎样编译单个可独立运行的EXE文件?(无需任何库支持)
- listview控件,我添加的节点,可以使他的visiable为看不见吗?我不想删除它.好像没有这个属性,有什么办法吗?
- DBedit的显示格式如何调整?
- 谁能看出下面这些代码是用什么加密的?
- delphi 视图如何限制条件
library HkTest;
uses
UCoord in UCoord.pas';//把你的UCoord.pas加入工程
exports//输出部分
EnableHotKeyHook,//供外面调用的函数
begin
end.
然后就是你的pas文件了,和其他的pas编写是一样的
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,
IniFiles,Forms,
Windows;{$R *.res}procedure Getinifile(Componentcount:Integer;Components:array of TComponent); stdcall;
var
i:integer;
IniFile: TIniFile;
begin
{生成語言庫}
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'demo1.ini');
IniFile.WriteInteger('language','ivar',0);
IniFile.WriteInteger('frmCount','wCount',1);
IniFile.WriteInteger('frm'+IntToStr(1),'total',Componentcount);
IniFile.WriteString('frm'+IntToStr(1),'frmCaption','form'+IntToStr(1));
for i := 1 to Componentcount do
begin
iniFile.WriteString('frm'+IntToStr(1),'label'+IntToStr(Components[i-1]),TForm(Components[i-1]).Caption+'^'+TForm(Components[i-1]).ClassName+'^'+''+'^'+inttostr(TForm(Components[i-1]).Font.Color)+'^'+inttostr(TForm(Components[i-1]).Font.Size)+'^'+TForm(Components[i-1]).Hint+'^'+'');
end;
copyfile('demo1.ini' ,'language.ini',false);
end;exports
Getinifile;begin
end.都等于没有说!有好多东西要改变的,知道的话我还用问吗?
例如IntToStr(Components[i-1])这句在程序中没有错,现在就没有办法用了!因为Components[i-1]的属性现在就不是integer啦!
procedure Getinifile(Componentcount:Integer;Components:array of TComponent);
stdcall;external 'Project1.dll';procedure TForm1.FormCreate(Sender: TObject);
var
i:Integer;
begin
Getinifile(Componentcount,Components[i-1]);
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure Getinifile(Componentcount:Integer;Components:array of TComponent);
stdcall;external 'Project1.dll';procedure TForm1.FormCreate(Sender: TObject);
var
i:Integer;
begin
for I := 0 to Componentcount do
Getinifile(Componentcount,Components[i-1]);
end;end.