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

請問可以使用variant改寫ISBN讓procedure可以回傳

缺席
sky810675
一般會員


發表:5
回覆:23
積分:5
註冊:2006-07-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-07-21 03:23:04 IP:218.170.xxx.xxx 訂閱


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, SHDocVw ,mshtml, Grids ;
{
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, SHDocVw, StdCtrls,mshtml, Grids,shellapi;
}
Type
TBookRec = record
ID : string ; //001 記錄識別欄
ISBN : string ; //010 國際標準書號 a 編號
bind : string ; // b 裝訂
price : string ; // c 價格
ISSN : string ; //011 國際標準叢刊號(ISSN)
Na_country : String ; //020 國家書目號 cw 表台灣
Na_id : string ; // b 號碼
org_id : string ; //050 國立中央圖書館卡片號碼 a
pub_Year : string ; //100 一般性資料 ,出版年(10-13)
is_Source : string ;//101 作品語文 , 0 原文或譯
language : string ; // a 語言
country: string ; //102 出版國別
name: string ; //200 題名及著者敘述項 a書名
name2: string ; //200 題名及著者敘述項 e 副題名及其他題名資料
author : string ; // f作者
author2 : string ; // f作者
paper : string ; // p卷數
volume : string ; // v 冊次號
version : string ; // 205 版本
pub_place : string ; //210 出版項 a 出版地
pub_name: string ; // b 出版者
pub_date : string ; // d 出版日期
is_chi : string ; //215 稽核項 0:中文
page_num : string ; // a 面數,冊數
pic : string ; // b 插圖
size : string ; //d 尺寸
att : string ; //e 附件
kind_id : string ; //681 中國圖書館分類號 (CCL) a 分類號
kind_num : string ; // b 書號
kind_v : string ; // v 版本
belong : String ; // 454 譯自
end ;

type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
EditISBN: TEdit;
Label2: TLabel;
Memo1: TMemo;
grid: TStringGrid;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
waitinput : boolean ;
public
{ Public declarations }
procedure InputISBN(isbn: string ) ;
end;

function IsISBN(ISBN: String): Boolean;
function ISBN_only_num(isbn: String ) : String ;
function Marc_data(marc : TStrings): TBookRec ;
function split( split_str : string ; line_str : string ) : TStrings ;
//function Marc_find(key : string ; list : TStringList) : string ;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

begin


//if IsISBN(EditISBN.text) then begin
waitinput:=true;
InputISBN(EditISBN.text);
//end
//else
// showmessage('ISBN編碼不正確!') ;

end;

procedure TForm1.InputISBN(isbn: string ) ;
var

doc:IHTMLDocument2;

link_url : string ;
isbn_n : string ;

begin

isbn_n := ISBN_only_num(isbn) ;
link_url:='http://nbinet.ncl.edu.tw/search*chi/i' isbn '/i' isbn_n '/1,0,0,B/marc&FF=i' isbn_n '&1,,' ;
edit1.text := link_url ;
waitinput := true ;
webbrowser1.Navigate(link_url);

while waitinput do
application.ProcessMessages;


//取得內容
doc:=webbrowser1.Document as IHTMLDocument2;

memo1.Clear ;
memo1.Lines.add(doc.Body.OuterText) ;
//Marc_data( TStrings(doc.Body.OuterText) ) ;
Marc_data( memo1.Lines ) ;


end ;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin

waitinput:=false;

end;

function ISBN_only_num(isbn: String ) : String ;
//把 isbn 中間的-號去掉
var
isbn_n : string ;
i : integer ;
begin
for i := 1 to length(ISBN) do begin
if (ISBN[i]<>'-') then
isbn_n := isbn_n isbn[i] ;
end ;
Result := isbn_n ;
end ;

