To all of the implementation tips/observations aside, I would add the following:
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. 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. This may not be a concern in your case, but then again it might be. :) 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. On 12 October 2016 at 12:27, Barry Neale <[email protected]> wrote: > The simplest way is just to have definition in the interface and then copy > what you have to the implementation > > unit Unit1; > > interface > > You'll need to use a few units to find the reference to TForm etc > > procedure FormScale (rHeiScale:real; rWidScale:real; sForm:tForm); > > implementation > > > procedure FormScale (rHeiScale:real; rWidScale:real; sForm:tForm); > var > i:integer; > rWidth,rHeight:real; > begin > with sForm do begin > rHeight:=rHeiScale*(Screen.Height/Height); // Scale form > rWidth:=rWidScale*(Screen.Width/Width); > Height:=Round(Height*rHeight); > Width:=Round(Width*rWidth); > Left:=Round((Screen.Width-Width)/2); // Center form > Top:=Round((Screen.Height-Height)/2); > for i:=0 to componentcount-1 do > if Components[i] is TControl then begin > TControl(Components[i]).Top := > Round(TControl(Components[i]).Top*rHeight); > TControl(Components[i]).Width := > Round(TControl(Components[i]).Width*rWidth); > TControl(Components[i]).Height := > Round(TControl(Components[i]).Height*rHeight); > TControl(Components[i]).Left := > Round(TControl(Components[i]).Left*rWidth); > end; > end; > end; > > end. > > A slightly different way would be to make a class, then have a class > function in the interface. > Ie: > > type > > TWallacesFormResize = TObject > public > class procedure FormScale (rHeiScale:real; rWidScale:real; > sForm:tForm); > end; > > Then to call it for a form it's > > TWallacesFormResize.FormScale(parameters) > > > > On Wed, Oct 12, 2016 at 11:10 AM, Marshland Engineering < > [email protected]> wrote: > >> When I put it in the interface unit, it added a uses statement before it >> with >> the forms included in it and each time I compiled it added more and more >> bits >> in. >> >> >Why not just put it in it's own unit (or a common utilities unit) and >> include >> it in any form that needs it, rather than having it in the mainform >> unit >> >> I like this idea but not sure how to implement it and how to call it. >> >> Adding a blank unit, I have >> >> unit Unit1; >> >> interface >> >> implementation >> >> end. >> >> Thanks Wallace. >> >> >> _______________________________________________ >> NZ Borland Developers Group - Delphi mailing list >> Post: [email protected] >> Admin: http://delphi.org.nz/mailman/listinfo/delphi >> Unsubscribe: send an email to [email protected] with >> Subject: unsubscribe >> > > > _______________________________________________ > NZ Borland Developers Group - Delphi mailing list > Post: [email protected] > Admin: http://delphi.org.nz/mailman/listinfo/delphi > Unsubscribe: send an email to [email protected] with > Subject: unsubscribe >
_______________________________________________ NZ Borland Developers Group - Delphi mailing list Post: [email protected] Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to [email protected] with Subject: unsubscribe
