BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TIdTCPClient within dll and use of TIdAntiFreeze

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Matej
Guest





PostPosted: Wed Oct 29, 2003 9:26 am    Post subject: TIdTCPClient within dll and use of TIdAntiFreeze Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.