Mega Search
23.2 Million


Sign Up

Make a donation  
Re: how to refresh/repaint/invalidate a component in firemon  
News Group: embarcadero.public.delphi.firemonkey

> {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

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 19-Jan-2012, at 8:02 AM EST
From: Stefan Baciu
 
Re: how to refresh/repaint/invalidate a component in firemon  
News Group: embarcadero.public.delphi.firemonkey
> {quote:title=Paolo Francesco Ingraito wrote:}{quote}
> I had a similar problem. Windows 32 bit behaves a bit differently from Windows 64 (on the same 32 bit exe)
> I managed to solve this using Canvas.Clear(0) method..

I am indeed running 32 bit. Your idea seems to help, but parts of the text go invisible sometimes. So I took your suggestion and then run through the items setting them to visible. This helps, but then I randomly get sections/all of the TListBox turning black. So this doesn't seem to be a full solution either. Here's my new code:
canvas.Clear($FFFFFF);  
for i := 0 to ListBox1.items.count-1 do
  ListBox1.ItemByIndex(i).Visible:= true;

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 20-Jan-2012, at 1:54 PM EST
From: Daryl Erwin