求教tthread里面使用tstrings的问题,附有代码片段

radarhp 2010-10-08 11:29:56


TMyThread = class(TThread)
private
{ Private declarations }

FList: TStrings;
procedure GetAllData;

protected
procedure Execute; override;

public
constructor Create(CreateSuspended: Boolean);
destructor Destroy; override;
end;

implementation

constructor TMyThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FList:= TStringList.Create;
end;


destructor TMyThread.Destroy;
begin
FList.Free;
inherited;
end;

procedure TMyThread.Execute;
var
...

begin

...

GetAllData;// 后面的procedure

...

end;



procedure TMyThread.GetAllData;
var
...
begin

.....

if FBoxList.Count > 0 then
OutputDebugString( PChar(IntToStr(FBoxList.Count)) );
....

//*************** 到OutputDebugString这里 watch显示 Flist 依然可以访问 *************//
OutputDebugString( PChar('GetAllData') );

//执行了ReadProcessMemory后,FList就是Inaccessible value
if not ReadProcessMemory(PHandle,Pointer(p),@Tmp1,32 ,ReadByte) then
begin
OutputDebugString('GetAllData --- ReadProcessMemory fail');
end;
if Tmp1 = 123 then
begin
FList.add('123'); //********************* access vioate 错误了 ********************//
end

......

end;




前面还判断了FList的count
在delphi的watch里一直查看着这个FList,执行了ReadProcessMemory就开始无法访问了


为什么一ReadProcessMemory其他进程的数据,FList就无法访问了,我加个123的字符串都报错

麻烦大家指点下,谢谢

...全文
148 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
radarhp 2010-10-08
  • 打赏
  • 举报
回复
最近流年不利,自己都不知道ReadProcessMemory这个附近改了什么
现在突然就好使了。。。

结贴睡觉先。。。唉
radarhp 2010-10-08
  • 打赏
  • 举报
回复
//执行了ReadProcessMemory后,FList就是Inaccessible value
//if not ReadProcessMemory(PHandle,Pointer(p),@Tmp1,32 ,ReadByte) then
//begin
// OutputDebugString('GetAllData --- ReadProcessMemory fail');
//end;
//if Tmp1 = 123 then
//begin
FList.add('123'); //********************* access vioate 错误了 ********************//
//end


To 楼上兄弟

代码注释那几句以后,完全正常。。。。
zhaodog 2010-10-08
  • 打赏
  • 举报
回复
代码太少,不好分析,有可能是读取时FList 被改变
1、可以不读取测试一下
2、读取内存的大小改为0测试一下
radarhp 2010-10-08
  • 打赏
  • 举报
回复
人工置顶下。。。。在线求解 速度结贴,呵呵

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