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

如果要把FontDialog內的屬性資料存到資料庫日後再讀出,我要存成何種型態呢?

答題得分者是:william
saam
初階會員


發表:61
回覆:75
積分:27
註冊:2003-03-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-11 09:42:26 IP:211.75.xxx.xxx 未訂閱
請教各位先進: 如果要把FontDialog內的屬性資料存到資料庫日後再讀出,我要存成何種型態呢? .尤其是style我不知道要存成什麼型態, 是否有方法存成一個字串,讀出時 直接轉成font的屬性呢?
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-11 10:01:51 IP:147.8.xxx.xxx 未訂閱
GetEnumName and GetEnumValue Font.Style is a set and I think you need to loop and test ,e.g. if fsBold in Font1.Style then {...} P.S. Instead of GetEnumName and GetEnumValue, you can simply use integer, .e.g Int := ord(fsBold); Font1.Style := Font1.Style TFontStyle(Int);
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-11 10:26:30 IP:147.8.xxx.xxx 未訂閱
Since you mentioned FontDialog, which is a TComponent. There is an easier method to save/load the whole component, e.g.
var
    FileStream: TFileStream;
begin
    FileStream := TFileStream.Create('c:\test.bin',fmCreate);
    try
        FileStream.WriteComponent(FontDialog1);
    finally
        FileStream.Free;
    end;
end;    var
    FileStream: TFileStream;
begin
    FileStream := TFileStream.Create('e:\test.bin',fmOpenRead);
    try
         FileStream.ReadComponent(FontDialog1);
    finally
        FileStream.Free;
    end;
end;
I think you could create a memory stream and save/load it into the DB as BLOB fields.
saam
初階會員


發表:61
回覆:75
積分:27
註冊:2003-03-03

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-11 13:39:55 IP:211.75.xxx.xxx 未訂閱
感謝William大大的指導: 但是我使用 in 這個方式找不出來 set 是否含有fsBold 或fsItalic 等, 我那理寫錯了呢?我寫的方式如下 var FName:String; FSize,FColor:Integer; FBold,FItalic,FUnDerline,FStrikeOut:Integer; begin if FontDialog1.Execute then begin FName:=FontDialog1.Font.Name ; FSize:=FontDialog1.Font.Size ; FColor:=FontDialog1.Font.Color ; if fsBold in FontDialog1.Font.Style then FBold := ord(fsBold); ========================>這裏不會做 if fsItalic in FontDialog1.Font.Style then FItalic := ord(fsItalic); ====================>這裏不會做 if fsUnDerline in FontDialog1.Font.Style then FUnDerline := ord(fsUnDerline); =================>這裏不會做 if fsStrikeOut in FontDialog1.Font.Style then FStrikeOut := ord(fsStrikeOut); ================>這裏不會 end; end;
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-04-11 14:13:31 IP:147.8.xxx.xxx 未訂閱
You code is fine but you forget to initialize FBold, FItalic, FUnDerline, FStrikeOut (e.g. -1 for none). BTW, you could simply use boolean type in your case becasue there is no need to store the actual value of the font style?    
var
  FName:String;
  FSize,FColor:Integer;
  FBold,FItalic,FUnDerline,FStrikeOut:boolean;
begin
  if FontDialog1.Execute then
  begin
    FName:=FontDialog1.Font.Name ;
    FSize:=FontDialog1.Font.Size ;
    FColor:=FontDialog1.Font.Color ;
    FBold := fsBold in FontDialog1.Font.Style;
    FItalic := fsItalic in FontDialog1.Font.Style;
    FUnDerline := fsUnDerline in FontDialog1.Font.Style
    FStrikeOut := fsStrikeOut in FontDialog1.Font.Style;
  end;
end;
saam
初階會員


發表:61
回覆:75
積分:27
註冊:2003-03-03

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-04-11 16:20:42 IP:211.75.xxx.xxx 未訂閱
非常感謝william大大:    請問我如果要把fsBold,fsItalic,fsUnDerline的值設到另一個元件的font ,要如何寫呢?我用 if FBold = true then include(label.Font.Style ,fsBold);    會有error.    
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-04-11 16:26:08 IP:147.8.xxx.xxx 未訂閱
if FBold then
    Lablel.Font.Style := Label.Font.Style     [fsBold];
saam
初階會員


發表:61
回覆:75
積分:27
註冊:2003-03-03

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-04-11 16:39:31 IP:211.75.xxx.xxx 未訂閱
我會了!感謝william的指導!
系統時間:2024-06-28 2:20:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!