function IsISBN(ISBN: String): Boolean;
//是否為正確的 isbn 編號
var
Number, CheckDigit: String;
CheckValue, CheckSum, Err: Integer;
i, Cnt: Word;
begin
{Get check digit}
CheckDigit := Copy(ISBN, Length(ISBN), 1);
{Get rest of ISBN, minus check digit and its hyphen}
Number := Copy(ISBN, 1, Length(ISBN) - 2);
{Length of ISBN remainder must be 11 and check digit between 9 and 9 or X}
if (Length(Number) = 11) and (Pos(CheckDigit, '0123456789X') > 0) then begin
{Get numeric value for check digit}
if (CheckDigit = 'X') then
CheckSum := 10
else
Val(CheckDigit, CheckSum, Err);
{Iterate through ISBN remainder, applying decode algorithm}
Cnt := 1;
for i := 1 to 12 do begin
{Act only if current character is between "0" and "9" to exclude hyphens}
if (Pos(Number[i], '0123456789') > 0) then begin
Val(Number[i], CheckValue, Err);
{Algorithm for each character in ISBN remainder, Cnt is the nth character so processed}
CheckSum := CheckSum CheckValue * (11 - Cnt);
Inc(Cnt);
end;
end;
{Verify final value is evenly divisible by 11}
if (CheckSum MOD 11 = 0) then
IsISBN := True
else
IsISBN := False;
end
else
IsISBN := False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
grid.Cells[0,0] := 'isbn';
grid.Cells[1,0] := '書名';
grid.Cells[2,0] := '作者';
grid.Cells[3,0] := '版次';
grid.Cells[4,0] := '出版地';
grid.Cells[5,0] := '出版社';
grid.Cells[6,0] := '出版年';
grid.Cells[7,0] := '譯自書名';
grid.Cells[8,0] := '頁樣式';
grid.Cells[9,0] := '包裝';
grid.Cells[10,0] := '副題';
grid.Cells[11,0] := '分類號';
grid.Cells[12,0] := '年份';
grid.Cells[13,0] := '年度書序';
grid.Cells[14,0] := '價格';
grid.Cells[15,0] := '語言';

end;

function Marc_data(marc : TStrings ): TBookRec ;
var
i : integer ;
line : string ;
len : integer ;
book : TBookRec ;
mid : integer ;
pid,dd : string ;
ddSplit : TStrings ;
fi : integer ;
begin
ddSplit := TStringList.Create;
for fi := 0 to Form1.grid.ColCount -1 do
Form1.grid.Cells[fi,1] := '';
for i := 0 to marc.Count do begin
line := Trim(marc.Strings[i]) ;
len := Length(line) ;
if len >0 then begin
ddSplit.Clear ;
try
mid := StrToInt(Copy(line,1,3)) ; //前三碼
except
on EConvertError do mid :=0 ;
end ;
pid := Copy(line,5,1) ;
dd := Copy(line,8,len-7) ;
ddSplit := split('|' , dd) ;

with Book do begin
case mid of
001: //記錄識別欄
ID := dd ;
010,011: begin //國際標準書號(ISBN) ISSN
ISBN := ddSplit[0];
//showmessage(ISBN) ;
Form1.grid.Cells[0,1] := ISBN;

for fi := 1 to ddSplit.Count -1 do begin
if copy(ddSplit.strings[fi],1,1)= 'b' then begin
bind := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
Form1.grid.Cells[9,1] := bind ;
end ;
if copy(ddSplit.strings[fi],1,1)= 'd' then begin
price := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
Form1.grid.Cells[14,1] := price ;
end ;
end ; //for

end ; //011
020: begin //020 國家書目號 cw 表台灣
Na_country := ddSplit[0];
for fi := 1 to ddSplit.Count -1 do begin
if copy(ddSplit.strings[fi],1,1)= 'b' then begin
Na_id := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
end ;
end ;
end ;
050: begin //050 國立中央圖書館卡片號碼 a
org_id := ddSplit[0];
end ;
100: begin //100 一般性資料 ,出版年(10-13)
pub_Year := copy(ddSplit[0],10,4) ;
form1.grid.Cells[6,1] := pub_Year ;
end ;
101: begin //101 作品語文 , 0 原文或譯
is_Source := pid ;
language := ddSplit[0];
form1.grid.Cells[15,1] := language ;
end ;
102: begin //102 出版國別
country := ddSplit[0];
end ;
200: begin //200 題名及著者敘述項 [必備欄]
name := name ddSplit[0]; //書名
form1.grid.Cells[1,1] := name ;
for fi := 1 to ddSplit.Count -1 do begin
if copy(ddSplit.strings[fi],1,1)= 'e' then begin //副書名
name2 := name2 copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ',';
form1.grid.Cells[10,1] := name2 ;
end ;
if copy(ddSplit.strings[fi],1,1)= 'f' then begin //作者
author := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
form1.grid.Cells[2,1] := author ;
end ;
if copy(ddSplit.strings[fi],1,1)= 'g' then begin //譯者
author2 := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
//form1.grid.Cells[2,1] := author2 ;
end ;
if copy(ddSplit.strings[fi],1,1)= 'p' then begin //卷數
paper := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
end ;
if copy(ddSplit.strings[fi],1,1)= 'v' then begin //冊次號
volume := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
end ;
end ;
end ;
205: begin //205 版本
version := ddSplit[0];
form1.grid.Cells[3,1] := version ;
end ;
210: begin //210 出版項 a 出版地
pub_place := ddSplit[0]; //出版地
form1.grid.Cells[4,1] := pub_place;
for fi := 1 to ddSplit.Count -1 do begin
if copy(ddSplit.strings[fi],1,1)= 'c' then begin //出版者
pub_name := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
form1.grid.Cells[5,1] := pub_name;
end ;
if copy(ddSplit.strings[fi],1,1)= 'd' then begin //出版日
pub_date := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
form1.grid.Cells[6,1] := pub_date;
end ;

