線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1067
推到 Plurk!
推到 Facebook!

初學 DLL,語法錯誤,不會改...><::

答題得分者是:Rain
littlefactor
一般會員


發表:24
回覆:25
積分:9
註冊:2002-07-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-07 18:16:26 IP:61.56.xxx.xxx 未訂閱
各位高手大家好: 現在試著在寫DLL,就想說把信用卡檢核的function寫成DLL 我想做到呼叫DLL的一個function,然後這個function會去呼叫其他function(同樣都在DLL裡),我看書的DLL範例以及網站上的範例都沒這種function中再呼叫其他function,我知道語法錯了,見笑了,還真的不知道如何改.. 高手們可以指點迷津一下嗎?    
 
library chk_function;    uses
  SysUtils,
  Classes;    {$R *.res}    function Check_Credit_Card(const p_crd_cd:string;const p_type:char):boolean; export;
begin
   if  Check_Card_No(p_crd_cd,Get_Card_Cd(p_type)) = false then
       Check_Credit_Card := False
   else
       Check_Credit_Card := True;
end;    function Get_Card_Cd(const p_crd_nm : string):char ;
begin
  if p_crd_nm = '聯合信用卡' then Result := 'U';
  if p_crd_nm = 'AMEX' then Result := 'A';
  if p_crd_nm = 'MASTER' then Result := 'M';
  if p_crd_nm = 'VISA' then Result := 'V';
  if p_crd_nm = 'JCB' then Result := 'J';
  if p_crd_nm = 'DINER' then Result := 'D';
  if p_crd_nm = '' then Result := ' ';
end ;        function Check_Card_No(const p_crd_cd:string;const p_type:char):boolean;
begin
  case p_type of
   'U':result:=union(p_crd_cd);
   'A':result:=AMEX(p_crd_cd);
   'M':result:=VISA(p_crd_cd);
   'V':result:=VISA(p_crd_cd);
   'J':result:=VISA(p_crd_cd);
   'D':result:=DINER(p_crd_cd);
  else
   result:=false;
  end;
end;        function VISA(const p_crd_cd : string):boolean;
var
iCount,product : integer ;
begin
 Result := true ;
 if length(p_crd_cd)= 16 then
 begin
   product :=0;
   for icount := 1 to 15 do
   begin
      If Icount mod 2 = 0 then
        product := product   strtoint(copy(p_crd_cd,icount,1))
      else
        product := product   ((strtoint(copy(p_crd_cd,Icount,1))*2) div 10)   ((strtoint(copy(p_crd_cd,Icount,1))*2) mod 10);
   end ;
   if strtoint(copy(p_crd_cd,16,1)) <> ((10 - (product mod 10)) mod 10 ) then
     result := false ;
 end
 else
   result := false ;
end;        function AMEX(const p_crd_cd : string):boolean;
var
iCount,product : integer ;
begin
 Result := true ;
 if ((copy(p_crd_cd,1,2)='34') or (copy(p_crd_cd,1,2)= '37')) and (length(p_crd_cd)= 15)then
 begin
   product :=0;
   for icount := 1 to 15 do
   begin
      If icount mod 2 <> 0 then
        product := product   strtoint(copy(p_crd_cd,icount,1))
      else
        product := product   ((strtoint(copy(p_crd_cd,icount,1))*2) div 10)   ((strtoint(copy(p_crd_cd,icount,1))*2) mod 10);
   end ;
   if product mod 10 <> 0 then
     result := false ;
 end
 else result := false;
end;        function DINER(const p_crd_cd : string) : boolean;
begin
   if copy(p_crd_cd,1,2)<> '36' then
   result := false
   else
   begin
      if length(p_crd_cd)<>14 then
         result := false
      else
         result := true;
   end;    end;        function Union(const p_crd_cd :string):boolean;
var Lst_digit,product,product_wt: integer;
begin
 Result := true ;
 if length(p_crd_cd)= 11 then
 begin
  product:= (strtoint(copy(p_crd_cd,1,1))*7) 
            (strtoint(copy(p_crd_cd,2,1))*3) 
            (strtoint(copy(p_crd_cd,3,1))*5) 
            (strtoint(copy(p_crd_cd,4,1))*6) 
            (strtoint(copy(p_crd_cd,5,1))*7) 
            (strtoint(copy(p_crd_cd,6,1))*9) 
            (strtoint(copy(p_crd_cd,7,1))*8) 
            (strtoint(copy(p_crd_cd,8,1))*5) 
            (strtoint(copy(p_crd_cd,9,1))*9) 
            (strtoint(copy(p_crd_cd,10,1))*7);          product_wt:= ( (product DIV 100) * 5 )   ( ((product MOD 100) DIV 10 )* 9 )   ( (product MOD 10) * 7 ) ;
      Lst_digit:=strtoint( copy(p_crd_cd,11,1));
      if Lst_digit= (10 - ( ((product_wt MOD 10)   3) MOD 10 )) mod 10 then
        result:=true
      else
        result:=false;
 end
 else
   result:=false;
end;    exports
Check_Credit_Card;    begin
end.
發表人 - littlefactor 於 2003/04/07 18:18:30
Rain
資深會員


發表:31
回覆:236
積分:268
註冊:2003-02-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-07 19:59:55 IP:218.5.xxx.xxx 未訂閱
/ 我想做到呼叫DLL的一個function,然後這個function會去呼叫其他function(同樣都在DLL裡),我看書的DLL範例以及網站上的範例都沒這種function中再呼叫其他function / 這樣子沒什麼不可以,沒有任何問題的,只是你的程式中把 Check_Credit_Card函數放在最前邊,又去調用後面的函數,當然 會出錯,你要把Check_Card_No這個函數放在Check_Credit_Card函數的前邊才可以調用,象下面這樣就可以了,其他的函數也同樣。 function Check_Card_No(const p_crd_cd:string;const p_type:char):boolean; begin … end; function Check_Credit_Card(const p_crd_cd:string;const p_type:char):boolean; export; begin Check_Card_No…; end; Once and only once
littlefactor
一般會員


發表:24
回覆:25
積分:9
註冊:2002-07-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-08 11:15:38 IP:61.56.xxx.xxx 未訂閱
引言: 要把Check_Card_No這個函數放在Check_Credit_Card函數的前邊才可以調用,其他的函數也同樣。
沒錯,調動後就可以了,非常謝謝Rain先生的回答~
系統時間:2024-05-12 23:21:27
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!