Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Problem Iterating controls
Thu, Jan 8 2015 7:40 PMPermanent Link

Roland

Hi

I am experimenting re-positioning controls in EWB 1.03 B7 using each control's tag property to store its design Top property.

In the following procedure, the iteration method doesn't work while the explicit method does. The iteration results in all the controls at the top of the client area with their Top property set to zero.

Am I doing something wrong here?

procedure TWrkActForm.SetTaskDetailPanel(Sender: TObject);
var
  AClientHeight: integer;
  DeltaHeight: integer;
  MinTop: integer;
  AClientWidth: integer;
  I: integer;
begin
  AClientHeight:= TaskDetailP.ClientHeight;
  DeltaHeight:= AClientHeight - TaskDetailP.Tag;
  AClientWidth:= TaskDetailP.ClientWidth;
  MinTop:= TaskDetail.Top + TaskDetail.Height;

  TaskDetail.Height:= TaskDetail.Tag + DeltaHeight;
  TaskDetail.Width:= AClientWidth - 10 - 20;
  TaskDocumentFile.Width:= AClientWidth - 10 - 20;
  Comments.Width:= AClientWidth - 10 - 20;
  ExpectedOutcome.Left:= Comments.Left + Comments.Width - ExpectedOutcome.Width;
  ExpectedOutcomeLable.Left:= ExpectedOutcome.Left;

// Does not work
//   for I:= 0 to TaskDetailP.ControlCount - 1 do
//      if TaskDetailP.Controls[I].Top > MinTop then
//         TaskDetailP.Controls[I].Top:= TaskDetailP.Controls[I].Tag + DeltaHeight;

  
// Works
  TaskDocumentFileLabel.Top:= TaskDocumentFileLabel.Tag + DeltaHeight;
  TaskDocumentFile.Top:= TaskDocumentFile.Tag + DeltaHeight;
  CommentsLabel.Top:= CommentsLabel.Tag + DeltaHeight;
  Comments.Top:= Comments.Tag + DeltaHeight;
  TaskOutcomeLabel.Top:= TaskOutcomeLabel.Tag + DeltaHeight;
  TaskOutcome1.Top:= TaskOutcome1.Tag + DeltaHeight;
  TaskOutcome2.Top:= TaskOutcome2.Tag + DeltaHeight;
  TaskOutcome3.Top:= TaskOutcome3.Tag + DeltaHeight;
  TaskOutcome4.Top:= TaskOutcome4.Tag + DeltaHeight;
  ExpectedOutcomeLable.Top:= ExpectedOutcomeLable.Tag + DeltaHeight;
  ExpectedOutcome.Top:= ExpectedOutcome.Tag + DeltaHeight;

end;
Fri, Jan 9 2015 4:33 AMPermanent Link

Matthew Jones

R. Verrinder wrote:

> //      if TaskDetailP.Controls[I].Top > MinTop then

That seems to be missing in the other lines.

FWIW, this is the code I have to iterate and clear a panel.

procedure ClearPanel(xForm : TForm; xClearPanel : TPanel);
var
   i: integer;
   c: TComponent;
begin
   for i := xForm.componentcount - 1 downto 0 do
   begin
       c := xForm.component[i];
       if TControl(c).parent = xClearPanel then
           c.free;
   end;
end;

I think I've had confusion in the past with TComponent and TControl.
That may have some impact on your situation.

But the main thing I've found is to add some basic reporting for debug
info. Then you can see exactly what is happening. So I'd have:

for I:= 0 to TaskDetailP.ControlCount - 1 do
 if TaskDetailP.Controls[I].Top > MinTop then
 begin
  Report('Changing [' + IntToStr(I) + ' to blah');
  TaskDetailP.Controls[I].Top:= TaskDetailP.Controls[I].Tag +
DeltaHeight;
 end
 else
 begin
  Report('NOT changing [' + IntToStr(I) + ' already at blah');
 end;

Obviously you probably remove it later, but it helps a lot. I use a
memo, in a panel on the right side that is normally hidden.

--

Matthew Jones
Sat, Jan 10 2015 3:17 AMPermanent Link

Roland

Hi Matthew and thanks for your response.

<<
But the main thing I've found is to add some basic reporting for debug
info. Then you can see exactly what is happening. So I'd have:

for I:= 0 to TaskDetailP.ControlCount - 1 do
 if TaskDetailP.Controls[I].Top > MinTop then
 begin
  Report('Changing [' + IntToStr(I) + ' to blah');
  TaskDetailP.Controls[I].Top:= TaskDetailP.Controls[I].Tag +
DeltaHeight;
 end
 else
 begin
  Report('NOT changing [' + IntToStr(I) + ' already at blah');
 end;

Obviously you probably remove it later, but it helps a lot. I use a
memo, in a panel on the right side that is normally hidden.
>>

I did this before but only for a single call to the procedure so I thought I'd try again, log everything and include all pertinent values. This revealed what is happening:

The procedure is called by the Panel's Resize Event which fires four times in this case (not all that surprising for a resize event).

The first call which I originally logged performs as expected however, in all the subsequent calls the crucial TaskDetailP.ClientHeight returns zero which subsequently moves the controls into negative territory.

The log of this activity is attached.

I am beginning to suspect this may be due to asynchronous behaviour in which case iteration should be used with some caution.

Roland

--

Matthew Jones



Attachments: EWB debug log.txt
Tue, Jan 27 2015 7:27 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< But the main thing I've found is to add some basic reporting for debug
info. >>

Use the LogOutput function in the WebHTTP unit for this:

  procedure LogOutput(const Msg: String;
                      const LogURL: String=DEFAULT_LOG_URL);

It will output the Msg parameter to the messages view in the IDE when
running the application.  It's especially beneficial because it works the
same even if you're running the application in an external browser like
Firefox outside of the IDE.  Just make sure the IDE is running and has the
same project loaded, and you'll get the messages.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com

Tue, Jan 27 2015 7:33 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roland,

<< In the following procedure, the iteration method doesn't work while the
explicit method does. The iteration results in all the controls at the top
of the client area with their Top property set to zero. >>

Can you send me a cut-down version of what you're doing as an example
project ?  The client height/width should be updated appropriately in real
time as the controls are resized, so I'm not sure what you're seeing.  But,
either way I need to run it here and examine exactly what's going on.

Thanks,

Tim Young
Elevate Software
www.elevatesoft.com
Sat, Jan 31 2015 8:30 PMPermanent Link

Roland

Tim

Thanks for your response.

I have solved this problem but have attached the cut down part of my experimental project anyway.

I have been experimenting with multiple nested panels to mimic a "scrolling panel" effect that provides the room for viewing on all devices down to the small tablet / Ipad level.

A simple escape exit was all I needed:
  {Escape fixes the problem}
  if AClientHeight = 0 then
     exit;

The problem was that the panel's resize event was being called  with a a client Height of zero (which I now see is appropriate) and subsequently disqualifying the appropriate controls from positioning in the iteration process.

This is now fixed with the escape above and works perfectly with the iteration code.

Please don't waste any more time on this as I too am desperately waiting for the release of EWB 2.
Roland



Attachments: Debug.zip
Image