PRCV_REPORT_STRUCTEx = ^tagRCV_REPORT_STRUCTEx;    TStockReport = array of TList;    tagRCV_REPORT_STRUCTEx=record
m_cbSize : WORD; // 结构大小
m_time : integer ; // 交易时间
m_wMarket : WORD; // 股票市场类型
m_szLabel : array[0..STKLABEL_LEN] of Char; // 股票代码,以'\0'结尾
m_szName : array[0..STKNAME_LEN] of Char; // 股票名称,以'\0'结尾        m_fLastClose : single; // 昨收
m_fOpen : single; // 今开
m_fHigh : single; // 最高
m_fLow : single; // 最低
m_fNewPrice : single; // 最新
m_fVolume : single; // 成交量
m_fAmount : single; // 成交额 m_fBuyPrice : array[0..3] of single; // 申买价1,2,3
m_fBuyVolume : array[0..3] of single; // 申买量1,2,3
m_fSellPrice : array[0..3] of single; // 申卖价1,2,3
m_fSellVolume : array[0..3] of single; // 申卖量1,2,3 m_fBuyPrice4 : single; // 申买价4
m_fBuyVolume4 : single; // 申买量4
m_fSellPrice4 : single; // 申卖价4
m_fSellVolume4 : single; // 申卖量4
    end;
///////////////////////////
m_pReport : PRCV_REPORT_STRUCTEx;我现在m_pReport 指向了一个内存块,里面放的是tagRCV_REPORT_STRUCTEx数组以前在C++中可以用m_pReport[i],来存取这块内存中的,现在在delphi中怎么办?

