Record Point는 New로 생성하고 dispose로 파괴함.
만일 고정 String이 아니고 가변 String 변수를 사용하면 Reset해야함. ( aMyRecord^.A := '')
TYPE
TMyRECord = Packed Record
A : String;
B : String;
End;
PMyRecord = ^TMyRecord;
procedure TForm1.Button1Click(Sender: TObject);
var
MyRecords : array [1..6] of PMyRecord;
I: Integer;
begin
for i := 1 to 6 do
begin
// 생성
new(MyRecords[i]);
//Data
MyRecords[i]^.A := 'a' + IntToStr(i);
MyRecords[i]^.B := 'b' + IntToStr(i);
end;
Memo1.Lines.Clear;
for i := 1 to 6 do
Memo1.Lines.Add(MyRecords[i].A + ' , ' + MyRecords[i].B);
for i := 1 to 6 do
begin
// 가변 String 사용시 가변 String Data Reset // 메모리 잡아먹음.
MyRecords[i].A := '';
MyRecords[i].B := '';
// 파괴
dispose(MyRecords[i]);
end;
end;
:
:
: 김하랑 님이 쓰신 글 :
: : 포인터에 대해 공부하고 있습니다.
: : 아직 개념이 부족해서 그러는데요.
: : 아래 코드 좀 완성해 주시면 공부에 많은 도움이 되겠습니다.
: : 감사합니다.
: :
: : TYPE
: : TMyRECord = Packed Record
: : A : String[10];
: : B : String[10];
: : End;
: : PMyRecord = ^TMyRecord;
: :
: :
: : procedure TForm1.Button1Click(Sender: TObject);
: : var
: : MyRecord : PMyRecord;
: : I: Integer;
: : begin
: : New(MyRecord);
: : MyRecord.A := 'a1';
: : MyRecord.B := 'b1';
: :
: : INC(MyRecord);
: : MyRecord.A := 'a2';
: : MyRecord.B := 'b2';
: :
: : INC(MyRecord);
: : MyRecord.A := 'a3';
: : MyRecord.B := 'b3';
: :
: : INC(MyRecord);
: : MyRecord.A := 'a4';
: : MyRecord.B := 'b4';
: :
: : INC(MyRecord);
: : MyRecord.A := 'a5';
: : MyRecord.B := 'b5';
: :
: : INC(MyRecord);
: : MyRecord.A := 'a6';
: : MyRecord.B := 'b6';
: :
: : ------ 첫번째 MyRecord로 이동 ----
: : FOR i=0 TO MyRecord갯수만큼 DO
: : Begin
: : Memo1.Lines.Add(MyRecord.A + ' , ' + MyRecord.B);
: : Inc(MyRecord);
: : End
: : end; |