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

Unicode, ADO and Delphi

 
AB
高階會員


發表:166
回覆:262
積分:125
註冊:2003-08-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-18 22:46:47 IP:61.64.xxx.xxx 未訂閱
http://ksajadi.com/dflat/archives/000002.html     
October 22, 2003
Unicode, ADO and Delphi
I was looking around for a way of storing and retrieving Unicode (widestring) strings in an ADO Memo (blob) field. This seems to be easy first, but Delphi can not handle this simple task easily. Here is a simple solution for this:        unit WideMemoField;     interface    uses       DB, Classes;  
     type       TWideMemoField = class(TWideStringField) 
  
private         
function GetAsWideString: WideString; 
    
procedure SetAsWideString(const Value: WideString); 
  
protected         
function GetAsString: string; override; 
    
procedure SetAsString(const Value: string); override;        
function GetAsVariant: Variant; override; 
    
procedure SetVarValue(const Value: Variant); override;      
public         
constructor Create(AOwner: TComponent); override; 
    
property Value: WideString read GetAsWideString write     SetAsWideString; 
  
end; 
     procedure Register; 
     implementation          { TWideMemoField }          constructor TWideMemoField.Create(AOwner: TComponent); 
begin       
inherited Create(AOwner); 
  SetDataType(ftMemo); 
end; 
     function TWideMemoField.GetAsString: string; 
begin       SetDataType(ftWideString); 
  
try         Result := inherited GetAsString; 
  
finally         SetDataType(ftMemo); 
  
end; 
end; 
     function TWideMemoField.GetAsVariant: Variant; 
begin       SetDataType(ftWideString); 
  
try         Result := inherited GetAsVariant; 
  
finally         SetDataType(ftMemo); 
  
end; 
end; 
     function TWideMemoField.GetAsWideString: WideString; 
begin       SetDataType(ftWideString); 
  
try         Result:=inherited GetAsWideString; 
  
finally         SetDataType(ftMemo); 
  
end; 
end; 
     procedure TWideMemoField.SetAsString(const Value: string);    begin       SetDataType(ftWideString); 
  
try         
inherited SetAsString(Value); 
  
finally         SetDataType(ftMemo); 
  
end; 
end; 
     procedure TWideMemoField.SetAsWideString(const Value: WideString);    begin       SetDataType(ftWideString); 
  
try         
inherited SetAsWideString(Value); 
  
finally         SetDataType(ftMemo); 
  
end; 
end; 
     procedure TWideMemoField.SetVarValue(const Value: Variant); 
begin       SetDataType(ftWideString); 
  
try         
inherited SetVarValue(Value); 
  
finally         SetDataType(ftMemo); 
  
end; 
end; 
     procedure Register; 
begin       RegisterClasses([TWideMemoField]); 
  RegisterFields([TWideMemoField]); 
end; 
     end.    In order to use this method, you need to compile this method as a component. Create a component package and add this unit to it, compile and install it. Then add all fields from a table to the form (Right-click on Dataset component and select add fields) The you need to delete all fields you want to have Unicode access to and create new ones manually (New fields option from right-click menu) with the type of WideMemo. There would be a problem in field size. You can not set fields size to 0 for proportional field sizes. There for use the largest size you can think of, i.e. 65535. This will not take any resource from the system in the runtime.    Hopes this document is useful to the Delphi developers who are doing Unicode stuff and find it difficult to find resources in this area of Delphi development as I did.    Thanks to Bryan Ashby, Ka Chun Cheng, Tory Wolbrink with his excellent Delphi Unicode package and Hank Barndwijk.    Posted by khash at October 22, 2003 11:26 AM      
系統時間:2024-06-24 20:38:22
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!