Recent

Author Topic: Getting stuff from a ListBox and doing stuff with it  (Read 4419 times)

heebiejeebies

  • Full Member
  • ***
  • Posts: 127
Getting stuff from a ListBox and doing stuff with it
« on: May 15, 2021, 09:53:28 am »
Mighty gods of Pascal, I entreat thee:

My program is entirely based around a large TPageControl that flicks between different screens.  There is a certain feature which, when activated, means I need to 'breadcrumb' the screens the user clicks on so that I can then cycle backwards between them, going backwards in the same order that the user clicked on them.  I've successfully created an invisible ListBox to store the names of the Tabsheets the user has clicked through when this feature is active.  I cannot for the life of me work out how I then read the contents of the ListBox and pass that onto the TPageControl, to actually make the pages move.  My best attempt is the following, which probably evokes feelings of pity and mild cuteness in mighty gods such as Thee:  :D

Code: Pascal  [Select][+][-]
  1. MainScreen.ActivePage:=CumuHistory.Items[CumuHistory.items.count];

Anyway, with that embarrassing attempt out of the way,  :-[ how do I actually do it?

I am burning incense in front of graven images of you all, in eternal gratitude.
Fedora 38/Lazarus 2.2.4- FPC 3.3.1

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #1 on: May 15, 2021, 10:05:23 am »
Wouldn't it be easier to store ActivePageIndex in an array in the OnChange event handler? Then you can traverse the array from bottom to top, setting ActivePageIndex (or PageIndex) from it, to "walk-back" the user actions.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

heebiejeebies

  • Full Member
  • ***
  • Posts: 127
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #2 on: May 15, 2021, 10:14:13 am »
I knew someone was going to say that....  :D um.... then I'd.... uh.... have to learn how to use arrays.   :-[

And I'd probably still have the same questions at the end of it to be honest.  At least I can make the ListBox temporarily visible so I can see what it's doing, too....

My total programming experience before Pascal was in HyperCard and I guess I still think like a HyperCard programmer.   :-[
Fedora 38/Lazarus 2.2.4- FPC 3.3.1

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #3 on: May 15, 2021, 10:22:01 am »
OK, gimme a little time and I'll write a small example ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

heebiejeebies

  • Full Member
  • ***
  • Posts: 127
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #4 on: May 15, 2021, 10:25:19 am »
LEGEND!!  :D
Fedora 38/Lazarus 2.2.4- FPC 3.3.1

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #5 on: May 15, 2021, 11:37:38 am »
Ok, here it is. A very basic, Q&D example of how you could do something like what you wanted.

It uses a dynamic array to hold (and get back) the page indexes but it also shows how to use a TListBox to show the current list of pages, if any. After "play-back" the list is cleared and all is ready to start again.

As said before, it's just a Q&D demo and for a release I'd probably add at least a helper to deal more easily with the array, and some other things. All in all, though, it shows the basics of how it might work.

To use just click or "tab" to several pages randomly and then click the buttons to show the list or play back the page changes.

HTH!
« Last Edit: May 15, 2021, 11:40:06 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

heebiejeebies

  • Full Member
  • ***
  • Posts: 127
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #6 on: May 15, 2021, 12:20:37 pm »
OK I'm going to download this now and will probably take about 3 days for my puny brain to digest it.  But on to more important matters....  Hope it isn't too personal a question but do you prefer bronze or marble????  Just wondering for when I build the public monument to you.  I guess it also depends on what sort of profits I get out of the programme.   :D
Fedora 38/Lazarus 2.2.4- FPC 3.3.1

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #7 on: May 15, 2021, 03:32:49 pm »
Hope it isn't too personal a question but do you prefer bronze or marble????  Just wondering for when I build the public monument to you.

Just make a nice, well thought-out program; that's monument enough ;D

Also, wait until you see the example ... it might not be what you were looking for :-[
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

heebiejeebies

  • Full Member
  • ***
  • Posts: 127
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #8 on: May 16, 2021, 04:25:57 am »
Thanks again Lucamar - that's very near exactly what I need and I mostly understood what it was doing, too!  Although I had to learn a few new things.  The only difference between your example and what I actually need is that it should only move back one screen per mouseclick, rather than playing back the entire history.  But I managed to figure out how to do that!  Feeling very smug with myself right now.  8)

And thanks Jamie for the thought, too.  ;)
Fedora 38/Lazarus 2.2.4- FPC 3.3.1

heebiejeebies

  • Full Member
  • ***
  • Posts: 127
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #9 on: May 16, 2021, 04:46:06 am »
Actually just one little thingumybob that I need to add in, as well.... It needs to grab a little piece of text data from each page and associate that with each entry in the page list.  Let's just say it grabs it from a TEdit to make the example easy.

I've defined a new array:

Code: Pascal  [Select][+][-]
  1. HistoryList: array of String;

And then in the PageControlChange I added:

Code: Pascal  [Select][+][-]
  1. HistoryList[Length(Playback)-1]:=Edit1.Text;

It compiles, but unfortunately Lazarus blows up when you try to actually use the feature. :'(

"Project project1 raised exception class 'External: SIGSEGV'.

 At address 42858E"
Fedora 38/Lazarus 2.2.4- FPC 3.3.1

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #10 on: May 16, 2021, 09:22:22 am »
But I managed to figure out how to do that!  Feeling very smug with myself right now.  8)

Should be easy, yes; basicaly, what was inside the for loop is "one step back".

It compiles, but unfortunately Lazarus blows up when you try to actually use the feature. :'(

Did you remember to SetLength(HistoryList, ...)?

C'mon, don't be shy, show us your code! If we don't see what's going on, how can we know what's booming out? ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

heebiejeebies

  • Full Member
  • ***
  • Posts: 127
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #11 on: May 17, 2021, 12:06:41 am »
It was basically just your code but with the lines I quoted added in.  Of course, you were right - I hadn't set the length!  I thought I could just piggyback off the other array and use it as the main counter.  But I think I understand properly how arrays work now.  Not so scary after all!   :D

Thanks again lucamar for being so helpful, and for encouraging me to do it properly!  ;)
Fedora 38/Lazarus 2.2.4- FPC 3.3.1

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Getting stuff from a ListBox and doing stuff with it
« Reply #12 on: May 17, 2021, 12:55:22 am »
Glad you solved it :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018