在线程中更新窗体上的ListView控件上的内容,更新时如果不使用Synchronize(更新函数)就会抱错Code:1400,使用的话又会导致界面无响应
解决方案 »
- delphi如何实现与android平台的通讯?
- 谁能提供一些关于操作OutLook Expreee的资料
- 程序绑定 IE
- 关于遍历注册表的函数 RegEnumValue
- 关于一个sql语句?
- 二次添加
- 选中控件,按ctrl+c,ctrl+v,怎样复制出相同的控件出来,就象是在设计的时候一样。up有分,谢谢
- 请问谁知道扩展名为.wdl文件应该用什么程序打开?谢谢!
- 怎样用BDE控件在SQL Server创建一个存储过程?
- 小问题,怎样调出Notepad显示一个文本文件?(前10个有分)
- WINDOWSMEDIAPLAY10控件的ONENDOFSTREAM事件
- 如何打开默认的浏览器,而不只是IE,现在的浏览器种类多,用户使用习惯不同。顶者有分。
private
fSender :THandle;//发送窗口句柄
fWorkStatus :Boolean;//线程运行状态,要求声明为公用
fListViewDisplay :TListView;//处理文件,转换完成后的显示区域,现在使用ListView
fListViewSrc :TListView;//文件的原始信息,这个是不可见的
fFile :string;//传入的文件
fReadText :WideString;//每次读取的文件内容
fFieldList :TFieldList;//传入文件的格式,以及那些字段需要进行转换
protected
procedure Execute; override;
public
property WorkStatus:Boolean read fWorkStatus write fWorkStatus;
constructor Create(hSender,hhint:THandle;LVDisplay,LVSrc:TListView;const FileName:String;FieldList:TFieldList);
destructor Destroy();
procedure AddItem;
function ConvertText(const nType:ShortInt;szText:String):string;
function ConvertDateTimeField(const szField:String):String;
function ConvertMoneyFen2Yuan(const szMoney:String):String;
function SplitStr(SzValue:WideString;var retList:TStringList):Boolean;
function ConvertCtrlCode(const nCtrlItemType:ShortInt;szText:String):string;
end;
implementation
procedure TDisposeFileThread.AddItem;
var
j,i,MinIndex,MaxIndex:Shortint;
SplitList:TStringList;
ConvText :string;
bIsCaption:Boolean;
begin
SplitList:=TStringList.Create;
SplitStr(fReadText,SplitList);
MinIndex:= Low(fFieldList);
MaxIndex:=High(fFieldList);
with fListViewDisplay.Items.Add do
begin
bIsCaption:=True;
for i:=MinIndex to MaxIndex do
begin
if (fFieldList[i].nVisible=1)then
begin
ConvText:= ConvertText(fFieldList[i].nType,SplitList.Strings[fFieldList[i].nPosInFile-1]);
if bIsCaption then
begin
Caption := ConvText;
bIsCaption:=False;
end
else
SubItems.Add(ConvText);
end
end;
end;
with fListViewSrc.Items.Add do
begin
ConvText:= SplitList.Strings[fFieldList[MinIndex].nPosInFile];
Caption := ConvText;
for i:=MinIndex+1 to MaxIndex do
begin
ConvText:=SplitList.Strings[fFieldList[i].nPosInFile-1];
SubItems.Add(ConvText);
end;
end;
SplitList.Free;
end;
constructor TDisposeFileThread.Create(hSender,hHInt:THandle;LVDisplay,LVSrc:TListView;const FileName:String;FieldList:TFieldList);
begin
inherited Create(True);
FreeOnTerminate:=True;
fSender :=hSender;
fhint :=hhint;
fListViewDisplay:=LVDisplay;
fListViewSrc :=LVSrc;
fFieldList :=FieldList;
fFile :=FileName;
WorkStatus :=True;
end;procedure TDisposeFileThread.Execute;
label
OnExit;
var
f:TextFile;
wTemp:Widestring;
I:ShortInt;
begin
LockWindowUpdate(fListViewDisplay.Handle);
fListViewDisplay.Items.Clear;
fListViewSrc.Items.Clear;
LockWindowUpdate(0);
if not FileExists(fFile) then
goto OnExit;
AssignFile(f,fFile);
Reset(f);
i:=0;
{
while not Terminated do
begin
if WorkStatus then
begin
while (not Eof(f))and (i<ReadTimesOnce) do
begin
Readln(f,wtemp);
fReadList.Add(wTemp);
Inc(i);
end;
Synchronize(AddItem);
Sleep(1);
end
else
begin
fListViewDisplay.Items.Clear;
fListViewSrc.Items.Clear;
Break;
end; end;
}
while (Not Terminated)and (not Eof(f)) do
begin
if (WorkStatus) then
begin
Readln(f,wTemp);
fReadText:=wTemp;
Synchronize(AddItem);
end
else
begin
fListViewDisplay.Items.Clear;
fListViewSrc.Items.Clear;
Break;
end;
end;
CloseFile(f);
OnExit:
SendMessage(fSender,WM_DOTRANMSG,0,0);
end;