Re: how to refresh/repaint/invalidate a component in firemon |
|
> {quote:title=Daryl Erwin wrote:}{quote}
> > {quote:title=Stefan Baciu wrote:}{quote}
> > > {quote:title=Daryl Erwin wrote:}{quote}
> > > I've tried to apply the suggestions in this thread to my solve my problem, but it's not working. I have a FireMonkey TListBox that won't repaint. I've tried:
> > > ListBox1.InvalidateRect(RectF(0,0,width,height));
> > > ListBox1.Realign;
> > > Application.ProcessMessages;
> > > Application.HandleMessage;
> > > None of the above work. Any thoughts?
> > >
> > >
> > > > {quote:title=Peter Wichenthaler-Sternbach wrote:}{quote}
> > > > > {quote:title=Dominique Willems wrote:}{quote}
> > > > > Peter Wichenthaler-Sternbach wrote:
> > > > > > button1.Text := inttostr(i);
> > > > >
> > > > > Compromise, but fast, is to use
> > > > >
> > > > > button1.Text := inttostr(i);
> > > > > Application.HandleMessage
> > > > >
> > > > > No Repaint necessary.
> > > >
> > > > Super - many thanks - this is really working. I haven't noticed that Application.ProcessMessages
> > > > & co is aboard in Firemonkey now...
> >
> > Hello,
> >
> > Well if you want to repaint the form while still in executing the callback of a button, you shall start a new Thread, because the callback actualy blocks your interface.
> >
> > Stefan
>
> I'm not sure I follow what you mean. I'll give a little more detail. I've built a simple client/server chat program. A message comes in from the client, which is displayed in TListBox. Then the server app waits until a TCheckBox is checked, then sends a response back to the client, and displays it response in its TListBox. Here's my procedure:
> procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
> var str: string;
> begin
> str:= AContext.Connection.IOHandler.ReadLn();
> ListBox1.Items.Add(AContext.Connection.Socket.Binding.PeerIP + ':' + IntToStr(AContext.Connection.Socket.Binding.PeerPort) + ': ' + str);
> ListBox1.ItemIndex:= ListBox1.Items.Count -1;
> while not DoneCheck.IsChecked do
> Delay(500);
> AContext.Connection.IOHandler.WriteLn(ReplyEdit.Text);
> ListBox1.Items.Add('Me: ' + ReplyEdit.Text);
> ListBox1.ItemIndex:= ListBox1.Items.Count -1;
> DoneCheck.IsChecked:= False;
> end;
Well, try this out, for me it works,
unit Unit2;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, IdContext, IdBaseComponent,
IdComponent, IdCustomTCPServer, IdTCPServer, FMX.Layouts, FMX.ListBox,
FMX.Edit;
type MyThread = class(TThread)
protected
procedure Execute; override;
public
AContext: TIdContext;
constructor Create; overload;
destructor Destroy; override;
end;
type
TForm2 = class(TForm)
DoneCheck: TCheckBox;
ListBox1: TListBox;
IdTCPServer1: TIdTCPServer;
ReplyEdit: TEdit;
procedure IdTCPServer1Execute(AContext: TIdContext);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.fmx}
constructor MyThread.Create;
begin
inherited Create(true); // suspended to allow creation of stuff before run
FreeOnTerminate := true;
end;
destructor MyThread.Destroy;
begin
inherited;
end;
procedure MyThread.Execute;
var
str : string;
host : string;
port : string;
begin
while NOT Form2.DoneCheck.IsChecked do
Sleep(500);
AContext.Connection.IOHandler.WriteLn(Form2.ReplyEdit.Text);
Form2.ListBox1.Items.Add('Me: ' + Form2.ReplyEdit.Text);
Form2.ListBox1.ItemIndex:= Form2.ListBox1.Items.Count -1;
Form2.DoneCheck.IsChecked:= False;
end;
procedure TForm2.IdTCPServer1Execute(AContext: TIdContext);
var str: string;
MT : MyThread;
begin
str:= AContext.Connection.IOHandler.ReadLn();
ListBox1.Items.Add(AContext.Connection.Socket.Binding.PeerIP + ':' + IntToStr(AContext.Connection.Socket.Binding.PeerPort) + ': ' + str);
ListBox1.ItemIndex:= ListBox1.Items.Count -1;
MT := MyThread.Create;
MT.AContext:=AContext;
MT.Start;
end;
end.
Regards,
Stefan
|
Re: how to refresh/repaint/invalidate a component in firemon |
|