这是一个画证券曲线的程序
程序的思想是这样的:
1.线程一,采样个股数据写进固定表格里,并从表格中取数据放进全局动态数组里面
2.线程二,用全局动态数组的数据画曲线运行一会就出错,valid pointer operation,但是把线程一里面的取数据放进全局动态数组里面的部分,程序不会出错,但是画不出来曲线,好心人,帮忙分析一下!!!分不够,可以加

解决方案 »

  1.   

    另外有个问题就是不能在线程当中对VCL进行操作,比如画图。
      

  2.   

    ..\Borland\Delphi7\Demos\Threads里有个多线程例子,拷贝一下其源代码
    { Since DoVisualSwap uses a VCL component (i.e., the TPaintBox) it should never
      be called directly by this thread.  DoVisualSwap should be called by passing
      it to the Synchronize method which causes DoVisualSwap to be executed by the
      main VCL thread, avoiding multi-thread conflicts. See VisualSwap for an
      example of calling Synchronize. }procedure TSortThread.DoVisualSwap;
    begin
      with FBox do
      begin
        Canvas.Pen.Color := clBtnFace;
        PaintLine(Canvas, FI, FA);
        PaintLine(Canvas, FJ, FB);
        Canvas.Pen.Color := clRed;
        PaintLine(Canvas, FI, FB);
        PaintLine(Canvas, FJ, FA);
      end;
    end;{ VisusalSwap is a wrapper on DoVisualSwap making it easier to use.  The
      parameters are copied to instance variables so they are accessable
      by the main VCL thread when it executes DoVisualSwap }procedure TSortThread.VisualSwap(A, B, I, J: Integer);
    begin
      FA := A;
      FB := B;
      FI := I;
      FJ := J;
      Synchronize(DoVisualSwap);
    end;
      

  3.   

    1.线程一,采样个股数据写进固定表格里,并从表格中取数据放进全局动态数组里面 
    2.线程二,用全局动态数组的数据画曲线 我的线程二是主线程,也就是主form在form.show里面做了一些初始化,
     form.show里面的最后用
    hthread := BeginThread(nil,          //Security attribute
      0,                                   //Initial Stack
      @ThreadFunc,                         //Starting address of thread
      nil,                                 //argument of thread
      0,                                   // Create flags
      ThreadID);  
    来开通的线程一,这样的情况该怎么去同步呢?我的多线程的知识不够丰富,请帮帮忙啊
      

  4.   

    应该是线程同步的问题导致的。用临界区来处理。网上有个很经典的delphi关于线程的文章,搜一下吧。
    那么长,也贴不出来啊!