[Lazarus] TListView.Items.Count property R/W?

Lee Jenkins lee at datatrakpos.com
Fri May 16 05:16:26 CEST 2008


Bill de Carle wrote:
> I would like to add a feature to my application but can't figure out 
> how to do it.
> Basically, when the user clicks on a button in Form1 I'd like a new 
> window to open
> up somewhere else on the desktop.  This new window is only for 
> displaying lines of
> text which I already have as strings in RAM.  As each new item is 
> entered via Form1
> I'll send one line of text to the new window, appending it to 
> whatever is already
> displayed in that window.  The new window should have a vertical 
> scroll bar in case
> the number of lines becomes too large to view all at once.  The user 
> should have the
> ability to operate the scroll bar and to click on a red X at the top 
> right corner of
> the new window to close it when he gets tired of seeing it.  Of 
> course, my code will
> need a way to learn when the new window has been closed by the user 
> so I don't keep
> sending additional lines to it.  I've seen this feature on several 
> Windows programs
> so it must be already in the can somewhere.  I don't know enough of the Windows
> jargon and I have no idea what the accepted name of such a component 
> might be.  I
> thought I might be able to use a Tlistbox widget on a separate form 
> but when I asked
> Lazarus to open a new form it automatically created a new unit as 
> well and everything
> got more complicated.  Can someone please provide a hint or tell me 
> the name of the
> component I need?  Perhaps there is an example somewhere.
> Thanks in advance,

1) In the IDE create form1 and design it as you like.
2) Create form2 and put a listbox (or memo) on it with Align=alClient
3) In project options, forms tab, remove form2 from auto create
4) in the implementation part of unit1, add: uses unit2;
5) Add a member variable to form1: FDisplayForm: Tform;
6) Add a method to form1: procedure Form1Destroy(Sender: TObject);
7) in your Form1.button1click, call something like
     FDisplayForm := TForm2.Create(Self);
     FDisplayForm.OnDestroy := @Form1Destroy
     FDisplayForm.Memo1.Lines.Text := 'your text here';
     FDisplayForm.Show
8) in your Form1.Form1Destroy put:
     FDisplayForm := nil;
9) In the code where you want to add data to the memo:
     if FDisplayForm <> nil
     then FDisplayForm.Memo1.Lines.Add('a new line');
10) run

ofcoarse step 7 and 9 can be bautified when a method
   AddText(AText: String);
is added to Form2

Marc




More information about the Lazarus mailing list