Recent

Author Topic: how to load or add more than one URL path in a listbox..  (Read 5673 times)

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
how to load or add more than one URL path in a listbox..
« on: December 27, 2018, 04:36:03 am »
  good day!,
                  im working on a list box and URL's, is it possible to load more than one URL path in a list box so that i can input different file path together, and what codes can i use to execute it..thanks in advance guys.. merry christmas.. O:-) O:-) O:-) O:-)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: how to load or add more than one URL path in a listbox..
« Reply #1 on: December 27, 2018, 05:08:20 am »
Adding items to a list box is done through TListBox.Items, p.e.:

Code: Pascal  [Select][+][-]
  1.   MyListBox.Items.Add('http://freepascal.org');

The Items property is of type TStrings so all its methods apply.
« Last Edit: December 27, 2018, 05:11:10 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.

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
Re: how to load or add more than one URL path in a listbox..
« Reply #2 on: December 27, 2018, 06:43:36 am »
 thanks sir for the codes,
but how can i link it in the exact location of the URL if i click it? and can i use a display name instead of putting the whole URL in the listbox?? thanks again ...GodBless.. O:-) O:-) :D

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: how to load or add more than one URL path in a listbox..
« Reply #3 on: December 27, 2018, 06:55:11 am »
thanks sir for the codes,
but how can i link it in the exact location of the URL if i click it? and can i use a display name instead of putting the whole URL in the listbox?? thanks again ...GodBless.. O:-) O:-) :D

Use listbox.ItemIndex to access the string in listbox.Items. If you want to use a display name, such as the file name, to select the url, one option is to use two string arrays, one of file names and one of urls. Use the first to fill the listbox, and the second to access the url when a selection is made from the listbox.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: how to load or add more than one URL path in a listbox..
« Reply #4 on: December 27, 2018, 08:51:09 am »
thanks sir for the codes,
but how can i link it in the exact location of the URL if i click it? and can i use a display name instead of putting the whole URL in the listbox?? thanks again ...GodBless.. O:-) O:-) :D

I had a little free-time so I have prepared a little demo for you, following VTwin's idea. Hope it helps!
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.

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
Re: how to load or add more than one URL path in a listbox..
« Reply #5 on: December 29, 2018, 01:37:44 am »
thank you so much for helping guys..ill try it in my project O:-) O:-) :-* :-* :-* :-*

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
Re: how to load or add more than one URL path in a listbox..
« Reply #6 on: December 29, 2018, 03:56:33 am »
    hi guys!, so i'vve tried the codes that you gave me and it worked, the question now is how can i save both the urls and display names in the listbox that im going to input.. thanks:D :D :D

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: how to load or add more than one URL path in a listbox..
« Reply #7 on: December 29, 2018, 04:26:36 am »
[...] the question now is how can i save both the urls and display names [...]

There are lots of ways of doing it. It mostly depends on the format of file you want: XML, JSON, CSV, INI, ...?

For a quick way, you can always add build a string by joining both strings, separated by some character, and add it to yet another TStringList. Once you're done you save with TStringList.SaveToFile() and later load with LoadFromFile.

Quite easy, all in all. If I have a little time tomorrow I'll add saving/loading to my little demo, if you want.
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.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: how to load or add more than one URL path in a listbox..
« Reply #8 on: December 29, 2018, 05:46:04 am »
A TStringList is  a simple solution, but read up on file handling:

http://wiki.freepascal.org/File_Handling_In_Pascal

json and xml are good options for key (file name) value (file path) pairs, but are more complex than you need here.

For a quick way, you can always add build a string by joining both strings, separated by some character

A tab character can be a good option, as it can not appear in file paths, or just save them in pairs. The important thing for learning is to try a few options and see what works best for you.

“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: how to load or add more than one URL path in a listbox..
« Reply #9 on: December 31, 2018, 06:32:53 pm »
Here is the extended (but still little) demo with Save/Load of the list. Sorry for the delay: this days of the year are hectic here around. :)

I made it in a hurry so some things may be suboptimal: sorry about that, too.

ETA: My code uses TStringList--in a sub-optimal way, though. I started implementing it with streams but the code grew quickly to less-than-ideal proportions, so I re-thought it and this is the result.

Let me stress again: it's not optimal code; I'm not actually embarrased by it but I wouldn't use it as-is for production.
« Last Edit: December 31, 2018, 07:26:21 pm 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.

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
Re: how to load or add more than one URL path in a listbox..
« Reply #10 on: January 03, 2019, 06:09:07 am »
Thank you so much for your help... i'll try to combine all of it to finish my project... :D :D :D :D

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
Re: how to load or add more than one URL path in a listbox..
« Reply #11 on: January 10, 2019, 04:48:38 am »
   I've used database to save the information and load it in my listbox, i've done it with listbox, the problem is i can't show the url in the statusbar when i click the title in the listbox.. what codes can i use to execute the code.. thank you..

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: how to load or add more than one URL path in a listbox..
« Reply #12 on: January 10, 2019, 02:30:25 pm »
Get the selected item, search in the database for the corresponding record and read it. Can't help more without knowing how you are doing it but there are quite a lot of database articles in the wiki showing how to do it. You can start in the Database Portal
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.

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
Re: how to load or add more than one URL path in a listbox..
« Reply #13 on: January 15, 2019, 03:10:49 am »
Good Day ..Sorry if my explanation is not that clear, as I was saying I've used database to save both the title and the url so that evertime i open the application that i am doing, all the saved items will be automatically visible in the list box,but the only item visible in the listbox is the title of the link. all i want do is if I click a title for example "Google" in the listbox, the corresponding link of that title that has been save in the database will also appear but in the STATUS BAR. I've tried looking for some codes in the link that you gave me but the problem is i can't construct the codes correctly..im just a newbie in pascal and programming that's why im having a hard time constructing codes..hahaha.. thank you for helping and Godbless.. :D :D :D O:-) O:-) :-* :-*

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: how to load or add more than one URL path in a listbox..
« Reply #14 on: January 17, 2019, 03:06:16 am »
Sorry for the delay. With some luck, gods willing, I'll have some time tomorrow to dedicate to your problem.

Can you share the code you're using? To be able to help I need to know exactly what you're doing and how.
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