unit部分----------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Pmyrecode=^Tmyrecode;
Tmyrecode=record
PNextREC:Pmyrecode; //下一个
PriorREC:Pmyrecode;//上一个memo
Id:Integer ;
MyMemo:TMemo;
end;
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Memo4: TMemo;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function NextPREC(OMyREC:Tmyrecode):Pmyrecode;
{ Public declarations }
end;
var
Form1: TForm1;
//MyGlobalREC:Tmyrecode;
SCurrREC:Pmyrecode;
FirstREC:Pmyrecode;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
pp,p01:Pmyrecode;
Myid,LastId:Integer;
begin
pp:=FirstREC; //SCurrREC ;
while pp<>nil do
begin
p01:=pp;
ShowMessage(p01^.MyMemo.Name+';;' +inttostr(p01^.id));
pp:= p01^.PnextREC;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
var
AbmNode:Pmyrecode;
i,j:Integer;
begin
SCurrREC := nil;
j:=0;
for i:=0 to Self.ComponentCount-1 do
begin
if Self.Components[i] is Tmemo then
begin
Inc(j);
AbmNode := New(Pmyrecode);
AbmNode^.MyMemo:=(Self.Components[i] as Tmemo);
AbmNode^.Id:=j;
AbmNode^.PriorREC := nil;
AbmNode^.PNextREC := nil;
if SCurrREC = nil then
FirstREC := AbmNode
else
SCurrREC^.PNextREC := AbmNode;
AbmNode^.PriorREC := SCurrREC;
SCurrREC := AbmNode;
end;
end;
end;
end.
-----Unit部分结束---------------------------
Form部分--------
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 487
ClientWidth = 715
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 96
Top = 379
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object Memo1: TMemo
Left = 32
Top = 8
Width = 185
Height = 89
ImeName = #20013#25991'('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
Lines.Strings = (
'Memo1')
TabOrder = 1
end
object Memo2: TMemo
Left = 32
Top = 120
Width = 185
Height = 89
ImeName = #20013#25991'('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
Lines.Strings = (
'Memo2')
TabOrder = 2
end
object Memo3: TMemo
Left = 32
Top = 240
Width = 185
Height = 89
ImeName = #20013#25991'('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
Lines.Strings = (
'Memo3')
TabOrder = 3
end
object Memo4: TMemo
Left = 368
Top = 64
Width = 185
Height = 169
ImeName = #20013#25991'('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
Lines.Strings = (
'Memo4')
TabOrder = 4
end
object Button2: TButton
Left = 223
Top = 48
Width = 75
Height = 25
Caption = 'Button2'
TabOrder = 5
end
object Button3: TButton
Left = 224
Top = 160
Width = 75
Height = 25
Caption = 'Button3'
TabOrder = 6
end
object Button4: TButton
Left = 223
Top = 280
Width = 75
Height = 25
Caption = 'Button4'
TabOrder = 7
end
end
------Form部分结束--------------------
-----------记录类型的指针内存操作-----
Type
PmyRecord=^TmyRecord;
TmyRecord=record
Fname:string;
FAge:Integer;
end;
var
MyR:PmyRecord;
begin
New(MyR);//和Dispose成对出现
//GetMem ( MyR , sizeof ( TmyRecord ));//也可以
MyR^.Fname:='string';
ShowMessage(MyR^.Fname);
Dispose(MyR);
//FreeMem ( MyR );//和GetMem 成对出现
end;
------------------------
---杂资料---
GetMem AllocMem ReallocMem FreeMem GetMemory ReallocMemory FreeMemory New Dispose NewStr DisposeStr StrNew StrAlloc StrDispose GlobalAllocPtr GlobalFreePtr WideStrAlloc AnsiStrAlloc StrDispose Move MoveMemory CopyMemory ZeroMemory FillMemory FillChar StrBufSize
----Delphi 的内存操作函数-1,2,3,4_chinajobs的专栏-CSDN博客 https://blog.csdn.net/chinajobs/article/details/44976479