全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1751
推到 Plurk!
推到 Facebook!

撰寫 DLL 的一些問題

尚未結案
JBLpower
一般會員


發表:17
回覆:6
積分:4
註冊:2003-04-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-03-25 14:58:01 IP:61.30.xxx.xxx 未訂閱
    ///  DLL 
library SfcsLib;    { 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,
  SysUtils,
  Classes,
  ActiveX,
  UntComFunc in 'UntComFunc.pas',
  UntWaitMsg in 'UntWaitMsg.pas' {frmWaitMsg},    exports
  DisConnectDB,
  ConnectDB,
  WaitMsg,
  LoadIni;    {$R *.res}    begin
  CoInitialize(nil);
end.    //// UntComFunc.Pas
unit UntComFunc;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, UntWaitMsg, IniFiles, ADODB ;    var    // Object
  ADOConnection1: TADOConnection;
  ADOQryOpen, ADOQryExec: TADOQuery;
  frmWaitMsg: TForm;
// varient
  gsLogoTime, gsLogoPicture, gsPicAutoSize, gsPicHeight, gsPicWidth,   // LOGO
  gsLoginTime, gsLoginPicture, gsLoginID, gsLoginPWD, gsLoginCount: String;
// procedure
  procedure LoadIni; export; stdcall;
  procedure DisConnectDB;export; stdcall;
  procedure ConnectDB;export; stdcall;
  procedure WaitMsg(bFlage: Boolean; sMsg, sTitle: String);export; stdcall;    implementation    procedure LoadIni;
var
  SFCSini: TIniFile;
begin
  frmWaitMsg:= TfrmWaitMsg.Create(Application);
  WaitMsg(True,'Load Config ...','SFCS Ini');
  SFCSini := TIniFile.Create(ExtractFilePath(Application.ExeName) 'SFCS.ini');
  With SFCSini do
  begin
     try
        // [LOGO]
        gsLogoTime := Trim(ReadString('LOGO','LogoTime','5'));                    // LOGO 停留時間 (Default: 10秒)
        gsLogoPicture := Trim(ReadString('LOGO','LogoPicture','Logo.jpg'));       // LOGO 圖片檔名 (Default: Logo.jpg)
        gsPicAutoSize := Trim(ReadString('LOGO','PicAutoSize','N'));              // LOGO 圖片大小 (Default: N)
        gsPicHeight := Trim(ReadString('LOGO','PicHeight','240'));                // LOGO 高       (Default: 240)
        gsPicWidth := Trim(ReadString('LOGO','PicWidth','320'));                  // LOGO 寬       (Default: 320)
           finally
        WaitMsg(False,'Load Config Complete.','SFCS Ini');
        Free;
     end;// try... finall      end;// with SFCSini    end;    procedure WaitMsg(bFlage: Boolean; sMsg, sTitle: String);
var
  Label1: TLabel;
  Animate1: TAnimate;
begin
 try
  label1:= TLabel.Create(frmWaitMsg);
  Animate1:= TAnimate.Create(frmWaitMsg);
  with frmWaitMsg do
  begin
    if bFlage then
    begin
      Label1.Caption:= sMsg;
      Caption:= sTitle;
      Show;
//      Refresh;
      Animate1.Active:= True;
    end
    else// if bFlage
    begin
      Hide;
      Animate1.Active:= False;
    end;// if bFlage
  end;// with frmWaitMsg
 finally
  label1.Free;
  Animate1.Free;
 end;
end;    procedure DisConnectDB;
begin
    ADOQryOpen.Close;
    ADOQryOpen.Free;
    ADOQryExec.Close;
    ADOQryExec.Free;
    ADOConnection1.Connected:= False;
    ADOConnection1.Destroy;
    ADOConnection1:= nil;
end;    procedure ConnectDB;
begin
  try
     try
       LoadIni;
       WaitMsg(True,'Connect ...','SFCS Ini');
       DisConnectDB;
       ADOConnection1:= TADOConnection.Create(Application);
       with ADOConnection1 do
       begin
         ConnectionString := 'Provider=SQLOLEDB.1;' 
                             'Password=sql2kadm;' 
                             'Persist Security Info=True;' 
                             'User ID=sa;' 
                             'Initial Catalog=' gsDatabaseName ';' 
                             'Data Source=' gsServerHost;
 //        LoginPrompt:=False;
//         Mode:= cmReadWrite;
         Connected:= True;
       end;
     finally
       WaitMsg(False,'Connect ...','SFCS Ini');
     end;// try... finally
  except
     on E:Exception do
        ShowMessage('連接資料庫失敗!'#13'錯誤原因:'#13 E.Message); // CHECK 看是什麼錯誤原因.
  end;// try... except    end;
end.    ///  UntWaitMsg.pas
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, DB, ADODB;    type
  TfrmWaitMsg = class(TForm)
    Animate1: TAnimate;
    Label1: TLabel;
    ADOConnection1: TADOConnection;
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  frmWaitMsg: TfrmWaitMsg;    implementation    {$R *.dfm}    end.    ///////  Call DLL prject    unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;    type
  TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    procedure ConnectDB; stdcall; external 'SfcsLib.dll';
procedure DisConnectDB; stdcall; external 'SfcsLib.dll';
procedure LoadIni; stdcall; external 'SfcsLib.dll';    implementation    {$R *.dfm}    procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled:=true;
  ConnectDB;
end;    procedure TForm1.Timer1Timer(Sender: TObject);
begin
  DisConnectDB;
  Timer1.Enabled:=False;
end;    procedure TForm1.Button2Click(Sender: TObject);
begin
  LoadIni;
end;
end.
JBLpower
一般會員


發表:17
回覆:6
積分:4
註冊:2003-04-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-03-25 15:16:38 IP:61.30.xxx.xxx 未訂閱
Sorry 忘記描述問題 1.因為第一次嘗試寫 DLL 所以有些觀念並不是很清楚,所以產生了一些問題,煩請各位大大解答、以匡正自身觀念。 2.以上 Code 在呼叫 時產生了如下畫面的問題(無法上傳用打字低)。 msg1: 'Exception EInvalidOperation in module SfcsLib.dll at 000569E4' msg2: 'RunTime error 216 at 5c003A00' 3.請問有何方式可以在 RunTime mode 下 可以像 寫Function 一樣 單步執行呢?
wyndog
資深會員


發表:7
回覆:362
積分:348
註冊:2004-10-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-03-25 15:29:35 IP:60.248.xxx.xxx 未訂閱
DLL 除錯,是有單步啦... 不過是組語的.... 我都是在 DLL 裡面插旗子,就是插個 ShowMessage 來顯示適當訊息,讓我大致推斷問題在哪
zhengdelphi
一般會員


發表:4
回覆:5
積分:1
註冊:2005-03-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-03-26 12:40:01 IP:219.128.xxx.xxx 未訂閱
可以单步,在run|parameters中设定宿主,就可以单步执行了
系統時間:2024-06-24 20:25:32
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!