我做了一个Dll里面只发布一个涵数;
//************************
在dll中是这样定义的(里面封装了窗体):
...................
library Project1;uses
Unit1 in 'Unit1.pas';
exports
dddd;
begin
end.
//涵数定义如下
function ddd( filename:Pchar;field_index:integer):Pchar;
var
input_form:Tinput_code_form;
begin
input_form:=Tinput_code_form.CreateForm(filename,field_index);
with input_form do
begin
if ShowModal = mrok then result:=Pchar(input_form.label1.Caption)
else result:='';
end;
end;//***********************************************
我用程序调用;
.......
implementation
function dddd(filename:pchar;field_index:integer):Pchar;stdcall;external'Project1.dll';//功能是返回一个人的姓名;
{$R *.dfm}
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=VK_F9 then
showmessage(dddd(pchar('C:\sy\person_id.CTD'),0));
end;
程序能够正常运行;
但是会出现一个奇怪的现象;
当返回的姓名是三个字的是侯就回出现如:原来是"杨伧林"会显示为
"杨伧 ",好象是被截断了半个字符,但是有时侯又能正常显示"杨伧林"
真不知道是什么原因?请给解释一下?
//************************
在dll中是这样定义的(里面封装了窗体):
...................
library Project1;uses
Unit1 in 'Unit1.pas';
exports
dddd;
begin
end.
//涵数定义如下
function ddd( filename:Pchar;field_index:integer):Pchar;
var
input_form:Tinput_code_form;
begin
input_form:=Tinput_code_form.CreateForm(filename,field_index);
with input_form do
begin
if ShowModal = mrok then result:=Pchar(input_form.label1.Caption)
else result:='';
end;
end;//***********************************************
我用程序调用;
.......
implementation
function dddd(filename:pchar;field_index:integer):Pchar;stdcall;external'Project1.dll';//功能是返回一个人的姓名;
{$R *.dfm}
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=VK_F9 then
showmessage(dddd(pchar('C:\sy\person_id.CTD'),0));
end;
程序能够正常运行;
但是会出现一个奇怪的现象;
当返回的姓名是三个字的是侯就回出现如:原来是"杨伧林"会显示为
"杨伧 ",好象是被截断了半个字符,但是有时侯又能正常显示"杨伧林"
真不知道是什么原因?请给解释一下?
解决方案 »
- access修改相同字段数据问题
- 急,一个弄不明白的小问题(access),搞定马上结贴,在线等ing
- 酷难!!我现在实现了能拖放文件到listview,并且当拖放完成时,能获取当前鼠标下的item,可问题是当鼠标拖拽着文件浮动于listview上时,我
- 预警系统
- 急,delphi7出错了,不能调试了..
- DELPHI与ORACLE9I中的BLOB字段存取的问题
- 一行代码实现无标题窗体移动!!!!!
- 字符串处理
- 我想在网页上显示图表,象CHART控件那样,用DELPHI可以实现吗?请大侠们指点!
- 如何把我的屏幕发送到别人的机器上??答好了另开贴加分
- 一个ADSL.一个4口PT—LINK,四台电脑,如何组内网!!
- 创建一个dll窗体加入了vcl skin 皮肤控件,在主程序调用时无效,该怎样解决?!?
function ddd( filename:Pchar;field_index:integer):Pchar; stdcall;
我不想用string;因为string只能用在delphi编的程序中;
请问budded
导出:
function ddd( filename:Pchar;field_index:integer):Pchar; stdcall;
是什么意思?不明白
我想知道的是为什么pchar就不行?
能具体一点吗?
var
input_form:Tinput_code_form;
temp:pchar;
begin
input_form:=Tinput_code_form.CreateForm(filename,field_index);
with input_form do
begin
if ShowModal = mrok then result:=Pchar(input_form.label1.Caption)
else result:= ' ';
end;
//temp := result ;
temp := SysAllocMem( result 的长度+1 );
复制result的内容到temp;
result:=temp;
end;
因为input_form.label1.Caption中显示的字符是正常的.只是返回到调用程序时才不能正常显示;
问题在于:没有释放form窗体把涵数改为:
function ddd( filename:Pchar;field_index:integer):Pchar;
var
input_form:Tinput_code_form;
begin
input_form:=Tinput_code_form.CreateForm(filename,field_index);
try
with input_form do
begin
if ShowModal = mrok then result:=Pchar(input_form.label1.Caption)
else result:= ' ';
end;
finally
input_form.free;//或是freeandnil(input_form);
end;
end; 可我还是弄不明白.照我的理解:showmodal=mrok就回释放form为什么还要free呢?
你返回了一个指针,这个指到一个局部变量,函数返回的时候这个局部变量已经无效.你说你返回的这个指针有意义么?
我写的方法就是在堆上分配一段内存,只要不释放一直是有效的返回string是因为string是一个对象,delphi会保证返回的string对象是有效的.