zoukankan      html  css  js  c++  java
  • Delphi结构体数组指针的问题

    //这段代码在Delphi 2007和delphi 7下是可以执行的,所以正确使用结构体数组和指针应该是这样的,已验证
    
    unit
    Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); type TMyType = record S: String; I: Integer; end; TMyArray = array of TMyType; PMyArray = ^TMyArray; var MyArray: PMyArray; i:integer; AList:TStrings; begin try new(MyArray); AList:=TStringList.Create; SetLength(MyArray^, 50000); for i:=0 to 49999 do begin MyArray^[i].S :='中山'+inttostr(i); myArray^[i].I :=i; AList.Add(MyArray^[i].S+',年龄为:'+inttostr(MyArray^[i].I)); end; self.Memo1.Lines:=Alist; finally SetLength(MyArray^, 0); Dispose(MyArray); end; end; end.

    这段代码在Delphi 2007和delphi 7下是可以执行的,所以正确使用结构体数组和指针应该是这样的,已验证。

  • 相关阅读:
    11. Container With Most Water
    9. Palindrome Number
    375. 猜数字大小 II leetcode java
    leetcode 72 编辑距离 JAVA
    73. 矩阵置零 leetcode JAVA
    快速排序 JAVA实现
    63. 不同路径 II leetcode JAVA
    重写(override)与重载(overload)
    62 不同路径 leetcode JAVA
    leetcode 56 合并区间 JAVA
  • 原文地址:https://www.cnblogs.com/China3S/p/3286875.html
Copyright © 2011-2022 走看看