[Lazarus] Find Form instance with Title

Timothy Groves the.tail.kinker at gmail.com
Sat Nov 16 05:48:33 CET 2013


On 13-11-15 11:13 PM, K. P. wrote:
> Look at your Screen object:
>
> http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tscreen.html
>
> Check out FindForm and Forms
>
>
>
> > Date: Fri, 15 Nov 2013 22:32:37 -0500
> > From: the.tail.kinker at gmail.com
> > To: lazarus at lists.lazarus.freepascal.org
> > Subject: [Lazarus] Find Form instance with Title
> >
> > Google has failed me on this one. :( I need to check to see if a
> > dynamically created form (object) with a given title already exists
> > within the application, and if so, to raise it to the front.
Thanks for the steer!  In case anyone cares, here's how I implemented this:

procedure TfrmVolume.lstVolumesDblClick (Sender : TObject );
var
   NewStoryForm : TfrmStory;
   FormCaption : string;
   index : integer;
   Present : boolean;
begin
     FormCaption := 'Volume "' + Volumes.Current.VolumeName + '"'; // 
The caption I want to search for/create.
   index := 0;
   Present := false;
   repeat
     if (Screen.Forms [index].Caption = FormCaption) then
       Present := true
     else
         index += 1;
   until (Present or (index >= Screen.FormCount));
   if (Present) then
     Screen.Forms [index].BringToFront
   else begin
     NewStoryForm := TfrmStory.Create (Application);
     NewStoryForm.Caption := FormCaption;
     NewStoryForm.Show;
   end;
end;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20131115/eec53184/attachment-0003.html>


More information about the Lazarus mailing list