掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
FormまたはUnitごと保存・読み取りをするには? (ID:39202)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
小生がかって先輩に教わったコード例です。何か参考になれば。 ざっと抜粋したのでミスがあると思いますが。 TForm1 = class(TForm) private { Private 宣言 } public { Public 宣言 } end; const BandCount=3; //CoolBarを置きその上にToolbarを3個置いているという宣言です。 //たとえば一段目を左右2個、2段目を一個。あるいは3段になったりする。 var Form1: TForm1; iniFile: TIniFile; //iniファイルの名前の宣言 AppPath: string; //このプログラムを置いておくフォルダパスを格納する implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Form1.Position:=poDesigned; iniFile := TIniFile.Create(AppPath);//iniファイルをオープン //フォーム形状復元 //最初inifairuganaitoki-100を取得したときインストールして最初の起動だと判断するため //いろいろな箇所で最初ならファイルを新規作成するため if IniFile.ReadInteger('Window', 'Top', -100)=-100 then begin Form1.Width:= 640;//俺のモニタはVGAだからはみ出すというクレームを食うので Form1.Height:= 480; end else begin //iniファイルがあるとき Form1.Top:= IniFile.ReadInteger('Window', 'Top', Form1.Top ); Form1.Left:= IniFile.ReadInteger('Window', 'Left', Form1.Left ); Form1.Width:= IniFile.ReadInteger('Window', 'Width', 640 ); Form1.Height:= IniFile.ReadInteger('Window', 'Height', 480); //USBメモリーにインストールしている場合開いたモニタのサイズが違うかもしれないから if IniFile.ReadBool('Window', 'Maxmize', False) then begin Form1.WindowState := wsMaximized; end else begin Form1.WindowState := wsNormal; end; end; //-------------------------CoolBarの左右の長さやフロート状態を復元する------------------------------------- //CoolBarの上に3個のToolBarがありどんな形になっているかわからないので復元 for i:=0 to BandCount-1 do begin //Bandの位置とBreakを読込む BandIDNumber[i]:= IniFile.ReadInteger('CoolBar1','Band'+IntToStr(i)+'ID',i); BandWidth[i] := IniFile.ReadInteger('CoolBar1','Band'+IntToStr(i)+'Width',452); //452は自分のサイズ if i=1 then BandBreak[i] := IniFile.ReadBool('CoolBar1','Band'+IntToStr(i)+'Break',false) else BandBreak[i] := IniFile.ReadBool('CoolBar1','Band'+IntToStr(i)+'Break',true); end; CoolBar1.Bands.BeginUpdate; //値の呼び出して復元 Tax :=iniFile.ReadInteger('Tax',%',5); //数値の復元 Edit1.Text :=iniFile.ReadString('Edit1','Text',''); //文字列の復元 DisplayYesNo :=iniFile.ReadBool(DisplayYesNot','Yes',false); //true or falseの復元 iniFile.Free; //iniファイルを閉じる end; procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin //フォームの状態をiniファイルに書き込みして保存する iniFile := TIniFile.Create(AppPath );//iniファイルを開く if Form1.WindowState = wsNormal then//フォームの状態を保存する begin IniFile.WriteBool( 'Window', 'Maxmize', False ); IniFile.WriteInteger('Window', 'Top', Form1.Top ); IniFile.WriteInteger('Window', 'Left', Form1.Left ); IniFile.WriteInteger('Window', 'Width', Form1.Width ); IniFile.WriteInteger('Window', 'Height', Form1.Height); end else begin IniFile.WriteBool('Window', 'Maxmize', True); end; //---------------------------CoolBarの上のToolBarの保存------------ for i:=0 to BandCount-1 do begin //Bandの位置とBreakを書きこむ iniFile.WriteInteger('CoolBar1','Band'+IntToStr(i) +'ID',CoolBar1.Bands[i].ID); iniFile.WriteInteger('CoolBar1','Band'+IntToStr(i) +'Width',CoolBar1.Bands[i].Width); iniFile.WriteBool('CoolBar1','Band'+IntToStr(i) +'Break',CoolBar1.Bands[i].Break); end; iniFile.WriteInteger('Tax','%',Tax );//数値の保存 iniFile.WriteString( 'Edit1','Text',Edit1.Text);//文字列の保存 iniFile.WriteBool('DisplayYesNot','Boolean',DisplayYesNo);//true or falseの保存 IniFile.Free;//iniファイルを閉じる end; initialization AppPath := ExtractFilePath(Application.ExeName); //起動時にこのexeファイルのあるフォルダパスを取得しておく end. // 一番最後のend
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.