grid memo欄位的utf8問題 |
答題得分者是:t27
|
vbnet1234
一般會員 發表:3 回覆:2 積分:1 註冊:2010-03-01 發送簡訊給我 |
大家好, 在DBGrid上遇到一個問題請教, 因為DBGrid秀出某些欄位時為memo, 所以我搜尋了網路上的方法
利用GetText, 使該欄位可正常秀出, 不過原本在mysql裡面是utf8的編碼, 輸出後中文都變成亂碼... 請問大哥們該如何解決^^" [code delphi] procedure TForm7.ADOTable1componentGetText(Sender: TField; var Text: string; DisplayText: Boolean); begin text:=trim(Sender.asstring); displaytext:=true; end; [/code] |
t27
中階會員 發表:34 回覆:95 積分:90 註冊:2002-06-19 發送簡訊給我 |
試試看
例: WideStringToString(cText, 950); //Unicode 轉 ANSI function WideStringToString(const WS: WideString; CodePage: Word): string; var InputLength, OutputLength: Integer; begin InputLength := Length(WS); OutputLength := WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, nil, 0, nil, nil); SetLength(Result, OutputLength); WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, PChar(Result), OutputLength, nil, nil); end;
|
vbnet1234
一般會員 發表:3 回覆:2 積分:1 註冊:2010-03-01 發送簡訊給我 |
謝謝大大回答, 改成這樣依然還是亂碼
[code delphi] function WideStringToString(const WS: WideString; CodePage: Word): string; var InputLength, OutputLength: Integer; begin InputLength := Length(WS); OutputLength := WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, nil, 0, nil, nil); SetLength(Result, OutputLength); WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, PAnsiChar(string(Result)), OutputLength, nil, nil); end; procedure TForm5.Table1descriptionGetText(Sender: TField; var Text: string; DisplayText: Boolean); begin text := WideStringToString(Sender.AsString,950); displaytext:=true; end; [/code]
編輯記錄
vbnet1234 重新編輯於 2010-03-17 16:47:06, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |