求大牛给我写个DLL (急求!!!)

a461467123 2013-04-14 11:27:18
急求一个DLL,DLL里面连表 delphi自带的DB。
读取一张表里的数据。然后返回结果集, 给别的程序调用。

大牛,大虾救我,急求代码!!

或者有别的返回表的内容的方法,也求大牛教我。


...全文
197 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
OO_is_just_P 2013-04-16
  • 打赏
  • 举报
回复
楼上漂亮
simonhehe 2013-04-15
  • 打赏
  • 举报
回复
以下代码Delphi XE 下测试通过 其中的test.db表, 含有id, name字段 test.dll
library test;

{ 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
  SysUtils,
  Classes,
  DB,
  DBTables;

{$R *.res}
function GetTable(ADBPath, ATBName : PChar) : TTable;
begin
  Result := nil;
  try
    Result := TTable.Create(nil);
    Result.DatabaseName := StrPas(ADBPath);
    result.TableName := StrPas(ATBName);
    result.open;
  except on E: Exception do
    raise Exception.Create('数据提取错误:' + e.message);
  end;
end;

exports
  GetTable;

begin
end.
调用方法(下边的代码中, table在dll销毁前也做了销毁, 如果你要在程序的其它部分使用该table, 最好使用dll的静态调用, 或者对dll的释放时机做出调整)
uses DBTables;
{$R *.dfm}

procedure TForm15.btn1Click(Sender: TObject);
type
  TFun = function (ADBPath, ATBName : PChar) : TTable;
var
  aFun : TFun;
  aHandle : thandle;
  aTable : ttable;
begin
  aHandle := LoadLibrary(PChar('test.dll'));
  try
    if aHandle <> 0 then
    begin
      aFun := GetProcAddress(aHandle, 'GetTable');
      try
        aTable := aFun(PChar(ExtractFilePath(Application.ExeName)), PChar('test.db'));
        if aTable <> nil then
        begin
          aTable.First;
          ShowMessage(aTable.FieldByName('id').AsString);

        end;
      except on E: Exception do
        ShowMessage(e.Message);
      end;
    end;
  finally
    if aTable <> nil then
      aTable.free;
    FreeLibrary(aHandle);
  end;
end;
a461467123 2013-04-14
  • 打赏
  • 举报
回复
晕死,这个问题就有这么难......无语了
sololie 2013-04-14
  • 打赏
  • 举报
回复
消灭0回复,撸过围观
经常使用电脑可能也遇到过了! 突然‘咚’的一声 提示 内存不能为read 这个问题我以前也遇到过不知道怎么解决 现在终于有办法了!呵呵! 我们就看看是什么原因引起的吧,另外附送一个小工具修复见下面附件 总结下大概以下9个原因 1、驱动不稳定,与系统不兼容,这最容易出现内存不能为 Read 或者文件保护(主要原因) 2、系统安装了一个或者多个流氓软件,这出现 IE 或者系统崩溃的机会也比较大,也有可能出现文件保护 3、系统加载的程序或者系统正在运行的程序之前有冲突,尤其是部分杀毒软件监控程序 4、系统本身存在漏洞,导致容易受到网络攻击。 5、病毒问题也是主要导致内存不能为 Read、文件保护、Explorer.exe 错误…… 6、如果在玩游戏时候出现内存不能为 Read,则很大可能是显卡驱动不适合(这里的不适合有不适合该游戏、不适合电脑的显卡)也有可能是 系统版本不够新或者不符合该游戏、显卡驱动 7、部分软件本身自身不足的问题 8、电脑硬件过热,也是导致内存不能为 Read 的原因之一。 9、电脑内存与主板兼容性不好也是导致内存不能为 Read 的致命原因! 以上大概就是目前可以引起系统提示 内存不能为read的原因了 另外软件是针对只是针对部分原因引起的内存不为read所做修复,不是100%有效,大家可以试试看 说下原理: 就是批处理使用 regsvr32命令 将动态链接库文件重新注册 (system32下的所有 .dll 和 .ocx 文件;) 注意:由于修复工具会重新注册 system32下的所有 .dll 和 .ocx 文件 此操作对杀毒软件来说属于敏感操作,所以建议使用修复工具的时候,请禁用杀毒软件,以免部分杀毒误报!jie

16,747

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