新建一程序
添加 PageControl控件
在PageControl1上添加5个页面
在每个页面上添加一个ListView控件
 在主窗体上添加一个button按钮
代码如下:unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    TabSheet5: TTabSheet;
    ListView1: TListView;
    ListView2: TListView;
    ListView3: TListView;
    ListView4: TListView;
    ListView5: TListView;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure lvadd;
  end;var
  Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.lvadd;
var
  i : integer;
begin
  for i := 1 to 50 do
  begin
    with Form1.ListView1.Items.Insert(Form1.ListView1.Items.Count) do
    begin
      Caption := '1首'+IntToStr(i);
      SubItems.Insert(0,'1次'+IntToStr(i));
      SubItems.Insert(1,'1中'+IntToStr(i));
      SubItems.Insert(2,'1末'+IntToStr(i));
      SubItems.Insert(3,'1尾'+IntToStr(i));
    end;
    with Form1.ListView2.Items.Insert(Form1.ListView2.Items.Count) do
    begin
      Caption := '2首'+IntToStr(i);
      SubItems.Insert(0,'2次'+IntToStr(i));
      SubItems.Insert(1,'2中'+IntToStr(i));
      SubItems.Insert(2,'2末'+IntToStr(i));
      SubItems.Insert(3,'2尾'+IntToStr(i));
    end;
    with Form1.ListView3.Items.Insert(Form1.ListView3.Items.Count) do
    begin
      Caption := '3首'+IntToStr(i);
      SubItems.Insert(0,'3次'+IntToStr(i));
      SubItems.Insert(1,'3中'+IntToStr(i));
      SubItems.Insert(2,'3末'+IntToStr(i));
      SubItems.Insert(3,'3尾'+IntToStr(i));
    end;
    with Form1.ListView4.Items.Insert(Form1.ListView4.Items.Count) do
    begin
      Caption := '4首'+IntToStr(i);
      SubItems.Insert(0,'4次'+IntToStr(i));
      SubItems.Insert(1,'4中'+IntToStr(i));
      SubItems.Insert(2,'4末'+IntToStr(i));
      SubItems.Insert(3,'4尾'+IntToStr(i));
    end;
    with Form1.ListView5.Items.Insert(Form1.ListView5.Items.Count) do
    begin
      Caption := '5首'+IntToStr(i);
      SubItems.Insert(0,'5次'+IntToStr(i));
      SubItems.Insert(1,'5中'+IntToStr(i));
      SubItems.Insert(2,'5末'+IntToStr(i));
      SubItems.Insert(3,'5尾'+IntToStr(i));
    end;
  end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
  hh : THandle;
  Id : DWord;
begin
  hh := Windows.CreateThread(nil,0,@TForm1.lvadd,nil,0,Id);
  Windows.CloseHandle(hh);
end;end.
奇怪的问题就是PageControl1的5个页面,在程序打开时直接点BUTTON1  你看下PageControl1的其他页面 不显示了!!而且在关闭的时候会提示一堆错误!!
如果在程序打开后 先把5个页面都点一下,然后在点BUTTON1 就正常了.不用线程的话就没有这个问题.现在就是想用线程添加数据呀,因为数据比较多呀.所以 这个问题要解决,各位朋友帮忙看看 什么原因?或怎么解决?

解决方案 »

  1.   

    如果对线程不熟悉,就老老实实用delphi封装的吧~~同步的时候可以用Synchronize,也可以使用postMessage向主线程发消息。
      

  2.   

    我现在是在Form1 的OnShow 事件里写的  TabSheet5.Show;
      TabSheet4.Show;
      TabSheet3.Show;
      TabSheet2.Show;
      TabSheet1.Show;这样就不会有问题了,但是想知道为什么??
      

  3.   

    "如果所有添加数据的火都让主窗体干"  ——那说明程序设计上有问题。给你举个例子,线程循环内部:
    ...
    ...
    s := xxxxxxx;
    postmessage(formhandle,WM_MYMSG,0,Integer(PChar(s)));
    ...
    ...主窗体消息处理过程:
    procedure WNMYMSG(var msg: TMessage);
    var s: string;
    begin
      s := StrPas(Pchar(PInteger(msg.lparam)^));
      memo1.lines.add(s);
    end;
      

  4.   

    wParam和lParam都是Integer类型,除了数字外,其它只能用地址表示。
    或者你就用Synchronize;具体使用方法看看书吧~~涉及到界面操作的,需要同步处理……-_-!!!   这20分挣的,费了老劲了
      

  5.   

    怎么把指针所指的地址 现实出来?
    var
      s:char;
      p:^Char;
    begin
      s := char('s');
      p := @s;
    end;
    这个P 怎么看它地址??
      

  6.   

    s := 's';
    showmessage(strpas(pchar(@s)));