码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi用数字访问相关的内存(此处数字要为有效地址,且知道该地址的类型)

时间:2021-03-17 14:08:06      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:eem   label   sse   util   开始   alt   integer   char   charset   

-----------Delphi XE---

仅仅是学习记录

---------------

技术图片

 

 

------------unit 开始

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Edit1: TEdit;
Button3: TButton;
Label1: TLabel;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Myarray:array of string;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
type
TArec=^Arec;
Arec=record
Name:string;//string[8];
Age:integer;
end;
var
p: ^Arec;
i,Num: Integer;
P001:Pointer;
type
ArrPoint = array of Arec;
begin
Num:=4;//当前Name:string;Num大于5就不会报错 //Name:string[8]; 这样的话,4是不会报错的
p := GetMemory(Num * SizeOf(Arec));
Label1.Caption:=IntToStr(Num * SizeOf(Arec));
FillChar(p^, num*sizeof(arec), #0); //当前Name:string;Num=4时,这么写不会报错
for i := 0 to Num-1 do
begin
P001:=pinteger(Integer(ArrPoint(p))+8*i);
Memo2.Lines.Add(IntToStr(integer(@(ArrPoint(p)[i]))) +‘ ‘+inttostr(Integer(ArrPoint(p))+8*i));
ArrPoint(p)[i].Name := ‘张三‘+inttostr(i);
self.Memo1.Lines.Add(ArrPoint(p)[i].Name+‘,年龄:‘+inttostr(ArrPoint(p)[i].Age));
ShowMessage(TArec(p001).Name);
ArrPoint(p)[i].Age :=i+30;
end;
FreeMemory(p);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i:Integer;
begin
SetLength(Myarray,StrToIntDef(Edit1.Text,4));
if StrToIntDef(Edit1.Text,4)<5 then
begin
for I := Low(Myarray) to High(Myarray) do
Myarray[i]:=‘Str_‘+IntToStr(i)
end
else
begin
Myarray[0]:=‘88‘;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
Type
TArr<MT> = array[0..9] of MT; {定义一个泛型数组}
var
Arr: TArr<Integer>;
i: Integer;
begin
for i := Low(Arr) to High(Arr) do
Arr[i] := i * i;

Memo1.Clear;
for i := Low(Arr) to High(Arr) do
Memo1.Lines.Add(Format(‘Arr[%d] = %d‘, [i, Arr[i]]));
end;

end.

 

----------------unit 结束

-----------Form 开始

object Form1: TForm1
Left = 1113
Top = 270
Caption = ‘Form1‘
ClientHeight = 332
ClientWidth = 420
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = ‘MS Sans Serif‘
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 103
Top = 40
Width = 105
Height = 13
AutoSize = False
Caption = ‘Label1‘
end
object Button1: TButton
Left = 103
Top = 112
Width = 75
Height = 25
Caption = ‘Button1‘
TabOrder = 0
OnClick = Button1Click
end
object Memo1: TMemo
Left = 0
Top = 8
Width = 97
Height = 161
ImeName = #20013#25991‘(‘#31616#20307‘) - ‘#25628#29399#25340#38899#36755#20837#27861
Lines.Strings = (
‘Memo1‘)
TabOrder = 1
end
object Button2: TButton
Left = 34
Top = 280
Width = 75
Height = 25
Caption = ‘Button2‘
TabOrder = 2
OnClick = Button2Click
end
object Edit1: TEdit
Left = 8
Top = 237
Width = 121
Height = 21
ImeName = #20013#25991‘(‘#31616#20307‘) - ‘#25628#29399#25340#38899#36755#20837#27861
TabOrder = 3
Text = ‘4‘
end
object Button3: TButton
Left = 288
Top = 192
Width = 75
Height = 25
Caption = #27867#22411
TabOrder = 4
OnClick = Button3Click
end
object Memo2: TMemo
Left = 214
Top = 8
Width = 179
Height = 161
ImeName = #20013#25991‘(‘#31616#20307‘) - ‘#25628#29399#25340#38899#36755#20837#27861
Lines.Strings = (
‘Memo2‘)
TabOrder = 5
end
end

------------Form 结束

 

 

 

 

 

参考博客

https://q.cnblogs.com/q/54116/

Delphi用数字访问相关的内存(此处数字要为有效地址,且知道该地址的类型)

标签:eem   label   sse   util   开始   alt   integer   char   charset   

原文地址:https://www.cnblogs.com/dmqhjp/p/14539540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!