Generate a report using thread in the background

1

I want to generate a report, but I want the system to be freed for the user to do other activities while the report does not return. For this I am using thread, but when I close the form it is giving error because the thread needs form information and how it was closed it is no longer in memory.

Does anyone have any suggestions?

    
asked by anonymous 28.07.2015 / 14:17

1 answer

2

In the thread you can do a new implementation of constructor where you will pass all the data that it needs, so as to be independent of the form, which when destroyed, will not compromise Thread execution.

It looks like this:

interface
  TRelatoriorThread = class(TThread)
  public
    constructor Create(const aParam1: string; aParam2: Integer...);
  end;

implementation
  constructor TRelatoriorThread.Create(const aParam1: string; aParam2: Integer...);
  begin
    inherited Create;
    FParam1 := aParam1;
    FParam2 := aParam2;
    ...
  end;

So you prepare the thread and it runs independently of the object that started it, it could be form, datamodule or anything else that might ever exist.

    
28.07.2015 / 14:53