掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
動的配列の件 (ID:150331)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TD = Record B1: Integer; B2: Double; B3: Byte; End; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; P: Pointer; implementation {$R *.dfm} //保存 procedure TForm1.Button1Click(Sender: TObject); var I,J,K: Integer; D: array of array of array of TD; FileStream: TFileStream; begin SetLength(D, 10, 10, 10 ); for I:=0 to 9 do begin for J:=0 to 9 do begin for K:=0 to 9 do begin D[I,J,K].B1 := I; D[I,J,K].B2 := J + 0.1; D[I,J,K].B3 := K; end; end; end; FileStream := TFileStream.Create('AA.TXT',fmCreate); for I:=0 to 9 do begin for J:=0 to 9 do begin for K:=0 to 9 do begin FileStream.WriteData(D[I,J,K]); end; end; end; FileStream.Free end; //読み込み procedure TForm1.Button2Click(Sender: TObject); var I,J,K: Integer; D: array of array of array of TD; FileStream: TFileStream; S: String; begin SetLength(D, 10, 10, 10 ); for I:=0 to 9 do begin for J:=0 to 9 do begin for K:=0 to 9 do begin D[I,J,K].B1 := 0; D[I,J,K].B2 := 0; D[I,J,K].B3 := 0; end; end; end; FileStream := TFileStream.Create('AA.TXT',fmOpenRead); for I:=0 to 9 do begin for J:=0 to 9 do begin for K:=0 to 9 do begin FileStream.ReadData(D[I,J,K]); end; end; end; FileStream.Free; for I:=0 to 9 do begin for J:=0 to 9 do begin S := ''; for K:=0 to 9 do begin S := S + IntToStr(D[I,J,K].B1) + FloatToStr(D[I,J,K].B2) + IntToStr(D[I,J,K].B3) + ' '; end; Memo1.Lines.Add(S); end; end; end; end.
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.