1
I’m trying to make a Windows service in the Delphi 10.2 and in one of the procedure
I need to create a TMemo
only when I execute this error below.
Project AutoPub.exe raised exception class EInvalidOperation with message 'Control 'TMemo($043A90C0)' has no parent window. Path: TServiceApplication($03164E50) .svcAutoPub <br> .TMemo($043A90C0)'
I’ll put the part where the error occurs.
procedure TsAutoPub.GetPublicacoes(var Nome: string; Token, Cod: string; Periodo: TDate);
var
Data: string;
begin
Data := StringReplace(DateToStr(Date()),'/','-',[rfReplaceAll]);
==> MemoJson := TMemo.Create; // Aqui onde da o erro!!
GETRequest.Params.Items[0].Value := NomeRelacional;
GETRequest.Params.Items[1].Value := Token;
GETRequest.Params.Items[2].Value := CodEscritorio;
GETRequest.Params.Items[3].Value := FormatDateTime('yyyy-mm-dd', Periodo);
GETRequest.Params.Items[4].Value := FormatDateTime('yyyy-mm-dd', Periodo);
try
try
GETRequest.Execute;
finally
MemoJson.Lines.Clear;
MemoJson.Lines.Add('{"Publicações":'+#13+GETResponse.JSONText+'}');
if not DirectoryExists(tbParametosPASTA_BD.AsString+'\Publicações') then
CreateDir(tbParametosPASTA_BD.AsString+'\Publicações');
MemoJson.Lines.SaveToFile('C:\Autosad\Banco\Publicações - '+Data+'.json');
end;
except on E: ERESTException do
ShowMessage(IntToStr(GETResponse.StatusCode) + ':' + GETResponse.StatusText);
end;
end;
I wanted to know how to create this TMemo
in the windows service correctly.
or where the error is in the code.
As stated by Leonardo Getulio, use the
TStrings
that will serve your purpose.– Matheus Ribeiro