解决方案 »

  1.   

    to 
    回复人: bluenightsky() ( ) 信誉:78  2003-09-19 11:10:00  得分:0 
     
     
      m_pReport^[i]
      编译不通过[Error] Unit1.pas(63): Array type required
      

  2.   

    m_pReport^.m_cbSize
    他就不是个数组
      

  3.   

    刚才没看懂你的意思
    我现在m_pReport 指向了一个内存块,里面放的是tagRCV_REPORT_STRUCTEx数组
    m_pReport[i]^.m_cbSize
      

  4.   

    是你说的意思,但是还是编译不通过,因为我的m_pReport定义的不是数据类型
    m_pReport : PRCV_REPORT_STRUCTEx;编译器提示:[Error] Unit1.pas(63): Array type required
      

  5.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    const STKLABEL_LEN=10;
    const STKNAME_LEN=20;
    type
       TStockReport = array of TList;
        tagRCV_REPORT_STRUCTEx=record
    m_cbSize : WORD; // 结构大小
    m_time : integer ; // 交易时间
    m_wMarket : WORD; // 股票市场类型
    m_szLabel : array[0..STKLABEL_LEN] of Char; // 股票代码,以'\0'结尾
    m_szName : array[0..STKNAME_LEN] of Char; // 股票名称,以'\0'结尾        m_fLastClose : single; // 昨收
    m_fOpen : single; // 今开
    m_fHigh : single; // 最高
    m_fLow : single; // 最低
    m_fNewPrice : single; // 最新
    m_fVolume : single; // 成交量
    m_fAmount : single; // 成交额 m_fBuyPrice : array[0..3] of single; // 申买价1,2,3
    m_fBuyVolume : array[0..3] of single; // 申买量1,2,3
    m_fSellPrice : array[0..3] of single; // 申卖价1,2,3
    m_fSellVolume : array[0..3] of single; // 申卖量1,2,3 m_fBuyPrice4 : single; // 申买价4
    m_fBuyVolume4 : single; // 申买量4
    m_fSellPrice4 : single; // 申卖价4
    m_fSellVolume4 : single; // 申卖量4
        end;
    ARCV_REPORT_STRUCTEx = array[0..1000]of tagRCV_REPORT_STRUCTEx;
    PRCV_REPORT_STRUCTEx=^ARCV_REPORT_STRUCTEx;
    ///////////////////////////
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
    m_pReport : PRCV_REPORT_STRUCTEx;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
    tmpi:integer;
    begin
    m_pReport:=PRCV_REPORT_STRUCTEx(allocmem(10000));
    tmpi:=0;
    repeat
    inc(tmpi);
    m_pReport^[tmpi].m_time:=tmpi*10;
    until tmpi>100;
    tmpi:=0;repeat
    inc(tmpi);
    memo1.Lines.Add(inttostr(m_pReport^[tmpi].m_time));
    until tmpi>100;freemem(m_pReport);end;end.
      

  6.   

    m_pReport并不是一个数组的指针,说仪刚才的编译会有错误。
    你定义的m_pReport是一个记录指针。按照你前面的定义,感觉你是要实现一个二维的表。
    假设。假设arr是一个TStockReport 类的对象的话,可以有下面的写法
    PRCV_REPORT_STRUCTEx(arr[i].items[j])^.m_cbSize:= 10;
    至于“^”在delphi中的要求不是很严格
      

  7.   

    m_pReport并不是一个数组的指针,说仪刚才的编译会有错误。
    你定义的m_pReport是一个记录指针。按照你前面的定义,感觉你是要实现一个二维的表。
    假设。假设arr是一个TStockReport 类的对象的话,可以有下面的写法
    PRCV_REPORT_STRUCTEx(arr[i].items[j])^.m_cbSize:= 10;
    至于“^”在delphi中的要求不是很严格
      

  8.   

    你在说什么呀?
    m_pReport只不过是个指向tagRCV_REPORT_STRUCTEx的指针记录。
    如果你是要访问m_pReport中的东西,只要m_pReport.m_cbsize就可以了
      

  9.   

    DELPHI与C++有区别,C++中:m_pReport : PRCV_REPORT_STRUCTEx;就给指针m_pReport 分配了内存,但DELPHI中不是的她仅仅是创建了这个指针,并未为指针分配内存,要自己分配:所以应该加上:new(m_pReport); 然后就可以这样引用了m_pReport[i]^.m_cbSize
      

  10.   

    你的指针并不是数组,而是一个记录型指针吧?
    那么应该这样引用:m_pReport^.m_cbSize
      

  11.   

    //给你个使用指针的Demo:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  PMyRecord = ^TMyRecord;
      TMyRecord = record             // 定义记录类型;
        MyValue: string;
        MyArray: array[0..3] of Integer;
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      MyRecord: PMyRecord;
      i: Integer;
    begin
      New(MyRecord);
      try
        MyRecord^.MyValue := 'MyValue';
        for i := 0 to 3 do
          MyRecord^.MyArray[i] := i;
        ShowMessage('MyRecord^.MyValue = ' + MyRecord^.MyValue);
        ShowMessage('MyRecord^.MyArray[0] = ' + IntToStr(MyRecord^.MyArray[0]));
        ShowMessage('MyRecord^.MyArray[1] = ' + IntToStr(MyRecord^.MyArray[1]));
        ShowMessage('MyRecord^.MyArray[2] = ' + IntToStr(MyRecord^.MyArray[2]));
        ShowMessage('MyRecord^.MyArray[3] = ' + IntToStr(MyRecord^.MyArray[3]));
      finally
        Dispose(MyRecord);
      end;
    end;end.
      

  12.   

    指针m_pReport不是数组类型,只是一个记录型指针,但是m_pReport.m_cbSize只能访问我的内存块中的第一个记录,我的内存块中有很多记录
      

  13.   

    type
      pa=^a;
      a=record
      aa:integer;
      end;
    ...............
    ar:array[1..5]of a;
    ...............
    var q:pa;
    begin
        ar[4].aa:=5;
        q:=@ar;
        inc(q,3);
        caption:=inttostr(q^.aa);
    end;明白你的意思了,看上面的代码吧,你是用一个指针指向一个数组的地址
      

  14.   

    明白了么,实际上就是+3,
    c中的a[i]与*(a+i)等价,此时指针移动i*变量类型的大小,如果是int,就移动i*2,这就是指针操作
    因此,inc(q,3);实际是把指针移动了 3*sizeof(PRCV_REPORT_STRUCTEx),即移动到了数组第4个元素