It seems like you are receiving the server's response asynchronously. In which case, I would suggest not waiting for the response at all. Send the request, and then move on. Let the asynchronous handler notify your code whenever the response actually arrives. You can always disable the UI in the meantime, if needed.
Otherwise, if you must make the function act synchronously, even though the response is asynchronous, then at least consider waiting on a TEvent instead of a boolean, eg:
function GetTCPIPC(const msg: string): string;
begin
if not clientclass.Connected then
begin
Result := '';
Exit;
end;
clientclass.MsgEvent.Reset;
idTCPClient.IOHandler.WriteLn(msg);
while clientclass.MsgEvent.WaitFor(10) <> wrSignaled do
Application.ProcessMessages;
Result := clientclass.msgfromserver;
end;
Otherwise, consider changing the function to read the response directly in the function itself, not asynchronously from elsewhere. That way, you can place a TIdAntiFreeze component on your Form to keep the UI responsive while the TCP socket is blocking the UI thread, eg:
function GetTCPIPC(const msg: string): string;
begin
if not clientclass.Connected then
begin
Result := '';
Exit;
end;
IdTCPClient.IOHandler.WriteLn(msg);
//read response here
Result := msgfromserver;
end;
Though, you really should not be doing socket I/O in the UI thread at all. Consider a threaded approach, similar to what ioan showed earlier.