<div dir="ltr">To all of the implementation tips/observations aside, I would add the following:<br><br>Any scaling based on simply modifying current values and using floating point and rounding is going to suffer from asymmetry and creeping rounding issues if forms are frequently scaled and rescaled.<br><br>Asymmetry I mean that - for example - applying a scale of 3.0x to a form will not necessarily be exactly undone by then applying a scale of (1 / 3) x (0.333333333333x). Recurring decimals are the most obvious case where problems are likely to occur, but the nature of floating point representation means that they are not the only ones.<div><br></div><div>This may not be a concern in your case, but then again it might be. :)<br><br>A more robust approach would be to establish reference dimensions for each form (the "1 x" dimensions) and to always scale with respect to those reference dimensions.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 12 October 2016 at 12:27, Barry Neale <span dir="ltr"><<a href="mailto:Barry.Delphi@gmail.com" target="_blank">Barry.Delphi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The simplest way is just to have definition in the interface and then copy what you have to the implementation<div><br></div><div>unit Unit1;<br></div><div><br>interface<br><br> You'll need to use a few units to find the reference to TForm etc<br><br><div><span style="font-size:12.8px">procedure FormScale (rHeiScale:real; rWidScale:real; sForm:tForm);</span><br></div><div><span style="font-size:12.8px"><br></span></div>implementation<br><br><br><span style="font-size:12.8px">procedure FormScale (rHeiScale:real; rWidScale:real; sForm:tForm);</span><br style="font-size:12.8px"><span style="font-size:12.8px">var</span><br style="font-size:12.8px"><span style="font-size:12.8px"> i:integer;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> rWidth,rHeight:real;</span><br style="font-size:12.8px"><span style="font-size:12.8px">begin</span><br style="font-size:12.8px"><span style="font-size:12.8px"> with sForm do begin</span><br style="font-size:12.8px"><span style="font-size:12.8px"> rHeight:=rHeiScale*(Screen.</span><span style="font-size:12.8px">Hei<wbr>ght/Height); // Scale form</span><br style="font-size:12.8px"><span style="font-size:12.8px"> rWidth:=rWidScale*(Screen.</span><span style="font-size:12.8px">Widt<wbr>h/Width);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Height:=Round(Height*rHeight);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Width:=Round(Width*rWidth);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Left:=Round((Screen.Width-</span><span style="font-size:12.8px">Widt<wbr>h)/2); // Center form</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Top:=Round((Screen.Height-</span><span style="font-size:12.8px">Heig<wbr>ht)/2);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> for i:=0 to componentcount-1 do</span><br style="font-size:12.8px"><span style="font-size:12.8px"> if Components[i] is TControl then begin</span><br style="font-size:12.8px"><span style="font-size:12.8px"> TControl(Components[i]).Top :=</span><br style="font-size:12.8px"><span style="font-size:12.8px">Round(TControl(Components[i]).</span><span style="font-size:12.8px"><wbr>Top*rHeight);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> TControl(Components[i]).Width :=</span><br style="font-size:12.8px"><span style="font-size:12.8px">Round(TControl(Components[i]).</span><span style="font-size:12.8px"><wbr>Width*rWidth);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> TControl(Components[i]).Height :=</span><br style="font-size:12.8px"><span style="font-size:12.8px">Round(TControl(Components[i]).</span><span style="font-size:12.8px"><wbr>Height*rHeight);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> TControl(Components[i]).Left :=</span><br style="font-size:12.8px"><span style="font-size:12.8px">Round(TControl(Components[i]).</span><span style="font-size:12.8px"><wbr>Left*rWidth);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> end;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> end;</span><br style="font-size:12.8px"><span style="font-size:12.8px">end;</span><br><br>end.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">A slightly different way would be to make a class, then have a class function in the interface.</div><div class="gmail_extra">Ie:</div><div class="gmail_extra"><br></div><div class="gmail_extra">type</div><div class="gmail_extra"><br></div><div class="gmail_extra">TWallacesFormResize = TObject</div><div class="gmail_extra">public</div><div class="gmail_extra"> class <span style="font-size:12.8px">procedure FormScale (rHeiScale:real; rWidScale:real; sForm:tForm);</span></div><div class="gmail_extra"><span style="font-size:12.8px">end;</span></div><div class="gmail_extra"><br></div><div class="gmail_extra">Then to call it for a form it's</div><div class="gmail_extra"><br></div><div class="gmail_extra">TWallacesFormResize.<span style="font-size:12.8px">FormScale(<wbr>parameters)</span><br></div><div class="gmail_extra"><span style="font-size:12.8px"><br></span></div><div class="gmail_extra"><span style="font-size:12.8px"><br></span></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 12, 2016 at 11:10 AM, Marshland Engineering <span dir="ltr"><<a href="mailto:marshland@marshland.co.nz" target="_blank">marshland@marshland.co.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">When I put it in the interface unit, it added a uses statement before it with<br>
the forms included in it and each time I compiled it added more and more bits<br>
in.<br>
<span class="m_-2854606191717217672gmail-"><br>
>Why not just put it in it's own unit (or a common utilities unit) and include<br>
it in any form that needs it, rather than having it in the mainform<br>
unit<br>
<br>
</span>I like this idea but not sure how to implement it and how to call it.<br>
<br>
Adding a blank unit, I have<br>
<br>
unit Unit1;<br>
<br>
interface<br>
<br>
implementation<br>
<br>
end.<br>
<br>
Thanks Wallace.<br>
<div class="m_-2854606191717217672gmail-HOEnZb"><div class="m_-2854606191717217672gmail-h5"><br>
<br>
______________________________<wbr>_________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" rel="noreferrer" target="_blank">http://delphi.org.nz/mailman/l<wbr>istinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz" target="_blank">delphi-request@listserver.123.<wbr>net.nz</a> with Subject: unsubscribe<br>
</div></div></blockquote></div><br></div></div>
<br>______________________________<wbr>_________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" rel="noreferrer" target="_blank">http://delphi.org.nz/mailman/<wbr>listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.<wbr>net.nz</a> with Subject: unsubscribe<br></blockquote></div><br></div>