H
himoo
Unregistered / Unconfirmed
GUEST, unregistred user!
详细情况是这样的一、使用【咏南插件框架】的主程序,插件自己按照向导创建了一个,并加入在Application中能用的相关多线程代码,结果如下:unit VisualPlugin;interfaceuses {vcl:} Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, {Hydra:} uHYVisualPlugin, uHYIntf;type TNewVisualPlugin = class(THYVisualPlugin) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private protected public end;//begin自己增加的var Form1: TNewVisualPlugin; hThread:Thandle;//定义一个句柄 ThreadIDWord;//endimplementationuses {Hydra:} uHYPluginFactories;{$R *.dfm}//自己增加的函数function MyThreadFunc(Pointer):Longint;stdcall;vari:longint;beginform1.Label1.Caption:='0';for i:= 0 to 50000 do begin form1.Label1.Caption:=inttostr(i); end;end;procedure Create_NewVisualPlugin(out anInstance: IInterface);begin anInstance := TNewVisualPlugin.Create(NIL);end;resourcestring sDescription = '';const sRequiredPrivilege = ''; sUserData = '';procedure TNewVisualPlugin.Button1Click(Sender: TObject);begin hthread:=CreateThread(nil,0,@MyThreadfunc,nil,0,ThreadID);end;initialization THYPluginFactory.Create(HInstance, 'NewVisualPlugin', Create_NewVisualPlugin, TNewVisualPlugin, 1, 0, sRequiredPrivilege, sDescription, sUserData);end.运行后,报错: project c:/xxxx/host.exe faulted with message :'access violation at 0x06b1203e:read of address 0x00000354'. 二、不在主窗体中建立,使用Thread Object 建立该线程代码。unit VisualPlugin;interfaceuses {vcl:} Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, {Hydra:} uHYVisualPlugin, uHYIntf;type TNewVisualPlugin = class(THYVisualPlugin) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private protected public end;var Form1: TNewVisualPlugin; hThread:Thandle;//定义一个句柄 ThreadIDWord;implementationuses {Hydra:} uHYPluginFactories,Unit1;{$R *.dfm}function MyThreadFunc(Pointer):Longint;stdcall;vari:longint;beginform1.Label1.Caption:='0';for i:= 0 to 50000 do begin form1.Label1.Caption:=inttostr(i); end;end;procedure Create_NewVisualPlugin(out anInstance: IInterface);begin anInstance := TNewVisualPlugin.Create(NIL);end;resourcestring sDescription = '';const sRequiredPrivilege = ''; sUserData = '';procedure TNewVisualPlugin.Button1Click(Sender: TObject);begin //hthread:=CreateThread(nil,0,@MyThreadfunc,nil,0,ThreadID); test.Create(false);end;initialization THYPluginFactory.Create(HInstance, 'NewVisualPlugin', Create_NewVisualPlugin, TNewVisualPlugin, 1, 0, sRequiredPrivilege, sDescription, sUserData);end.===============unit Unit1;interfaceuses Classes,Windows,SysUtils;type test = class(TThread) private { Private declarations } protected procedure Execute; override; end;implementationuses VisualPlugin;{ Important: Methods and properties of objects in visual components can only be used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure test.UpdateCaption; begin Form1.Caption := 'Updated in a thread'; end; }{ test }procedure test.Execute;vari:longint;beginform1.Label1.Caption:='0';for i:= 0 to 50000 do begin form1.Label1.Caption:=inttostr(i); end;end;end.执行后不会报错,不过运行到 form1.Label1.Caption:='0'; 就直接跳出了,没有任何提示,也不报错,但就是不执行该句话,及后面的话。请问为什么啊?怎么弄呢?或者说,有没有使用多线程的方法?谢啦