如果要把FontDialog內的屬性資料存到資料庫日後再讀出,我要存成何種型態呢? |
答題得分者是:william
|
saam
初階會員 發表:61 回覆:75 積分:27 註冊:2003-03-03 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
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 發送簡訊給我 |
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 發送簡訊給我 |
感謝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 發送簡訊給我 |
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 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
saam
初階會員 發表:61 回覆:75 積分:27 註冊:2003-03-03 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |