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

請問TIdBase64decoder如何使用?謝謝

尚未結案
kagaya
中階會員


發表:74
回覆:175
積分:59
註冊:2002-12-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-07-03 13:34:57 IP:61.219.xxx.xxx 未訂閱
字串(String)是亂碼 而TIdBase64decoder要使用哪個方法(methods)才能把字串解碼成中文? 謝謝
------
KUSO 無處不在
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-07-03 13:58:29 IP:61.217.xxx.xxx 未訂閱
引言: 字串(String)是亂碼 而TIdBase64decoder要使用哪個方法(methods)才能把字串解碼成中文? 謝謝
你的解出後的資料,例如放於MEMO元件,則該元件的字型預設建議用「細明體」 範例:
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdCoder, IdCoder3To4, StdCtrls, IdGlobal;    type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Memo2: TMemo;
    TIdBase64Encoder1: TIdBase64Encoder;
    SaveDialog1: TSaveDialog;
    Memo3: TMemo;
    Button3: TButton;
    IdBase64Decoder1: TIdBase64Decoder;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;
  RString:string;    implementation    {$R *.dfm}    //進行加密處理
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo2.Clear;
  TIdBase64Encoder1.CodeString(Memo1.Text); //取得使用者輸入的資料
  RString:=TIdBase64Encoder1.CompletedInput;
  Fetch(RString,';');
  Memo2.Text:=Fetch(RString,';');
end;    //儲存加密後的檔案
procedure TForm1.Button2Click(Sender: TObject);
begin
  if SaveDialog1.Execute then
   Memo2.Lines.SaveToFile(SaveDialog1.FileName);
end;    //解密後結果預覽
procedure TForm1.Button3Click(Sender: TObject);
begin
  Memo3.Clear;
  IdBase64Decoder1.CodeString(Memo2.Text); //取得加密的資料
  RString:=IdBase64Decoder1.CompletedInput;
  Fetch(RString,';'); 
  Memo3.Text:=Fetch(RString,';');   //解密後結果預覽
end;    end.
 
網海無涯,學無止境! 發表人 - qoo1234 於 2003/07/03 14:34:40
kagaya
中階會員


發表:74
回覆:175
積分:59
註冊:2002-12-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-07-03 14:37:46 IP:61.219.xxx.xxx 未訂閱
謝謝大大的回答 我最初也是寫的和上面一樣 但得到錯誤訊"coding table entry not found" 不知是否是codingtable的內容要改? 謝謝
------
KUSO 無處不在
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-07-03 14:55:15 IP:61.217.xxx.xxx 未訂閱
引言: 謝謝大大的回答 我最初也是寫的和上面一樣 但得到錯誤訊"coding table entry not found" 不知是否是codingtable的內容要改? 謝謝
你試試: (讀取INI檔解密方式) Ini := TIniFile.Create(ExtractFilePath(Paramstr ) 'Setup.ini'); //讀之前先找檔案 de64_Line(Trim(ini.ReadString('Setup', 'username', ''))); 網海無涯,學無止境!
kagaya
中階會員


發表:74
回覆:175
積分:59
註冊:2002-12-28

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-07-03 15:14:44 IP:61.219.xxx.xxx 未訂閱
sorry.不是很了解ini在解碼上的做用?... 其實我想做的是預覽信箱內信件的標題.但標題是經過編碼的 所以我需要解碼才看得到中文 預設的codingtable的內容是ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 / 不知道是不是這個綠故才有錯誤訊息? 謝謝
------
KUSO 無處不在
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-07-03 15:54:13 IP:61.217.xxx.xxx 未訂閱
引言: sorry.不是很了解ini在解碼上的做用?... 其實我想做的是預覽信箱內信件的標題.但標題是經過編碼的 所以我需要解碼才看得到中文 預設的codingtable的內容是ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 / 不知道是不是這個綠故才有錯誤訊息? 謝謝
請簡短程式碼放上來~才能知道你的問題~ < src="http://delphi.ktop.com.tw/download/upload\33223_qoo.gif">網海無涯,學無止境!
kagaya
中階會員


