Forum > LCL

NBPages in TabControl... what for?

<< < (2/3) > >>


Doesn't that go against the suggested behaviour as described in


--- Quote --- ... the control always shows the same page whichever tab is selected. In fact, it containts only a single page. The idea behind this concept is illustrated best by an editor or viewer for text files: When the TabControl contains a TMemo then the individual tabs refer to the files loaded into the memo; whenever the active tab changes another file is loaded into the (same) memo.
--- End quote ---

if you are simply using it as a Memo viewer then can't you simply put a single instance of a memo
on the single page and then simply load that single memo via a TStringList that is already preloaded with all the files or, have the List hold the file paths to each one ?

 You can react on the Tab Change by reloading the single memo that reflects the tab that is currently in view.

I would not "abuse" the internal structure of the TTabControl to store the contents of the memo, too complicated stuff...

Rather than that, I'd use an external list or array to store the memo's Line.Text in the TabControl's OnChanging event and restore it on the OnChange event. A TStringList to take the text on the current tab is fine. Extra code is required to keep the tabs and this stringlist in sync when tabs are added and deleted (or moved).

See attached demo.

But note: this code saves/restores only the contents of the memo, scroll bar positions and caret positions are not stored. If you need this, I strongly recommend Bart's proposal to use a TPageControl and add a new memo on each tab.



Because this would not permit me to easily edit multiple files
and i would lose the caret's position on each reload...

I add the file and it's name (and any other wanted property)
 in a tabControl.tabs.addObject as an item of a TList
and swap the TStringList with the memo.lines at TabControlChange

I thought at first glance that those NBCustomPages
could permit the same kind of operations
and so, am now investigating


our posts just crossed

your solution is in the same line as what I actually use


I still haven't find the answer
explaining the presence and/or purpose and usage
of the NPCustomPages
which are offered as public in the interface

Thanks for the demo

I don't like using TPageControl for an editor type application
I prefer if needed, attaching TMemos directly to the tabs (as objects)
and assigning their visibility to the TabControl's tabIndex


[0] Message Index

[#] Next page

[*] Previous page

Go to full version