Recent

Author Topic: NBPages in TabControl... what for?  (Read 935 times)

polpero

  • Full Member
  • ***
  • Posts: 102
NBPages in TabControl... what for?
« on: March 19, 2023, 01:43:11 pm »
Hi

I'm trying to maximise usage of the TTabControl...

I've setup a TabControl and a TMemo to load various text files
adding a new tab for each file...

I thought that I could use pages.text (NBCustomPage)
to buffer the content of the TMemo when not selected (tabIndex)
but it doesn't seem to work that way?

What is the purpose of TNBPages in the TabControl?
Are there any demos/docu on the subject?

Thanks

jamie

  • Hero Member
  • *****
  • Posts: 5332
Re: NBPages in TabControl... what for?
« Reply #1 on: March 19, 2023, 04:39:04 pm »
its more of a runtime thing.

If you add a page to pages, then it has a page attached to the stretched down page of the Tab control.

 using the TabToPage or PageToTab functions you can link them,
 
 Also, using PAGE[index] will give you the Page control, from that I believe you can add items to it as child controls etc.

  That is what i got out of it from playing around.

  The problem is that you can have more pages than tabs so its possible to link specific pages to tabs etc
The only true wisdom is knowing you know nothing

polpero

  • Full Member
  • ***
  • Posts: 102
Re: NBPages in TabControl... what for?
« Reply #2 on: March 19, 2023, 06:49:48 pm »
Ok
Thanks for giving it a look...

Now try to load (pages.loadFromFile() ) a text file...
it looks like each line of text becomes a page!

and trying to load back the content of Pages to the TMemo 
( memo.text := pages.text or memo.lines.assign( pages.text ) )
doesn't work

So it got me wondering what is it meant for?
What should NBPages' purppose be?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1396
  • Fifty shades of code.
    • Delphi & FreePascal
Re: NBPages in TabControl... what for?
« Reply #3 on: March 19, 2023, 07:27:00 pm »
TabControls properties have nothing to do with its controls inside.
When you want to load something to a memo, use memo's load method.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Bart

  • Hero Member
  • *****
  • Posts: 4971
    • Bart en Mariska's Webstek
Re: NBPages in TabControl... what for?
« Reply #4 on: March 19, 2023, 07:38:58 pm »
Hi

I'm trying to maximise usage of the TTabControl...

I've setup a TabControl and a TMemo to load various text files
adding a new tab for each file...

Probably better use a TPageControl for that.
Add TTabSheets as needed and put the TMeme's on those.

Bart

polpero

  • Full Member
  • ***
  • Posts: 102
Re: NBPages in TabControl... what for?
« Reply #5 on: March 19, 2023, 08:03:20 pm »
@Bart

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

https://wiki.freepascal.org/TTabControl

?

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.


jamie

  • Hero Member
  • *****
  • Posts: 5332
Re: NBPages in TabControl... what for?
« Reply #6 on: March 19, 2023, 09:19:51 pm »
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.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 10851
Re: NBPages in TabControl... what for?
« Reply #7 on: March 19, 2023, 09:28:01 pm »
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.

polpero

  • Full Member
  • ***
  • Posts: 102
Re: NBPages in TabControl... what for?
« Reply #8 on: March 19, 2023, 09:34:22 pm »

@wp

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

Actually
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
...


polpero

  • Full Member
  • ***
  • Posts: 102
Re: NBPages in TabControl... what for?
« Reply #9 on: March 19, 2023, 09:44:25 pm »
@wp

our posts just crossed

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

but

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

P.S.
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
 

jamie

  • Hero Member
  • *****
  • Posts: 5332
Re: NBPages in TabControl... what for?
« Reply #10 on: March 19, 2023, 11:15:06 pm »
Are you interacting with the memo's? for example, copying and pasting between them ?
The only true wisdom is knowing you know nothing

polpero

  • Full Member
  • ***
  • Posts: 102
Re: NBPages in TabControl... what for?
« Reply #11 on: March 20, 2023, 01:04:48 am »
@Jamie

Yes, might happen
or writing, deleting
moving pieses around
usual editing stuff


jamie

  • Hero Member
  • *****
  • Posts: 5332
Re: NBPages in TabControl... what for?
« Reply #12 on: March 20, 2023, 03:09:25 am »
check out this project.

It uses the TTabCOntrol and its own pages within.

I just made very basic test case for you to look at but it has a memo on each page created and it sizes with the form etc.
The only true wisdom is knowing you know nothing

polpero

  • Full Member
  • ***
  • Posts: 102
Re: NBPages in TabControl... what for?
« Reply #13 on: March 20, 2023, 07:28:59 pm »
Thanks Jamie

I discovered more than expected in your demo

Guess I was going backwards with TCustomPage
(or forward when it had to be dealed backward...
  if this makes any sense)

I've played with it a while
and posting here the results





 

TinyPortal © 2005-2018