for j:=0 to screen.Imes.Count-1 do
begin
BB[j]:=screen.imes.strings[j];
end;
以上这样好象总是报内存错!
begin
BB[j]:=screen.imes.strings[j];
end;
以上这样好象总是报内存错!
解决方案 »
- 窗体上放一个ActiveX插件,为什么程序关闭后,任务管理器中还是看到程序在运行?
- 在动态添加字段后,如何在DBGrid中立即显示?
- 我的窗体屏蔽了ALT+F4功能,但还是可以用他,为什么??是MDI主窗体,测试的时候,随便做一个窗体可以屏蔽啊,但现在我的软件不行,代码
- 如何判断一个文件夹是否存在
- BDE在何时释放内存?
- 难、难、难!!!难死我了!唉~~~~~~
- insert问题
- 一条汇编题目?
- 用{$imagebase $80000000}为何不能把dll文件映射到2G以上空间
- 如何拦截按钮被按下后不放开左键而鼠标移出按钮,以及再移回的Windows事件?
- DBGRIDEH分组汇总
- 如何将两张图片合并成一张
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type TAgeData = array of string; {------------声明}
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
function lst:TAgeData;{------------------------声明返回数组的函数}
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
a:TAgeData;
i:integer;
begin
{---------------------将输入法列表添加到ListBox1中}
a:=lst;
for i :=low(a) to High(a) do
ListBox1.Items.Add(a[i]);
end;function lst:TAgeData; {---------------------函数实体}
var
bb:TAgeData;
j:integer;
begin
SetLength(bb,screen.Imes.Count);
for j:=0 to screen.Imes.Count-1 do
begin
BB[j]:=screen.imes.strings[j];
end;
Result:=bb;
SetLength(bb,0);
end;end.
假如此函数在一个PROCEDURE中不报错,但是在FUNCTION里报"HWND"有错.为什么?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,imm;
type
TimmData = array of string; {------------声明}
TForm1 = class(TForm)
Button2: TButton;
ListBox1: TListBox;
Button1: TButton;
ComboBox1: TComboBox;
Button3: TButton;
Button4: TButton;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject); private
{ Private declarations }
public
end;
var
Form1: TForm1;
implementation
function getallime:TIMMData; stdcall;external 'tdks.dll';
function opencid(cidname: string):BOOLEAN; stdcall;external 'tdks.dll';
{$R *.dfm}//选择输入法 ,用 opencid函数
procedure TForm1.Button2Click(Sender: TObject);
var
str:string;
begin
str:=ComboBox1.text;
opencid(str) ;
end;//添加下拉列表框,通过函数GETallime
procedure TForm1.Button3Click(Sender: TObject);
var
bb:Timmdata;
i:integer;
begin
bb:=getallime;
for i:=low(BB) to HIGH(BB) DO
COMBOBOX1.Items.ADD(BB[i]) ;
end;
end.
报错:没有找到DLL接口,为什么?
library Project2;
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,imm;
{$R *.res}
type
TimmData = array of string; {------------声明}
//获取所有输入发的数组
function getALLIME: tIMMDATA ; stdcall;
var
j: integer;
a:Timmdata;
Begin
SetLength(a,screen.Imes.Count);
for j:=0 to screen.Imes.Count-1 do
begin
a[j]:=screen.imes.strings[j];
end;
result:=a;
SetLength(a,0);
End;
//打开输入法的函数
function opencid(cidname: string):BOOLEAN;stdcall;
var
I: Integer;
mycid:hkl;
begin
I:=screen.Imes.Indexof(cidname);
mycid:=hkl(screen.Imes.Objects[i]);
activatekeyboardlayout(mycid, KLF_activate);
RESULT:=TRUE;
end;
//关闭中文输入法 (要用PROCEDURE)
//procedure closeimm; stdcall;
// var
// mycid:hkl;
// begin
// mycid:=getkeyboardlayout(0);
// if immISime(mycid) then
// immsimulateHotkey(handle,IME_CHotKey_IME_NonIME_Toggle);
// end; //导出函数接口
exports
getallime,opencid;begin
end.
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
sharemem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls,Imm;
const
nHKL_LIST = 20;
{$R *.res}
function SetActivateIme(sWanted: string): boolean;stdcall;
var iHandleCount: integer;
pList: array[1..nHKL_LIST] of HKL;
szImeFileName: array[0..MAX_PATH] of char;
sImeFileName: string;
bInstalled: boolean;
i: integer;
begin
Result := False;
sWanted := AnsiUpperCase(sWanted);
// 看看是否安裝了這個輸入法
bInstalled := False;
iHandleCount := GetKeyboardLayoutList(nHKL_LIST, pList);
for i := 1 to iHandleCount do
begin
ImmGetDescription(pList[I], szImeFileName, MAX_PATH);
sImeFileName := AnsiUpperCase(StrPas(szImeFileName));
if (pos(sWanted,sImeFileName)>0) or (sWanted = sImeFileName) then
begin
bInstalled := True;
Break;
end;
end;
// 如果這個輸入法已安裝了, 讓那個輸入法的鍵盤分佈(KeyLayout)作用
if bInstalled then
begin
ActivateKeyboardLayout(pList[i], 0);
if (sWanted = sImeFileName) then
Result := False
else
Result := True;
end;
end; { of SetActivateIme }exports
SetActivateIme;
begin
end.
2:调用:
1.程序体:program lokeimm;uses
sharemem,{--------------------------注意这里}
Forms,
Umain in 'Umain.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.2:窗体调用DLL:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls,Imm; {Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Imm;
}type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
nHKL_LIST = 20;var
Form1: TForm1;
function SetActivateIme(sWanted: string): boolean;
//function SetKey2Ime(aObj: TWinControl): boolean;implementation{$R *.dfm}
function SetActivateIme(sWanted: string): boolean;
var iHandleCount: integer;
pList: array[1..nHKL_LIST] of HKL;
szImeFileName: array[0..MAX_PATH] of char;
sImeFileName: string;
bInstalled: boolean;
i: integer;
begin
Result := False;
sWanted := AnsiUpperCase(sWanted);
// 看看是否安裝了這個輸入法
bInstalled := False;
iHandleCount := GetKeyboardLayoutList(nHKL_LIST, pList);
for i := 1 to iHandleCount do
begin
ImmGetDescription(pList[I], szImeFileName, MAX_PATH);
sImeFileName := AnsiUpperCase(StrPas(szImeFileName));
if (pos(sWanted,sImeFileName)>0) or (sWanted = sImeFileName) then
begin // En 時, 其值為''
bInstalled := True;
Break;
end;
end;
// 如果這個輸入法已安裝了, 讓那個輸入法的鍵盤分佈(KeyLayout)作用
if bInstalled then
begin
ActivateKeyboardLayout(pList[i], 0);
if (sWanted = sImeFileName) then
Result := False
else
Result := True;
end;
end; { of SetActivateIme }{function SetKey2Ime(aObj: TWinControl): boolean;
begin
ImmSimulateHotKey(aObj.Handle, IME_THOTKEY_IME_NONIME_TOGGLE);
result:= True;
end;}
procedure TForm1.Button1Click(Sender: TObject);
begin
SetActivateIme('念青五笔'); //调用念青五笔
end;procedure TForm1.Button2Click(Sender: TObject);
begin
SetActivateIme('');
end;end.
2.窗体调用DLL: 应改为:unit Umain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
function SetActivateIme(sWanted: string): boolean;stdcall;external 'myimm.dll';//??DLL??????
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
SetActivateIme('念青五笔');
end;procedure TForm1.Button2Click(Sender: TObject);
begin
SetActivateIme('');//关闭输入法
end;end.
library Project2;
uses
sharemem,{加入了这个}Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,imm;
{$R *.res}
type
TimmData = array of string; {------------声明}
//获取所有输入发的数组
function getALLIME: tIMMDATA ; stdcall;
var
j: integer;
a:Timmdata;
Begin
SetLength(a,screen.Imes.Count);
for j:=0 to screen.Imes.Count-1 do
begin
a[j]:=screen.imes.strings[j];
end;
result:=a;
SetLength(a,0);
End;
//打开输入法的函数
function opencid(cidname: string):BOOLEAN;stdcall;
var
I: Integer;
mycid:hkl;
begin
I:=screen.Imes.Indexof(cidname);
mycid:=hkl(screen.Imes.Objects[i]);
activatekeyboardlayout(mycid, KLF_activate);
RESULT:=TRUE;
end;
//关闭中文输入法 (要用PROCEDURE)
//procedure closeimm; stdcall;
// var
// mycid:hkl;
// begin
// mycid:=getkeyboardlayout(0);
// if immISime(mycid) then
// immsimulateHotkey(handle,IME_CHotKey_IME_NonIME_Toggle);
// end; //导出函数接口
exports
getallime,opencid; begin
end.
dll部分:library Project2;{ 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
sharemem,{加入了这个}Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,imm; type
TimmData = array of string;
{$R *.res}
//获取所有输入发的数组
function getALLIME: tIMMDATA;stdcall;
var
j: integer;
a:Timmdata;
Begin
SetLength(a,screen.Imes.Count);
for j:=0 to screen.Imes.Count-1 do
begin
a[j]:=screen.imes.strings[j];
end;
result:=a;
SetLength(a,0);
End;
exports
getallime;
begin
end.调用:
程序体:program Project1;uses
sharemem,
Forms,
Umain in 'Umain.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
窗体中调用:unit Umain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;typeTimmData = array of string;
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
function getALLIME: tIMMDATA;stdcall;external 'Project2.dll';
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
a:TimmData;
i:integer;
begin
{---------------------将输入法列表添加到ListBox1中}
a:=getALLIME;
for i :=low(a) to High(a) do
ListBox1.Items.Add(a[i]);
end;
end.