我在關閉應用程序窗體時遇到了EAccessViolation,我不知道如何處理這個問題,我有兩個單元,這裏是主要單元的相關代碼:如何處理關閉窗體時的EAccessViolation
unit MainUnit;
uses
.., myComponent1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MyComponent1.doSomeWork(p1, p2, ..., pn);
end;
procedure TForm1.OnMyComponen1tEvent(sender: TObject; p: Integer);
begin
memo1.Lines.Add(message);
end;
end.
本機使用另一個單元是組件類,其中我將信號發送到memo1使用組件事件顯示過程的消息,它的東西,如:
unit myComponent;
type
TMyComponentEvent = procedure(sender: TObject; p: integer) of object;
type
TMyComponent = class(TComponent)
// Properties and events declaration
procedure TPThread.Execute;
begin
try
// Create and run some worker threads
// Wait for them to finish the job
// This is the last thing to do:
if Assigned(FOnMyComponentEvent) then
begin
FOnMyComponentEvent(Self, p);
end;
finally
//free ressources
end;
end;
procedure TMyComponent.DoSomeWork;
begin
TPThread.Create(p1, p2 ...);
end;
end.
當我關閉在程序完成其工作之前的形式(線程仍在工作),我明白了這一點但有時候,沒有例外。那麼,當異常被提出時,它表示該行:memo1.Lines.Add(message);
。 我不知道如何解決它,所以如何防止發生異常?
他們已被銷燬後,不要訪問的對象。如果您需要如何實現這一目標的幫助,我們希望看到一些代碼。 –