掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
フォント情報をファイルに保存するには? (ID:10630)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
>どこが間違っているのでしょうか?ご教授お願いします。 例えば以下のコードでできます.複数のラベルということですので,3つの 例としました.後は適当に... ちなみに,私自身は,ファイルへの保存を伴う形でレコード型を使用するこ とはまずないですね.またほとんどTFileStreamを使用しています.(^_^) implementation type //レコード型の保存読出しテスト用 TSaveData = packed record FontColor: TColor; FontName : String[32]; FontSize : Integer; end; var ASaveData : array[0..2] of TSaveData; {$R *.DFM} //==================================================================== // Writeメソッドで保存 //==================================================================== procedure TForm1.Button1Click(Sender: TObject); var AFile : String; F : file of TSaveData; i : Integer; begin //保存前にプロパティを変更(これを保存) Label1.Font.Name :='MS ゴシック'; Label1.Font.Color :=clGray; Label1.Font.Size :=20; Label2.Font.Name :='MS ゴシック'; Label2.Font.Color :=clRed; Label2.Font.Size :=25; Label3.Font.Name :='MS P明朝'; Label3.Font.Color :=clBlue; Label3.Font.Size :=30; //保存データをSavedataに代入 ASavedata[0].FontName :=Label1.Font.Name; ASavedata[0].FontColor:=Label1.Font.Color; ASavedata[0].FontSize :=Label1.Font.Size; ASavedata[1].FontName :=Label2.Font.Name; ASavedata[1].FontColor:=Label2.Font.Color; ASavedata[1].FontSize :=Label2.Font.Size; ASavedata[2].FontName :=Label3.Font.Name; ASavedata[2].FontColor:=Label3.Font.Color; ASavedata[2].FontSize :=Label3.Font.Size; //保存 AFile := ChangeFileExt(Application.ExeName,'.sav'); try AssignFile(F, AFile); Rewrite(F); for i:=0 to 2 do begin Write(F, ASavedata[i]); end; finally CloseFile(F); end; end; //==================================================================== // Readメソッドで読出す //==================================================================== procedure TForm1.Button2Click(Sender: TObject); var AFile : String; F : file of TSaveData; i : Integer; begin //保存したデータを読出す AFile := ChangeFileExt(Application.ExeName,'.sav'); try AssignFile(F, AFile); Reset(F); for i:=0 to 2 do begin Read(F, ASavedata[i]); end; finally CloseFile(F); end; //読出した値でLabelのプロパティ変更 Label1.Font.Name := ASavedata[0].FontName; Label1.Font.Color:= ASavedata[0].FontColor; Label1.Font.Size := ASavedata[0].FontSize; Label2.Font.Name := ASavedata[1].FontName; Label2.Font.Color:= ASavedata[1].FontColor; Label2.Font.Size := ASavedata[1].FontSize; Label3.Font.Name := ASavedata[2].FontName; Label3.Font.Color:= ASavedata[2].FontColor; Label3.Font.Size := ASavedata[2].FontSize; end; end.
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.