读书人

什么在多程下反按后

发布时间: 2012-02-19 19:43:39 作者: rapoo

什么在多程下,反按后生Access Violation的?
什么在多程下,反按后生Access Violation的?

在unit1窗上1Flash,和1按:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, ShockwaveFlashObjects_TLB, StdCtrls,unit2;

type
TForm1 = class(TForm)
Fla: TShockwaveFlash;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
public
iSwf:integer;
IsSwfBusy:boolean;
hThread:TMyThread;
end;

var
Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if IsSwfBusy then exit;
IsSwfBusy:=true;
hThread:=TMyThread.Create(false);
hThread.FreeOnTerminate:=true;
IsSwfBusy:=true;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
hThread:=nil;iSwf:=0;
end;

end.



unit Unit2;

interface

uses
Classes,SysUtils;

type
tmythread = class(TThread)
protected
procedure Execute; override;
end;

implementation
uses unit1;
procedure tmythread.Execute;
begin
unit1.Form1.iSwf:=unit1.Form1.iSwf mod 2+1; //1.swf,2.swfFlash,交替播放
unit1.Form1.Fla.Movie:='C:\'+inttostr(unit1.Form1.iSwf)+'.swf';
unit1.Form1.Fla.Play();
unit1.Form1.IsSwfBusy:=false;
end;

end.


你快速次按后,就。而程很定,什么,怎么解?!

[解决办法]
不需要用线程



[解决办法]
用线程锁控制就不会出现线程冲突了,不过要确定你是否是因为线程冲突造成的

读书人网 >.NET

热点推荐