问题是这样的:窗体上有个listview ,我用的是vsreport模式,然后建立8个列,然后设置listview的owndata=true,设置为virtual listview模式,在ondata事件里面增加了几个给listitem赋值的语句。然后建立一个thread,里面就一个语句 String p="fddfd";然后循环执行。程序运行的时候,线程中的语句报错,提示out of memory 我在线程里面创建任何vcl组件,比如TStringList Tlist,创建后,立刻删除。即使这样的代码,在运行的时候,也会出错。
C/C++ code//---------------------------------------------------------------------------#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include "Unit2.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TListView *lv1;
TPanel *pnl1;
TButton *btn1;
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall lv1Data(TObject *Sender, TListItem *Item);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif// ---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TStringList *list;
TMyThread *thread;// ---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{list = new TStringList();
lv1->OwnerData=true;
// lv1->OwnerData=false;
thread = new TMyThread(false);
for (int i = 0; i < 200; i++)
{
String str = IntToStr(Random(99999)) + IntToStr(Random(99999)) + "额佛法我的看得人浮动框积分的放假了对抗赛";
list->Add(str);
}
lv1->Items->Count = list->Count;
}// ---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete list;
thread->Terminate();}// ---------------------------------------------------------------------------
void __fastcall TForm1::lv1Data(TObject *Sender, TListItem *Item)
{
if (Item->Index > list->Count)
return;Item->Caption = list->Strings[Item->Index];
Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);
}
// ---------------------------------------------------------------------------
C/C++ code
//---------------------------------------------------------------------------#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
//---------------------------------------------------------------------------
class TMyThread : public TThread
{
private:
protected:
void __fastcall Execute();
public:
__fastcall TMyThread(bool CreateSuspended);
};
//---------------------------------------------------------------------------
#endif[code=C/C++]
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit2.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------__fastcall TMyThread::TMyThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
FreeOnTerminate=true;
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::Execute()
{
//---- Place thread code here ----
while(!Terminated)
{
try
{
String p="ytytrytrytrytrythgmnytjythtss";
}
catch(Exception & e)
{
int i=0;
}
}
}
//---------------------------------------------------------------------------
代码下载地址和视频演示在此下载,文件不大,只有200多K
http://pan.baidu.com/netdisk/singlepublic?fid=596138_634710353bcb和delphi差不多,我相信在delphi里也会有这个问题
C/C++ code//---------------------------------------------------------------------------#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include "Unit2.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TListView *lv1;
TPanel *pnl1;
TButton *btn1;
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall lv1Data(TObject *Sender, TListItem *Item);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif// ---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TStringList *list;
TMyThread *thread;// ---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{list = new TStringList();
lv1->OwnerData=true;
// lv1->OwnerData=false;
thread = new TMyThread(false);
for (int i = 0; i < 200; i++)
{
String str = IntToStr(Random(99999)) + IntToStr(Random(99999)) + "额佛法我的看得人浮动框积分的放假了对抗赛";
list->Add(str);
}
lv1->Items->Count = list->Count;
}// ---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete list;
thread->Terminate();}// ---------------------------------------------------------------------------
void __fastcall TForm1::lv1Data(TObject *Sender, TListItem *Item)
{
if (Item->Index > list->Count)
return;Item->Caption = list->Strings[Item->Index];
Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);Item->SubItems->Add(list->Strings[Item->Index]);
Item->SubItems->Add(list->Strings[Item->Index]);
}
// ---------------------------------------------------------------------------
C/C++ code
//---------------------------------------------------------------------------#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
//---------------------------------------------------------------------------
class TMyThread : public TThread
{
private:
protected:
void __fastcall Execute();
public:
__fastcall TMyThread(bool CreateSuspended);
};
//---------------------------------------------------------------------------
#endif[code=C/C++]
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit2.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------__fastcall TMyThread::TMyThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
FreeOnTerminate=true;
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::Execute()
{
//---- Place thread code here ----
while(!Terminated)
{
try
{
String p="ytytrytrytrytrythgmnytjythtss";
}
catch(Exception & e)
{
int i=0;
}
}
}
//---------------------------------------------------------------------------
代码下载地址和视频演示在此下载,文件不大,只有200多K
http://pan.baidu.com/netdisk/singlepublic?fid=596138_634710353bcb和delphi差不多,我相信在delphi里也会有这个问题
解决方案 »
- 请问inno怎么设置上一级目录呢?
- 按钮凹凸问题
- delphi 有什么 "输入框" 控件 可以实现 背景 渐变色 效果 (图) !!!!!!!!!!!!! 急!!!!!!!!!!!!!!!!!
- DBChart 对记录中字段空值,如何除去空值,而不是将空值显示成0
- 请问各位高手——关于DBGird的问题
- 在线等待:请问如何根据某一字段来控制DBgrid的显示颜色
- 关于主表单的设置
- paradox的数据库的字段名在delphi怎么样才能显示为中文?
- TreeView怎么在指定的目录级别下生成别外一个级别。。。
- 在98里怎么调用DCOMCNFG.exe,应如何设置
- 请问大家,关于access字段里有日文 用sql like语句就报内存溢出的问题
- 第一位是0的string转换成double?
只是循环对字符串变量赋值?bcb这种 重复给字符串赋值 会引起内存泄漏吗?
{
try
{
String p="ytytrytrytrytrythgmnytjythtss";
}
catch(Exception & e)
{
int i=0;
}这里面是不是循环一次就得申请一次内存呀。一直为真就一直申请给P,造成内存溢出。
String p="";
int i=0;
while(!Terminated)
{
try
{
p="ytytrytrytrytrythgmnytjythtss";
}
catch(Exception & e)
{
i=0;
}这样行不?