end ;
end ;
215: begin //稽核項
is_chi := pid ;
page_num := ddSplit[0]; //頁
form1.grid.Cells[8,1] := page_num;
for fi := 1 to ddSplit.Count -1 do begin
if copy(ddSplit.strings[fi],1,1)= 'b' then begin //圖樣
pic := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
//form1.grid.Cells[5,1] := pub_name;
end ;
if copy(ddSplit.strings[fi],1,1)= 'd' then begin // 尺寸
size := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
//form1.grid.Cells[6,1] := pub_date;
end ;
if copy(ddSplit.strings[fi],1,1)= 'e' then begin // 附件
att := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
//form1.grid.Cells[6,1] := pub_date;
end ;
end ;
end ;
454: begin //譯自

belong := ddSplit[0]; //譯自

for fi := 1 to ddSplit.Count -1 do begin
if copy(ddSplit.strings[fi],1,1)= 'a' then begin //圖樣
belong := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
//form1.grid.Cells[5,1] := pub_name;
end ;
end ;
form1.grid.Cells[7,1] := belong;
end ;
681: begin //681 中國圖書館分類號 (CCL)

kind_id := ddSplit[0]; //分類號
form1.grid.Cells[11,1] := kind_id;
for fi := 1 to ddSplit.Count -1 do begin
if copy(ddSplit.strings[fi],1,1)= 'b' then begin //
kind_num := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
form1.grid.Cells[13,1] := kind_num;
end ;
if copy(ddSplit.strings[fi],1,1)= 'v' then begin // 尺寸
kind_v := copy(ddSplit[fi], 2 , length(ddSplit[fi])-1) ;
//form1.grid.Cells[6,1] := pub_date;
end ;
end ;
end ;
end; // case
end ; //with
end ; //if

end ;
ddSplit.Free ;
Result := book ;
end ;

{
function Marc_find(key : string ; mlist : TStringList) : string ;
var
i : integer ;
ans : string ;
find_fg : Boolean ;
begin
i:=0 ;
find_fg := False ;
while (not find_fg ) and (i < mlist.Count) do begin
if copy(mlist.strings[i],1,1) = key then begin
ans := copy(mlist.strings[i], 2 , length(mlist.strings[i])-1) ;
find_fg := true ;
end;
i := i 1 ;
end ;
Result := ans ;
end ;
}

function split(split_str : string ; line_str : string ) : TStrings ;
//字串分割 分割用字元 , 原始字串,
var
posi : integer ;
str : TStringList ;
l_str : string ;
begin
str := TStringList.Create;
posi := pos(split_str, line_str) ;

while (posi > 0) do begin
l_str := copy(line_str,1, posi-1) ;
str.Add(l_str) ;
line_str := copy (line_str , posi 1, length(line_str) - posi) ;
posi := pos(split_str, line_str) ;
end ; //while
str.Add(line_str) ;

Result := str ;

end ;

end.

sky810675
一般會員


發表:5
回覆:23
積分:5
註冊:2006-07-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2006-07-25 17:45:09 IP:218.170.xxx.xxx 訂閱
請問大大有人能解釋一下上面程式碼是寫什麼的嗎~
系統時間:2024-05-15 23:44:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!