我调用DLL里面的数据后,返回主程序的全是一样的数据,请问是我哪里写错了。我把代码贴出来.
DLl:
type
TArr=array[0..2] of ShortString;
PTArr=^TArr;function getspecial(a:PTArr):ShortString;StdCall;
var
ADOQ:TADOQuery;
FileName:String;
begin
CoInitialize(nil);
FileName:=ExtractFilePath(ParamStr(0))+'bin\MDB\Assistant.mdb';
ADOQ:=TADOQuery.Create(nil);
try
with ADOQ do
begin
Close;
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+FileName+ ';Persist Security Info=False';
CursorType:=ctKeyset;
SQL.Clear;
SQL.Text:='select Top 1 * from memo1 where memodate>=date() and memotype ='''+'0'+''' order by memotime asc';///按照升序法筛选出第一条记录
Open;
end;
if ADOQ.RecordCount>0 then
begin
a^[0]:=TimetoStr(ADOQ.Fields[3].Value);
a^[1]:=DatetoStr(ADOQ.Fields[2].Value);
a^[2]:=ADOQ.Fields[1].Value;
end;
ADOQ.Close;
ADOQ.Free;
except
on E:Exception do
begin
showmessage(e.Message);
end;
end;
CoUnInitialize;
end;function geteveryday(b:PTArr):ShortString;StdCall;
var
ADOQ:TADOQuery;
FileName:String;
begin
CoInitialize(nil);
FileName:=ExtractFilePath(ParamStr(0))+'bin\MDB\Assistant.mdb';
ADOQ:=TADOQuery.Create(nil);
try
with ADOQ do
begin
Close;
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+FileName+ ';Persist Security Info=False';
CursorType:=ctKeyset;
SQL.Clear;
SQL.Text:='select Top 1 * from memo1 where memotime>=now() and memotype ='''+'1'+''' order by memotime asc';///按照升序法筛选出第一条记录
Open;
end;
if ADOQ.RecordCount>0 then
begin
b^[1]:=TimetoStr(ADOQ.Fields[3].Value);
b^[2]:=ADOQ.Fields[1].Value;
end;
ADOQ.Close;
ADOQ.Free;
except
on E:Exception do
begin
showmessage(e.Message);
end;
end;
CoUnInitialize;
end;
主程序:
procedure getspecial;
type
TArr=array[0..2] of ShortString;
PTArr=^TArr;
Tgetspecial=Function(a:PTArr):ShortString;stdcall;
var
a:TArr;
HGDS:THandle;
FPointers:TFarProc;
MyFuncts:Tgetspecial;
begin
HGDS:=LoadLibrary('memo_gettask.dll');
if HGDS > 32 then
try
FPointers:=GetProcAddress(HGDS,'getspecial');
MyFuncts:=Tgetspecial(FPointers);
MyFuncts(@a);
if FPointers <> nil then
begin
alspecial[0]:=a[0];
alspecial[1]:=a[1];
alspecial[2]:=a[2];
end;
finally
FreeLibrary(HGDS);
end;
end;procedure geteveryday;
type
TArr=array[0..2] of ShortString;
PTArr=^TArr;
Tgeteveryday=Function(a:PTArr):ShortString;stdcall;
var
b:TArr;
HGDD:THandle;
FPointerd:TFarProc;
MyFunctd:Tgeteveryday;
begin
HGDD:=LoadLibrary('memo_gettask.dll');
if HGDD > 32 then
try
FPointerd:=GetProcAddress(HGDD,'geteveryday');
MyFunctd:=Tgeteveryday(FPointerd);
MyFunctd(@b);
if FPointerd <> nil then
begin
aleveryday[0]:=b[0];
aleveryday[1]:=b[1];
end;
finally
FreeLibrary(HGDD);
end;
end;我用showmessage函数显示alspecial[2]和aleveryday[1]的时候,显示出来的都是第一条数据的数据,我开始以为是sql语句的问题,但是修改了以后也不对,请大家帮帮忙。
DLl:
type
TArr=array[0..2] of ShortString;
PTArr=^TArr;function getspecial(a:PTArr):ShortString;StdCall;
var
ADOQ:TADOQuery;
FileName:String;
begin
CoInitialize(nil);
FileName:=ExtractFilePath(ParamStr(0))+'bin\MDB\Assistant.mdb';
ADOQ:=TADOQuery.Create(nil);
try
with ADOQ do
begin
Close;
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+FileName+ ';Persist Security Info=False';
CursorType:=ctKeyset;
SQL.Clear;
SQL.Text:='select Top 1 * from memo1 where memodate>=date() and memotype ='''+'0'+''' order by memotime asc';///按照升序法筛选出第一条记录
Open;
end;
if ADOQ.RecordCount>0 then
begin
a^[0]:=TimetoStr(ADOQ.Fields[3].Value);
a^[1]:=DatetoStr(ADOQ.Fields[2].Value);
a^[2]:=ADOQ.Fields[1].Value;
end;
ADOQ.Close;
ADOQ.Free;
except
on E:Exception do
begin
showmessage(e.Message);
end;
end;
CoUnInitialize;
end;function geteveryday(b:PTArr):ShortString;StdCall;
var
ADOQ:TADOQuery;
FileName:String;
begin
CoInitialize(nil);
FileName:=ExtractFilePath(ParamStr(0))+'bin\MDB\Assistant.mdb';
ADOQ:=TADOQuery.Create(nil);
try
with ADOQ do
begin
Close;
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+FileName+ ';Persist Security Info=False';
CursorType:=ctKeyset;
SQL.Clear;
SQL.Text:='select Top 1 * from memo1 where memotime>=now() and memotype ='''+'1'+''' order by memotime asc';///按照升序法筛选出第一条记录
Open;
end;
if ADOQ.RecordCount>0 then
begin
b^[1]:=TimetoStr(ADOQ.Fields[3].Value);
b^[2]:=ADOQ.Fields[1].Value;
end;
ADOQ.Close;
ADOQ.Free;
except
on E:Exception do
begin
showmessage(e.Message);
end;
end;
CoUnInitialize;
end;
主程序:
procedure getspecial;
type
TArr=array[0..2] of ShortString;
PTArr=^TArr;
Tgetspecial=Function(a:PTArr):ShortString;stdcall;
var
a:TArr;
HGDS:THandle;
FPointers:TFarProc;
MyFuncts:Tgetspecial;
begin
HGDS:=LoadLibrary('memo_gettask.dll');
if HGDS > 32 then
try
FPointers:=GetProcAddress(HGDS,'getspecial');
MyFuncts:=Tgetspecial(FPointers);
MyFuncts(@a);
if FPointers <> nil then
begin
alspecial[0]:=a[0];
alspecial[1]:=a[1];
alspecial[2]:=a[2];
end;
finally
FreeLibrary(HGDS);
end;
end;procedure geteveryday;
type
TArr=array[0..2] of ShortString;
PTArr=^TArr;
Tgeteveryday=Function(a:PTArr):ShortString;stdcall;
var
b:TArr;
HGDD:THandle;
FPointerd:TFarProc;
MyFunctd:Tgeteveryday;
begin
HGDD:=LoadLibrary('memo_gettask.dll');
if HGDD > 32 then
try
FPointerd:=GetProcAddress(HGDD,'geteveryday');
MyFunctd:=Tgeteveryday(FPointerd);
MyFunctd(@b);
if FPointerd <> nil then
begin
aleveryday[0]:=b[0];
aleveryday[1]:=b[1];
end;
finally
FreeLibrary(HGDD);
end;
end;我用showmessage函数显示alspecial[2]和aleveryday[1]的时候,显示出来的都是第一条数据的数据,我开始以为是sql语句的问题,但是修改了以后也不对,请大家帮帮忙。
不要用 TString , 用PChar