 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Matej Guest
|
Posted: Wed Oct 29, 2003 9:26 am Post subject: TIdTCPClient within dll and use of TIdAntiFreeze |
|
|
I put TIdCTCPClient withing dll to send particular file to server. Now I'm
experiencing random crashes when I want to call this function from a form in
Delphi.
Function within dll is:
function SendFile(FileName: PChar): boolean;
var
ini: TIniFile;
sPort: string;
sHost: string;
SResponse: string;
FStream: TFileStream;
KVM_Client: TIdTCPClient;
begin
Result:= true;
if not FileExists(FileName) then
begin
Result:= false;
end else
begin
try {KVMCSENV.SendFile}
ini:= TIniFile.Create(ExtractFileDir(ParamStr(0)) + '' +
'KVM_Client.ini');
sPort:= ini.ReadString('Client', 'Port', '');
sHost:= ini.ReadString('Client', 'Host', '');
ini.Free;
FStream:= TFileStream.Create(FileName, fmOpenRead);
KVM_Client:= TIdTCPClient.Create(Application);
try {KVMCSENV.SendFile}
with KVM_Client do
begin
Port:= StrToInt(sPort);
Host:= sHost;
Connect;
WriteLn(ExtractFileName(FileName));
WriteStream(FStream, True, True, 0);
Disconnect;
end; { end of KVM_IdTCPClient }
KVM_Client.Free;
except
on e:exception do
begin
Result:= false;
end;
end; {end of KVMCSENV.SendFile}
FStream.Free;
except
on e:exception do
begin
Result:= false;
end;
end; {end of KVMCSENV.SendFile}
end; {end of FileExists}
end; {end of SendFile}
In a delphi form I have TOpenDialog and when it is executed it calls this
function: SendFile(PChar(OpenDialog1.FileName))
Sometimes it work with no problem. But sometimes application freezes and
when I open taskmanager i see 100% percent cpu usage. But server still gets
specified file.
There is something odd here. If I call my application with a parameter send
and I specifie a file then it does not create a form but it just call
SendFile function, the application does not freeze.
How come?
And the code in dpr file:
begin
Application.Initialize;
if ParamStr(1) = '--test' then
begin
Application.CreateForm(TFormClientTest, FormClientTest);
end else
if ParamStr(1) = '--send' then
if ParamCount = 2 then
begin
SendFile(Pchar(ParamStr(2)))
end;
Application.Run;
end;
I have read Indy help and it says that ff calls are made in the main thread
this will cause the Application User Interface to "freeze" during Indy
calls.
Can my problem be solved with use of TIdAntiFreeze? I tried to put on a form
but it does not work. So my suggestion was that I must include AntiFreeze
within dll function.
In uses clause of dll I added IdAntiFreezeBase, IdAntiFreeze. In SendFile
function I added TIdAntiFreeze within var block. I also added
AntiFreeze:= TIdAntiFreeze.Create(Application);
And at the end of the function:
AntiFreeze.Free;
But it does not work.
Am I something missing here or what? I just don't get it.
Can someone help me please!
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|