回 帖 发 新 帖 刷新版面

主题:这个程序运行的时候错误,怎么回事啊?

这个程序运行的时候错误,怎么回事啊?




var
  hcurrentwindow:hwnd;
  sztext:array[0..254]of   char;
  gao:array [0..200] of string;
  i:integer;
begin
  listbox1.Items.Clear;
  hcurrentwindow:=GetForegroundWindow;
  while hcurrentwindow <> 0 do
  begin
    if getwindowtext(hcurrentwindow,@sztext,254) > 0 then
      listbox1.Items.Add(inttostr(hcurrentwindow)+':'+strpas(@sztext));
    hcurrentwindow:=GetNextWindow(hcurrentwindow,gw_hwndnext);
    gao[i]:=sztext[1]+sztext[2]+sztext[3]+sztext[4]+sztext[5];
    inc(i);
  end;
end;[em8][em8]

回复列表 (共1个回复)

沙发

首先你的i变量未初始化,其次,你在这个循环中,已经限制了gao数组成员的个数为201,所以当i的值超过201当然就会出错了!
还有数组应该从0开始,而不是你程序中szText[1]...

我来回复

您尚未登录,请登录后再回复。点此登录或注册