發表:74
回覆:175
積分:59
註冊:2002-12-28

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-07-03 16:15:23 IP:61.219.xxx.xxx 未訂閱
程式碼如下.謝謝. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient, IdPOP3, IdBaseComponent, IdCoder, IdCoder3To4, Psock, NMpop3; type TForm1 = class(TForm) b1: TBitBtn; b2: TBitBtn; pop3: TNMPOP3; m1: TListBox; b64: TIdBase64Decoder; t1: TEdit; procedure b1Click(Sender: TObject); procedure b2Click(Sender: TObject); procedure pop3Connect(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; khost, kuser, kpasswd: string; implementation {$R *.dfm} procedure TForm1.b1Click(Sender: TObject); begin khost := 'cm1.ethome.net.tw'; kuser := '我的帳號'; kpasswd := '我的密碼'; pop3.Host := khost; pop3.UserId := kuser; pop3.Password := kpasswd; pop3.Connect; end; procedure TForm1.b2Click(Sender: TObject); begin pop3.Disconnect; self.Caption := ''; end; procedure TForm1.pop3Connect(Sender: TObject); var s1: string; z: integer; begin self.Caption := 'ok,' inttostr(pop3.MailCount) '封'; m1.Items.Clear; if pop3.MailCount = 0 then begin self.Caption := 'no mail'; exit; end; for z := 1 to pop3.MailCount do //把所有郵件主題顯示到m1 begin pop3.GetSummary(z); s1 := pop3.Summary.Subject; //這時s1是亂碼 b64.CodeString(s1); s1 := b64.CompletedInput; //程式跑到這裡錯誤 m1.Items.Add(s1); end; end; end.
------
KUSO 無處不在
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-07-03 20:39:47 IP:61.216.xxx.xxx 未訂閱
該範例你參考看看~ 來源:自由尊龍原始碼系列之一 http://playstation2.idv.tw/sourcecode/projects/db64.html 原始碼下載: http://cafehat.no-ip.org/raiden/sourcecode/dbase64src.zip    其他: Base64 的 encode/decode  http://delphi.ktop.com.tw/topic.php?topic_id=26104 http://delphi.ktop.com.tw/topic.php?topic_id=22036 關於BASE64的解碼(附原始碼)  http://delphi.ktop.com.tw/topic.php?topic_id=27151    =================================================================    投機的方式~單純使用該Function處理(不用TIdBase64decoder元件方式) 大富翁論壇: src="http://delphi.ktop.com.tw/download/upload\33223_qoo.gif"> 網海無涯,學無止境! 發表人 - qoo1234 於 2003/07/04 00:47:42
kagaya
中階會員


發表:74
回覆:175
積分:59
註冊:2002-12-28

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-07-04 09:16:34 IP:61.219.xxx.xxx 未訂閱
目前還沒試出來.不過很感謝大大你的指導 如果有試出來我再跟你報告.謝謝~_~
------
KUSO 無處不在
kagaya
中階會員


發表:74
回覆:175
積分:59
註冊:2002-12-28

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-07-04 09:34:26 IP:61.219.xxx.xxx 未訂閱
試出來了.感謝大大的提供.看到中文的一刻真感動 用大富翁的那個函數 function CheckTxt(s: string): string; var s1,s2,s3: integer; t,v: string; Encoding: char; hex,step: integer; a1: array[1..4] of byte; b1: array[1..3] of byte; j: integer; byte_ptr,real_bytes: integer; begin s1:=Pos('=?',s); s2:= 1 ; hex:= 0 ; if s1>0 then begin for s2:=Length(s)-1 downto 1 do begin if Copy(s,s2,2)='?=' then Break; end; end; if (s1=0) or (s2=1) then begin Result:=s; Exit; end; t:=Copy(s,s1 2,s2-2-s1); s3:=Pos('?',t); Delete(t,1,s3); if(t='')then begin Result:= s; Exit ; end ; Encoding:=t[1]; Delete(t,1,2); v:=''; step:=0; case Encoding of 'Q': while t<>'' do begin case step of 0: begin case t[1] of '_': v:=v ' '; '=': step:=1; else v:=v t[1]; end; end; 1: begin if t[1]<='9' then hex:=(Ord(t[1])-Ord('0'))*16 else hex:=(Ord(t[1])-55)*16; step:=2; end; 2: begin if t[1]<='9' then hex:=hex (Ord(t[1])-Ord('0')) else hex:=hex Ord(t[1])-55; v:=v Chr(hex); step:=0; end; end; Delete(t,1,1); end; 'B': begin byte_ptr:=0; for j:=1 to Length(t) do begin Inc(byte_ptr); case t[j] of 'A'..'Z': a1[byte_ptr]:=Ord(t[j])-65; 'a'..'z': a1[byte_ptr]:=Ord(t[j])-71; '0'..'9': a1[byte_ptr]:=Ord(t[j]) 4; ' ': a1[byte_ptr]:=62; '/': a1[byte_ptr]:=63; '=': a1[byte_ptr]:=64; end; if byte_ptr=4 then begin byte_ptr:=0; real_bytes:=3; if a1[1]=64 then real_bytes:=0; if a1[3]=64 then begin a1[3]:=0; a1[4]:=0; real_bytes:=1; end; if a1[4]=64 then begin a1[4]:=0; real_bytes:=2; end; b1[1]:=a1[1]*4 (a1[2] div 16); b1[2]:=(a1[2] mod 16)*16 (a1[3]div 4); b1[3]:=(a1[3] mod 4)*64 a1[4]; if(real_bytes>0)then v:= v chr(b1[1]) ; if(real_bytes>1)then v:= v chr(b1[2]) ; if(real_bytes>2)then v:= v chr(b1[3]) ; end; end; end; end; Result:=Copy(s,1,s1-1) v Copy(s,s2 2,999); end;
------
KUSO 無處不在
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-07-04 09:43:00 IP:61.216.xxx.xxx 未訂閱
恭喜~ < src="http://delphi.ktop.com.tw/download/upload\33223_qoo.gif">網海無涯,學無止境!
系統時間:2024-05-04 9:08:15
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!