I'm having trouble sending text messages from a Client Socket . The form that sends the text is always displayed above the form that always stays on the top, when FormOnTop
does not exist (not shown), works fine, since FormOnTop
exists and form that sends the text is displayed above the FormOnTop
, the submission fails, and the text (message) does not even exit Client.exe from my software.
Is there a solution to this?
To understand better, I'll leave below the code I use:
Form containing Client Socket component:
unit Unit1;
interface
uses
FormSender;
type
......
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CS1Read(Sender: TObject; Socket: TCustomWinSocket);
var
StrCommand: String;
begin
StrCommand := Socket.ReceiveText;
if Pos('<|Command_From_Server|>', StrCommand) > 0 then
begin
FormSender.PopupMode:= pmExplicit;
FormSender.PopupParent:= FormOnTop;
FormSender.Show;
end;
end;
end.
Form that sends the text (FormSender) and appears above the form that always remains at the top:
unit FormSender;
interface
uses
Unit1;
type
......
end;
var
FormSender: TFormSender;
implementation
{$R *.dfm}
procedure TFormSender.Button1Click(Sender: TObject);
begin
Form1.CS1.Socket.SendText('<|Hello_To_Server|>' + Edit1.Text + '<<|);
end;
end.
Form that always stays on top:
NOTE: The FormStyle property is: fsStayOnTop
.
unit FormOnTop;
interface
uses
.......
type
......
end;
var
FormOnTop: TFormOnTop;
implementation
{$R *.dfm}
procedure TFormOnTop.FormCreate(Sender: TObject);
begin
{ Position form }
Top := 0 ;
Left := 0 ;
{ Go full screen }
BorderStyle := bsNone ;
WindowState := wsmaximized;
ClientWidth := Screen.Width ;
ClientHeight := Screen.Height;
Refresh;
SetForegroundWindow(Handle) ;
SetActiveWindow(Application.Handle);
end;
procedure TFormOnTop.CreateParams(var Params: TCreateParams);
begin
inherited;
if (FormStyle = fsStayOnTop) then begin
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := GetDesktopWindow;
end;
end;
procedure TFormOnTop.FormShow(Sender: TObject);
begin
SetWindowPos(FormOnTop.handle, HWND_TOPMOST, FormOnTop.Left, FormOnTop.Top, FormOnTop.Width, FormOnTop.Height, 0);
end;
end.