Forum > Carbon

How do I create a form to show up as a dialog seen with other Mac apps?

<< < (2/2)

Hansaplast:
Yeah, I figured that there would be limitations, but so far I can't really complain too much :)
I think Lazarus/FPC is great  8)
I can use my Delphi experience, in a programming language that I really like, and the few little tools I create can be used on at least 3 platforms if I pay enough attention - and I think it's worth it :)

I hope one of these days I can contribute more than just finding "issues" and bugs ;)

Hansaplast:
I figured I'll mimic this behavior by aligning the "form" to the main form, only to find out that the windows function GetSystemMetrics(SM_CYCAPTION) does not seem to return anything useful (0 under carbon?).

So I'm using a trick that "might" work for other platforms as well (probably not as clean as it should be, but it might be helpful to someone);

First I created a form (form2) with borderstyle=bsNone, FormStyle=fsSplash, position=poDesigned - in this form a "busy" indicator.

Next I had quite a challenge determining the titlebar height of the main form (form1), but this trick seems to work ...

1) find a visible object on the main form (form1), say label1 for argument sake. Avoid objects like TPageControl, TGroupBox, etc as they can have an unexpected outcome.

2) Create an onChangeBounds event of the main form (calls this at onShow of the main form at least once to get an initial proper position):


--- Code: ---procedure Form1.FormChangeBounds(Sender: TObject);
var myPoint:TPoint;
begin
  myPoint := Label1.ClientToScreen(Point(0,0));
  Form2.Top:=myPoint.Y - Label5.Top; // proper alignment, snug under the titlebar
  Form2.Left:=self.Left+(self.Width DIV 2)-(Form2.width DIV 2); // center the form to the main form
end;   
--- End code ---
   

Now myPoint.Y gives the absolute position of Label1 (of Form1) on the screen, and we know the top of that object (label1), which is related to the workable area of Form1 -> we now know what Top of Form2 should be :)

Works like a charm ... :)

Edit: This doesn't look all that great in Windows though. Might need to set border style to bsSingle.

Hansaplast:
@Phil:
Thank you for taking the effort to write http://web.me.com/macpgmr/ObjP/MacXPlatform_Intro.html
It has been very informative!  :)

Phil:

--- Quote from: Hansaplast on January 27, 2011, 08:03:14 pm ---@Phil:
Thank you for taking the effort to write http://web.me.com/macpgmr/ObjP/MacXPlatform_Intro.html

--- End quote ---

You're welcome. The idea was to capture some of what I was discovering. If I didn't write it down, soon I'd forget half of it and then it wouldn't be of much use to anyone, not even to myself.

I would encourage anyone on this forum to write up little articles like this when you discover something that you think others might find interesting or useful. I wouldn't worry about writing it in English if you're not comfortable doing that. Write it in whatever language you have and hope that someone translates it for you.

For example, I wrote this topic on the Laz wiki years ago:

http://wiki.lazarus.freepascal.org/Overview_of_Free_Pascal_and_Lazarus

I'm still in awe at how many times this has been translated (14 by my count). Talk about unsung heroes! To take the time to do that is really commendable.

Anyone can add articles to the wiki. Just keep in mind some of the rough guidelines for any wiki:
 - Don't post someone else's work or copyrighted material.
 - Remember that others might edit your work to improve (or ruin) it.
 - Use a faux-objective writing "voice" like what an encyclopedia uses.
 - Short and sweet is fine.

Thanks.

-Phil

Navigation

[0] Message Index

[*] Previous page

Go to full version